parrotcode: a Lua grammar in PGE | |
Contents | Language Implementations | Lua |
lua.pg - a Lua grammar in PGE
The grammar rules are according to the original Lua parser as defined lparser.c in the lua distribution.
Operator precedence is implemented using an optable.
Helper rules will match a specific token, otherwise a syntax error is generated. These rules make the grammar more readable, so the calls to syntax_error() are not all over the grammar, but only in these rules.
an identifier MUST start on a word boundary. If the \b is removed, this is allowed: a=1b=2, which of course should be an error.
A string can be either a single-quoted, double-quoted or a long string. Long strings are parsed using a custom parsing method.
Lua keywords may not be used as identifiers.
To make sure the longest identifier is matched,
so that identifiers that start with a keyword is still an identifier,
a keyword should end at a word boundary.
This way,
for instance,
the identifier format
is not read as for
.
|