lua-users home
lua-l archive

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


I've been working with gema recently and have found that it's
reasonably powerful when integrated w/ lua.
My main beef w/ gema is that you can make it segfault w/ certain
patterns (but w/ some testing w/ your patterns beforehand, you're all
set).... also the fact that it is non-re-entrant...  There's a single
gema parser that you can set/clear rules and such and push data
through.  So.. if you want to use any additional patterns, you need to
set your patterns, use them, then clear them out.
Hmm... here's something that might work w/ gema to your liking.
function onFirst(arg1, arg2)
end
function onSecond(arg1, arg2, arg3)
end
--[["(.)%s*(.-)%s*(.+)" or just "(.-)%s*(.+)".]]
gel.rulestring([[
*<s>*=@lua{ onFirst("$1", "$2")}
?<s>*<s>*=@lua{ onSecond("$1", "$2", "$3")}
]])
gel.parsestring( logFileData )
--.. or if you only do one thing w/ the file...
gel.parsefile( filename )

I think gema's pretty good, but it needs some work...
For one... note that I had to put quotes around the $1 $2... that's
because gema takes the lua string and replaces those values, then
executes it.... somewhat inefficient.. but faster than lots of
gsubs/finds/etc since it works somewhat like a dynamic bison/flex.
You can use regular expressions in gema, but there's no non-greedy
op.. + its semi-limited in ability.
The * matches as much as it can until it reaches the following
delimiter.  The ? matches any single character.
You might need to add an end-of-line/end-of-file marker at the end too.

http://gema.sourceforge.net/ is the link...

--
Thomas Harning Jr.