Posted on 2014-11-03 22:08
S.l.e!ep.¢% 閱讀(747)
評論(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(百科全書)
傳統(tǒng), LPeg定義模式為第一類對象,也就是說.