[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lua-l
Subject:    LPeg: fold capture in re
From:       Александр Машин <alex.mashin () gmail ! com>
Date:       2015-08-03 13:08:00
Message-ID: 55BF67B0.9010102 () gmail ! com
[Download RAW message or body]

> 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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic