Oops, didn't respond to all yesterday... ---------- Forwarded message ---------- From: Michael Trinkala <[email protected]> Date: Sat, Jan 31, 2015 at 2:16 PM Subject: Re: [heka] Help with lpeg grammar for KV-tuples To: Anton Lindström <[email protected]>
Added the message grammar and cleaned up the pair grammar. http://lpeg.trink.com/share/12944348678422514771 Trink On Sat, Jan 31, 2015 at 5:11 AM, Anton Lindström < [email protected]> wrote: > Hi! > > I'm trying to write a lpeg grammar for parsing key-value tuples with a > "suffix message". I got the key-value part working, but I can't figure out > how to extract the rest of the message. > My input data looks like this: > > x="a string" status=200 hello world > > I want to parse this into: > message: "hello world" > x: "a string" > status: 200 > > The grammar currently looks like this ( > http://lpeg.trink.com/share/17121232195128835076): > > local l = require 'lpeg' > l.locale(l) > local sp = l.space > local key = l.C((1 - l.S('= '))^1) > local rawString = l.C((1 - sp)^1) > local quotedString = l.C((l.P('\\"') + (1 - l.P('"')))^0) > local integer = l.digit^1 / tonumber > > > local double = l.digit^1 * "." * l.digit^1 / tonumber > > local pair = ( > l.Cg(key * "=" * '"' * quotedString * '"' ) + > l.Cg(key * "=" * (double + integer + rawString)) > ) * sp^0 > > grammar = l.Cf(l.Ct("") * pair^0, rawset) > > > I don't understand how to extract "hello world" into the result table. Any > pointers on how to do this? > > > Thanks, > Anton > > _______________________________________________ > Heka mailing list > [email protected] > https://mail.mozilla.org/listinfo/heka > >
_______________________________________________ Heka mailing list [email protected] https://mail.mozilla.org/listinfo/heka

