hi,

attached a patch for the PGE implementation of the Lua parser (lua.pg).

fixing:

* make <name> rule match longest identifiers, not keyword-prefixed identifiers (like "for" in "format")
* fix parameter list rule
* all examples in the lua distribution (in the test directory) can be parsed correctly now.

regards,
klaas-jan
Index: languages/lua/src/lua.pg
===================================================================
--- languages/lua/src/lua.pg	(revision 17016)
+++ languages/lua/src/lua.pg	(working copy)
@@ -128,14 +128,13 @@
   [ <recfield> | <expr> ]*
 }
 
-
 rule parlist {
-    [ <namelist1> [ <','> <'...'> ]? ]?
+    <namelist1> [ <','> <'...'> ]? 
   | <'...'>
 }
 
 rule body {
-  <'('> <parlist> <?closeparen> <block> <?end>
+  <'('> <parlist>? <?closeparen> <block> <?end>
 }
 
 rule explist1 {
@@ -147,7 +146,7 @@
 }
 
 rule funcargs {
-    <'('> <explist1>? <?closeparen>
+    <'('> <explist1>? <?closeparen> 
   | <constructor>
   | <string>
 }
@@ -282,7 +281,7 @@
 =cut
 
 token name {
-  <!keyword> \b <ident>
+  <!keyword> \b <ident> 
 }
 
 
@@ -317,12 +316,20 @@
     ]*
 }
 
+=head2 Keywords
 
+Lua keywords may B<not> be used as identifiers. To make sure the longest
+identifier is matched, so that identifiers that B<start> with a keyword
+is still an identifier, a keyword should end at a word boundary.
+This way, for instance, the identifier C<format> is not read as C<for>.
+
+=cut
+
 token keyword {
-    <'and'>      |  <'break'> | <'do'>    | <'elseif'>
+  [  <'and'>     | <'break'>  | <'do'>    | <'elseif'>
   | <'else'>     | <'end'>    | <'false'> | <'for'>
   | <'function'> | <'if'>     | <'in'>    | <'local'>
   | <'nil'>      | <'not'>    | <'or'>    | <'repeat'>
   | <'return'>   | <'then'>   | <'true'>  | <'until'>
-  | <'while'>
+  | <'while'> 	 ] \b
 }

Reply via email to