This will capture everything after the key/value pairs to the end of the line into a 
"message" entry:

http://lpeg.trink.com/share/3535991849462443947

-r



On 01/31/2015 05:11 AM, Anton Lindström 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

Reply via email to