lpeg学习笔记- -

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



你可能感兴趣的:(lpeg学习笔记- -)