lua-users home
lua-l archive

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


It was thus said that the Great Sean Conner once stated:
> It was thus said that the Great Roberto Ierusalimschy once stated:
> > >   Thanks for the confirmation.  I'm going to have to rethink my approach.
> > 
> > If that indeed is the culprit, you can still build a grammar in LPeg.
> > You can build it piecemeal if you want:
> > 
> > + local G = {}
> >   ...
> > - local P = <some pattern>
> > + G.P = <some pattern>
> > + P = lpeg.V"P"
> >   ...
> > + G[1] = final_pattern
> > + final_pattern = lpeg.P(G)

  As an experiment, I converted a few of the LPEG expressions to LPEG
grammars, like turning:

	CFWS = (FWS^-1 * comment)^1 * FWS^-1 -- original size 179
             + FWS

into:

	CFWS    = P{
	             'CFWS',
	             CFWS     = (V"FWS"^-1 * V"comment")^1 * V"FWS"^-1 + V"FWS",
	             comment  = P"(" * (V"FWS"^-1 * V"ccontent")^0 * V"FWS"^-1 * P")",
	             ccontent = ctext + quoted_pair + V"comment",
	             FWS      = FWS,
	           }

and

	dot_atom = CFWS^-1 * C(dot_atom_text) * CFWS^-1

into

	dot_atom = P{
	              'dot_atom',
	              dot_atom = V"CFWS"^-1 * C(V"dot_atom_text") * V"CFWS"^-1,
	              dot_atom_text = dot_atom_text, 
	              CFWS     = (V"FWS"^-1 * V"comment")^1 * V"FWS"^-1 + V"FWS",
	              comment  = P"(" * (V"FWS"^-1 * V"ccontent")^0 * V"FWS"^-1 * P")",
	              ccontent = ctext + quoted_pair + V"comment",
	              FWS      = FWS,
	           }

 and a few more.  This helped, cutting the LPEG dump from 611,931 lines to
just (JUST!) 230,684.  But this cuts into one of the important things about
LPEG---the ability to reuse existing expressions.  Ah well ...

  -spc