diff options
Diffstat (limited to 'examples/lua_parser.py')
-rw-r--r-- | examples/lua_parser.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/examples/lua_parser.py b/examples/lua_parser.py index 34651dd..9ee730a 100644 --- a/examples/lua_parser.py +++ b/examples/lua_parser.py @@ -99,13 +99,16 @@ keywords = { """.split() } vars().update(keywords) +any_keyword = pp.MatchFirst(keywords.values()).setName("<keyword>") comment_intro = pp.Literal("--") short_comment = comment_intro + pp.restOfLine long_comment = comment_intro + LBRACK + ... + RBRACK lua_comment = long_comment | short_comment -ident = ppc.identifier +# must use negative lookahead to ensure we don't parse a keyword as an identifier +ident = ~any_keyword + ppc.identifier + name = pp.delimitedList(ident, delim=".", combine=True) namelist = pp.delimitedList(name) @@ -274,6 +277,12 @@ if __name__ == "__main__": if t['foo'] then n = n + 1 end + if 10 > 8 then + n = n + 2 + end + if (10 > 8) then + n = n + 2 + end end """ |