[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: how to (slightly) modify the Lua parser
- From: KHMan <keinhong@...>
- Date: Tue, 13 Oct 2009 00:36:41 +0800
steve donovan wrote:
On Mon, Oct 12, 2009 at 6:08 PM, Francesco Abbate
|x, y| sin(x) * cos(y)
You're not the first to want this ;)
No direct clues there to patch the parser, however.
If you trace the call tree of the recursive descent parser in
lparser.c (starting from luaY_parser), I think it is do-able, the
call tree is pretty straightforward.
For function definitions:
statement() -> funcstat() -> funcname() -> body()
body() is where the parameter list is parsed.
So for |x,y|, you need to check for the first '|', then call out
to its own 'stat' (statement handler) function, where you follow
the style of the parameter parsing in body(), but check for '|'
instead of a closing ')'.
For the body, which is a expression (or can it be a list of
expressions?), you can look at the flow of explist1(). The
expression handling stuff is pretty compact code, so take your
time to follow the call tree.
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia