lua-users home
lua-l archive

Re: Any LPEG tutorial for laymen ?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Sep 25, 2013 at 12:28 AM, Sean Conner <sean@conman.org> wrote:
> line = SP^0 * word * SP^1 * word * SP^1 * word
This is an excellent answer. One small change might be to assign the
captures to a map, so that you have three variables, as you do in
REXX. My change:
Ct = lpeg.Ct --capture table, which puts one or more matches into a table.
Cg = lpeg.Cg --capture group, which is used for back captures and to
label items in a capture table.
--here I replace the original line assignment with:
line = Ct(SP^0 * Cg(word, "userid") * SP^1 * Cg(word, "connid") * SP^1
* Cg(word,"state"))
--the pretty print becomes:
function parse(text)
 for i, v in pairs(line:match(text)) do
 print(i,v)
 end
end

AltStyle によって変換されたページ (->オリジナル) /