[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: LPeg grammars and metatables
- From: Peter Odding <xolox@...>
- Date: Mon, 28 May 2007 18:27:09 +0200
Roberto Ierusalimschy wrote:
I've been working on a lexer framework based on LPeg and noticed that
lpeg.P() does not accept grammars with open references to patterns defined
in another grammar shadowed by the current grammar with __index. Has
support for __index in grammars been considered for a future version of
LPeg? That would allow grammars to inherit one another via Lua's
Can you be more specific about what you have in mind? An example, perhaps?
My lexer framework contains a table of named patterns that all lexers may use.
This table contains start/end of string assertions, line boundary assertions,
character classes, etc.: patterns I don't want to repeat in each lexer. This
table is basically an LPeg grammar without initial rule, though it's never fixed
Each lexer is represented by an LPeg grammar. I wanted to be able to refer to
patterns in the table described above from each lexer's grammar table via
lpeg.V('key'), after having installed a metatable on the grammar table that
makes it shadow the table described above (via __index).
My request is to let LPeg honor __index for open references in grammar tables,
so I can avoid copying patterns back and forth between grammar tables. But maybe
that's not so bad after all: on second thought this might not belong in LPeg...
Totally unrelated but to small for a new thread: Can I match the start of string
in LPeg without lpeg.P(function(s, i) return i == 1 and i end)?
Thanks for your time,
- Peter Odding