Posted on 2014-11-03 22:08
S.l.e!ep.¢% 阅读(736)
评论(0) 编辑 收藏 引用 所属分类:
Lua
LPeg
is a new pattern-matching library for Lua, based on Parsing Expression Grammars (PEGs). This text is a reference manual for the library. For a more formal treatment of LPeg, as well as some discussion about its implementation, see A Text Pattern-Matching Tool based on Parsing Expression Grammars. (You may also be interested in my talk about LPeg given at the III Lua Workshop.)
LPeg是一个为Lua所使用的新的模式匹配库,基于解析表达式语法(PEGs).
本文作为此库的参考手册.
Following the Snobol tradition, LPeg defines patterns as first-class objects. That is, patterns are regular Lua values (represented by userdata). The library offers several functions to create and compose patterns. With the use of metamethods, several of these functions are provided as infix or prefix operators. On the one hand, the result is usually much more verbose than the typical encoding of patterns using the so called regular expressions (which typically are not regular expressions in the formal sense). On the other hand, first-class patterns allow much better documentation (as it is easy to comment the code, to break complex definitions in smaller parts, etc.) and are extensible, as we can define new functions to create and compose patterns.
按
Snobol(百科全书)
传统, LPeg定义模式为第一类对象,也就是说.