当前位置: 首页 > news >正文

lpeg学习笔记- -

为什么80%的码农都做不了架构师?>>>   hot3.png

lpeg.match
匹配函数。返回满足匹配模式字符串后的位置
lpeg.type (value)
如果type是一个模式,返回字符串"pattern",其他返回nil
lpeg.version ()
返回lpeg版本字符串
lpeg.setmaxstack (max)
---------------------------------------------------------------
lpeg.P (value)
1.value = 模式, 返回一个不可修改的模式
2.value = 字符串,返回一个逐字匹配字符串的模式
3.value = 非负整数, 返回一个匹配长度为n的模式
4.value = 负整数,返回一个匹配长度少于n的模式,lpeg.P(-n) 等价于 -lpeg.P(n)
5.value = bool,返回一个一直为真或者假的模式,不管输入字符串是什么
6.value = table,被解释为一个语法
7.value = 函数,
---------------------------------------------------------------
lpeg.B(patt)
Matches patt behind the current position, consuming no input
---------------------------------------------------------------
lpeg.R ({range})
返回一个模式,它匹配指定范围的一个字符。每个范围字符串必须长度为2。R("az", "AZ") 匹配ascii字母.
---------------------------------------------------------------
lpeg.S (string)
返回一个模式,它匹配指定字符集中的一个字符
---------------------------------------------------------------
lpeg.V (v)
为语法创建一个变量。
---------------------------------------------------------------
lpeg.locale ([table])
返回一个带有一些模式的表,这些模式在当前locale匹配一些字符类
---------------------------------------------------------------
#patt
Returns a pattern that matches only if the input string matches patt, but without consuming any input, independently of success or failure.
返回一个模式,只有输入字符串匹配了模式,但是没有消耗任何输入,独立的成功或者失败。
---------------------------------------------------------------
-patt
返回一个模式,当输入字符串不匹配模式模式,才能匹配它;不消耗任何输入,独立的成功或者失败;等价于!patt
-lpeg.P(1)匹配字符串结尾
这个模式不会产出任何捕获
---------------------------------------------------------------
patt1 + patt2
返回一个模式,按顺序匹配patt1 and patt2中的一个;
lower = lpeg.R("az")
upper = lpeg.R("AZ")
letter = lower + upper
---------------------------------------------------------------
patt1 - patt2
返回一个模式,,如果没有没有匹配patt2,则匹配patt1
如果成功,这个模式产出的捕获都来自于patt1;他不会从patt2产出捕获;
如果patt1和patt2都是字符集,这个操作等价于一个差集;-patt等价于"" - patt.如果patt是一个字符集,那么1-patt就是他的补集
---------------------------------------------------------------
patt1 * patt2
返回一个模式,他先匹配patt1,当匹配patt1从成功再匹配patt2,
---------------------------------------------------------------
patt^n
当n为非负数,他等价于patt*: 他匹配n个或更多的patt
当n为负数,他等价于(patt?)-n: 他匹配最多n个的patt
当n为0,等价于patt*
 
---------------------------------------------------------------
Grammars
---------------------------------------------------------------
lpeg.C(patt)     the match for patt plus all captures made by patt
创建一个简单的捕获,是匹配patt的字符串的子串
---------------------------------------------------------------
lpeg.Carg(n)     the value of the nth extra argument to lpeg.match (matches the empty string)
创建一个带参数的捕获,
---------------------------------------------------------------
lpeg.Cb(name)     the values produced by the previous group capture named name (matches the empty string)
Creates a back capture. This pattern matches the empty string and produces the values produced by the most recent group capture named name.

Most recent means the last complete outermost group capture with the given name. A Complete capture means that the entire pattern corresponding to the capture has matched. An Outermost capture means that the capture is not inside another complete capture.
---------------------------------------------------------------
lpeg.Cc ([value, ...])
Creates a constant capture. This pattern matches the empty string and produces all given values as its captured values.
创建常量捕获.
---------------------------------------------------------------
lpeg.Cf (patt, func)
创创建一个捕获集合,如果模式产出一些捕获,函数func将以这些捕获为参数被调用.
---------------------------------------------------------------
lpeg.Cg (patt [, name])
创建一个组捕获,他保存所有被patt捕获的字符串.组可以匿名,也可以命名
一个匿名组捕获用于将几个捕获保存到一个捕获中;一个命名组捕获的值用于之后的捕获或者表捕获;
---------------------------------------------------------------
lpeg.Cp ()
创建一个位置捕获;它能捕获发生一个捕获时子串的位置.返回一个数字.
Creates a position capture. It matches the empty string and captures the position in the subject where the match occurs. The captured value is a number.
---------------------------------------------------------------
lpeg.Cs (patt)
创建一个替代捕获;
Creates a substitution capture, which captures the substring of the subject that matches patt, with substitutions. For any capture inside patt with a value, the substring that matched the capture is replaced by the capture value (which should be a string). The final captured value is the string resulting from all replacements.
---------------------------------------------------------------
lpeg.Ct (patt)
创建一个表捕获;这个捕获将创建一个表,将匿名的捕获保存到表中,索引从1开始.对于命名组捕获,以组名为key.
Creates a table capture. This capture creates a table and puts all values from all anonymous captures made by patt inside this table in successive integer keys, starting at 1. Moreover, for each named capture group created by patt, the first value of the group is put into the table with the group name as its key. The captured value is only the table.
---------------------------------------------------------------

---------------------------------------------------------------

---------------------------------------------------------------
lpeg.Cc(values)     the given values (matches the empty string)
lpeg.Cf(patt, func)     a folding of the captures from patt
lpeg.Cg(patt [, name])     the values produced by patt, optionally tagged with name
lpeg.Cp()     the current position (matches the empty string)
lpeg.Cs(patt)     the match for patt with the values from nested captures replacing their matches
lpeg.Ct(patt)     a table with all captures from patt
patt / string     string, with some marks replaced by captures of patt
patt / number     the n-th value captured by patt, or no value when number is zero.
patt / table     table[c], where c is the (first) capture of patt
patt / function     the returns of function applied to the captures of patt
lpeg.Cmt(patt, function)     the returns of function applied to the captures of patt; the application is done at match time



转载于:https://my.oschina.net/jkkkls/blog/220930

相关文章:

  • nslookup工具的使用方法
  • 菜鸟入门【ASP.NET Core】2:部署到IIS
  • 23种简洁好看的扁平化模板
  • TransE论文剩余部分
  • 《Effective C++》 笔记:Tips01-Tips04
  • 实现数据排序的几种方法
  • Laravel整合Bootstrap 4的完整方案
  • Android存储方式之SQLite的使用
  • Redis项目实战 .net StackExchange.Redis
  • [Json.net]快速入门
  • getRequestURI,getRequestURL的区别
  • 2018年测试状况调查
  • 一个CCIE的梦想(转)
  • 如何快速找到多个字典中的公共键(key)
  • form表单的onclick与submit提交顺序
  • [js高手之路]搞清楚面向对象,必须要理解对象在创建过程中的内存表示
  • Angular4 模板式表单用法以及验证
  • css属性的继承、初识值、计算值、当前值、应用值
  • Javascript设计模式学习之Observer(观察者)模式
  • JS基础篇--通过JS生成由字母与数字组合的随机字符串
  • leetcode46 Permutation 排列组合
  • vue+element后台管理系统,从后端获取路由表,并正常渲染
  • vue脚手架vue-cli
  • yii2中session跨域名的问题
  • 对JS继承的一点思考
  • 区块链将重新定义世界
  • [地铁译]使用SSD缓存应用数据——Moneta项目: 低成本优化的下一代EVCache ...
  • elasticsearch-head插件安装
  • 回归生活:清理微信公众号
  • 整理一些计算机基础知识!
  • ​VRRP 虚拟路由冗余协议(华为)
  • #WEB前端(HTML属性)
  • #我与Java虚拟机的故事#连载13:有这本书就够了
  • (22)C#传智:复习,多态虚方法抽象类接口,静态类,String与StringBuilder,集合泛型List与Dictionary,文件类,结构与类的区别
  • (day 12)JavaScript学习笔记(数组3)
  • (附源码)spring boot公选课在线选课系统 毕业设计 142011
  • (力扣记录)1448. 统计二叉树中好节点的数目
  • (免费领源码)Java#ssm#MySQL 创意商城03663-计算机毕业设计项目选题推荐
  • (四)七种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (一)UDP基本编程步骤
  • (转) ns2/nam与nam实现相关的文件
  • (转)机器学习的数学基础(1)--Dirichlet分布
  • .NET Core 中的路径问题
  • .Net Core与存储过程(一)
  • .NET Framework 3.5中序列化成JSON数据及JSON数据的反序列化,以及jQuery的调用JSON
  • .NET 中 GetProcess 相关方法的性能
  • .NET/C# 编译期间能确定的相同字符串,在运行期间是相同的实例
  • .NET3.5下用Lambda简化跨线程访问窗体控件,避免繁复的delegate,Invoke(转)
  • .Net的DataSet直接与SQL2005交互
  • .NET高级面试指南专题十一【 设计模式介绍,为什么要用设计模式】
  • .net专家(张羿专栏)
  • /var/spool/postfix/maildrop 下有大量文件
  • @NoArgsConstructor和@AllArgsConstructor,@Builder
  • [30期] 我的学习方法
  • [Android]使用Android打包Unity工程