lua-users home
lua-l archive

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


I've always thought of the re module as a demo application: see here,
this is how one should build a large, complex LPeg program.

You seem to prefer re and fall back to straight LPeg as a last resort.

And he is not alone. The reasons to prefer re are
1) more concise syntax,
2) natural serialisability--you can easily store re grammars and their parts in a database, 3) greater flexibility in assembling grammars from chunks of any kind: only concatenation is needed.

spc (Except you still can't do a folding capture in re ... )
I think fold captures can be added to re:

"~>"  *  S*  m.Cg(Def/  getdef*  m.Cc(m.Cf))

(diff: http://traditio.wiki/w/index.php?diff=524882&oldid=517695)

And example of usage (http://traditio.wiki/wiki/Module:Test4):

local  serialise=  require  "Module:Test".serialise
local  re=  require  "Module:re"
return {
	show=  function  ()
		local  p=  re.compile([==[
			list	<- ( {| |} pair* ) ~> rawset
			pair	<- {: name space equals space value :} ( space sep space )?
			name	<- { %w+ }
			value	<- { %w+ }
			equals	<- '='
			sep	<- [,;]
			space	<- %s*
		]==],  {  rawset  =  rawset  })
		local  r=  p:match"a=b, c = hi; next = pi"
		return  serialise(r)
	end
}

show () returns:

table {
    a = b
    c = hi
    next = pi
}

This may be considered a feature request. Thanks in advance.

Alexander Mashin