Update LuaParser.jj and LuaParser.java to accept lua 5.2 syntax for all files in the standard tests.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Javacc grammar for lua language version 5.1
|
||||
* Javacc grammar for lua language version 5.2
|
||||
*
|
||||
* Originally created for use in luaj, a Java implementation of the lua language
|
||||
* @see http://sourceforge.net/projects/luaj/
|
||||
@@ -133,7 +133,7 @@ TOKEN :
|
||||
| < #QUOTED: <DECIMAL> | <UNICODE> | <CHAR> >
|
||||
| < #DECIMAL: "\\" ["0"-"9"] (["0"-"9"])? (["0"-"9"])? >
|
||||
| < DBCOLON: "::" >
|
||||
| < SHEBANG: "#" ["!"," "] (~["\n","\r"])* ("\n"|"\r"|"\r\n") >
|
||||
| < SHEBANG: "#" ["!"," "] (~["\n","\r"])* (<LF>)? >
|
||||
| < #UNICODE: "\\" "u" <HEXDIGIT> <HEXDIGIT> <HEXDIGIT> <HEXDIGIT> >
|
||||
| < #CHAR: "\\" (~[]) >
|
||||
| < #LF: ("\n" | "\r" | "\r\n") >
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Luaj.org. All rights reserved.
|
||||
* Copyright (c) 2010-2012 Luaj.org. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -20,7 +20,7 @@
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
/**
|
||||
* Javacc grammar used to produce a parse tree.
|
||||
* Javacc grammar used to produce a parse tree. Based on lua 5.2 syntax.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -123,6 +123,7 @@ TOKEN :
|
||||
| <FALSE: "false">
|
||||
| <FOR: "for">
|
||||
| <FUNCTION: "function">
|
||||
| <GOTO: "goto">
|
||||
| <IF: "if">
|
||||
| <IN: "in">
|
||||
| <LOCAL: "local">
|
||||
@@ -143,17 +144,21 @@ TOKEN :
|
||||
{
|
||||
< NAME: ["a"-"z", "A"-"Z", "_"] (["a"-"z", "A"-"Z", "_", "0"-"9"])* >
|
||||
| < NUMBER: <HEX> | <FLOAT> >
|
||||
| < #FLOAT: (<DIGIT>)+ "." (<DIGIT>)* (<EXP>)? | "." (<DIGIT>)+ (<EXP>)? | (<DIGIT>)+ (<EXP>)? >
|
||||
| < #FLOAT: <FNUM> (<EXP>)? >
|
||||
| < #FNUM: (<DIGIT>)+ "." (<DIGIT>)* | "." (<DIGIT>)+ | (<DIGIT>)+ >
|
||||
| < #DIGIT: ["0"-"9"] >
|
||||
| < #EXP: ["e","E"] (["+","-"])? (<DIGIT>)+ >
|
||||
| < #HEX: "0" ["x","X"] (<HEXDIGIT>)+ >
|
||||
| < #HEX: "0" ["x","X"] <HEXNUM> (<HEXEXP>)? >
|
||||
| < #HEXNUM: (<HEXDIGIT>)+ "." (<HEXDIGIT>)* | "." (<HEXDIGIT>)+ | (<HEXDIGIT>)+ >
|
||||
| < #HEXDIGIT: ["0"-"9","a"-"f","A"-"F"] >
|
||||
| < #HEXEXP: ["e","E","p","P"] (["+","-"])? (<DIGIT>)+ >
|
||||
| < STRING: "\"" (<QUOTED> | ~["\\","\""])* "\"" >
|
||||
| < CHARSTRING: "'" (<QUOTED> | ~["\\","'"])* "'" >
|
||||
| < #QUOTED: <DECIMAL> | <UNICODE> | <CHAR> >
|
||||
| < #DECIMAL: "\\" ["0"-"9"] (["0"-"9"])? (["0"-"9"])? >
|
||||
| < DBCOLON: "::" >
|
||||
| < SHEBANG: "#" ["!"," "] (~["\n","\r"])* (<LF>)? >
|
||||
| < #UNICODE: "\\" "u" <HEXDIGIT> <HEXDIGIT> <HEXDIGIT> <HEXDIGIT> >
|
||||
//| < #CHAR: "\\" ("a"|"b"|"f"|"n"|"r"|"t"|"v"|"["|"]"|"'"|"\""|"\\"|"0"|<LF>) >
|
||||
| < #CHAR: "\\" (~[]) >
|
||||
| < #LF: ("\n" | "\r" | "\r\n") >
|
||||
}
|
||||
@@ -164,7 +169,7 @@ Chunk Chunk():
|
||||
Block b;
|
||||
}
|
||||
{
|
||||
b=Block() <EOF> { return new Chunk(b); }
|
||||
( <SHEBANG> )? b=Block() <EOF> { return new Chunk(b); }
|
||||
}
|
||||
|
||||
Block Block():
|
||||
@@ -173,7 +178,7 @@ Block Block():
|
||||
Stat s;
|
||||
}
|
||||
{
|
||||
(s=Stat() (";")? {b.add(s);} )* (s=LastStat() (";")? {b.add(s);} )? { return b; }
|
||||
(s=Stat() {b.add(s);} )* (s=ReturnStat() {b.add(s);} )? { return b; }
|
||||
}
|
||||
|
||||
Stat Stat():
|
||||
@@ -188,7 +193,11 @@ Stat Stat():
|
||||
List<Exp> el=null;
|
||||
}
|
||||
{
|
||||
<DO> b=Block() <END> { return Stat.block(b); }
|
||||
";" { return null; }
|
||||
| s=Label() { return s; }
|
||||
| <BREAK> { return Stat.breakstat(); }
|
||||
| <GOTO> n=<NAME> { return Stat.gotostat(n.image); }
|
||||
| <DO> b=Block() <END> { return Stat.block(b); }
|
||||
| <WHILE> e=Exp() <DO> b=Block() <END> { return Stat.whiledo(e,b); }
|
||||
| <REPEAT> b=Block() <UNTIL> e=Exp() { return Stat.repeatuntil(b,e); }
|
||||
| s=IfThenElse() { return s; }
|
||||
@@ -220,13 +229,20 @@ Stat IfThenElse():
|
||||
{ return Stat.ifthenelse(e,b,el,bl,b3); }
|
||||
}
|
||||
|
||||
Stat LastStat():
|
||||
Stat ReturnStat():
|
||||
{
|
||||
List<Exp> el=null;
|
||||
}
|
||||
{
|
||||
<BREAK> { return Stat.breakstat(); }
|
||||
| <RETURN> ( el=ExpList() )? { return Stat.returnstat(el); }
|
||||
<RETURN> ( el=ExpList() )? ( ";" )? { return Stat.returnstat(el); }
|
||||
}
|
||||
|
||||
Stat Label():
|
||||
{
|
||||
Token n;
|
||||
}
|
||||
{
|
||||
<DBCOLON> n=<NAME> <DBCOLON> { return Stat.labelstat(n.image); }
|
||||
}
|
||||
|
||||
Stat ExprStat():
|
||||
@@ -347,7 +363,7 @@ Exp SimpleExp():
|
||||
| s=Str() { return Exp.constant(s); }
|
||||
| "..." { return Exp.varargs(); }
|
||||
| tc=TableConstructor() { return Exp.tableconstructor(tc); }
|
||||
| fb=Function() { return Exp.anonymousfunction(fb); }
|
||||
| fb=FunctionCall() { return Exp.anonymousfunction(fb); }
|
||||
| e=PrimaryExp() { return e; }
|
||||
}
|
||||
|
||||
@@ -373,7 +389,7 @@ Exp Exp():
|
||||
(LOOKAHEAD(2) op=Binop() s=Exp() {e=Exp.binaryexp(e,op,s);} )* { return e; }
|
||||
}
|
||||
|
||||
FuncBody Function():
|
||||
FuncBody FunctionCall():
|
||||
{
|
||||
FuncBody fb;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -51,57 +51,69 @@ public interface LuaParserConstants {
|
||||
/** RegularExpression Id. */
|
||||
int FUNCTION = 37;
|
||||
/** RegularExpression Id. */
|
||||
int IF = 38;
|
||||
int GOTO = 38;
|
||||
/** RegularExpression Id. */
|
||||
int IN = 39;
|
||||
int IF = 39;
|
||||
/** RegularExpression Id. */
|
||||
int LOCAL = 40;
|
||||
int IN = 40;
|
||||
/** RegularExpression Id. */
|
||||
int NIL = 41;
|
||||
int LOCAL = 41;
|
||||
/** RegularExpression Id. */
|
||||
int NOT = 42;
|
||||
int NIL = 42;
|
||||
/** RegularExpression Id. */
|
||||
int OR = 43;
|
||||
int NOT = 43;
|
||||
/** RegularExpression Id. */
|
||||
int RETURN = 44;
|
||||
int OR = 44;
|
||||
/** RegularExpression Id. */
|
||||
int REPEAT = 45;
|
||||
int RETURN = 45;
|
||||
/** RegularExpression Id. */
|
||||
int THEN = 46;
|
||||
int REPEAT = 46;
|
||||
/** RegularExpression Id. */
|
||||
int TRUE = 47;
|
||||
int THEN = 47;
|
||||
/** RegularExpression Id. */
|
||||
int UNTIL = 48;
|
||||
int TRUE = 48;
|
||||
/** RegularExpression Id. */
|
||||
int WHILE = 49;
|
||||
int UNTIL = 49;
|
||||
/** RegularExpression Id. */
|
||||
int NAME = 50;
|
||||
int WHILE = 50;
|
||||
/** RegularExpression Id. */
|
||||
int NUMBER = 51;
|
||||
int NAME = 51;
|
||||
/** RegularExpression Id. */
|
||||
int FLOAT = 52;
|
||||
int NUMBER = 52;
|
||||
/** RegularExpression Id. */
|
||||
int DIGIT = 53;
|
||||
int FLOAT = 53;
|
||||
/** RegularExpression Id. */
|
||||
int EXP = 54;
|
||||
int FNUM = 54;
|
||||
/** RegularExpression Id. */
|
||||
int HEX = 55;
|
||||
int DIGIT = 55;
|
||||
/** RegularExpression Id. */
|
||||
int HEXDIGIT = 56;
|
||||
int EXP = 56;
|
||||
/** RegularExpression Id. */
|
||||
int STRING = 57;
|
||||
int HEX = 57;
|
||||
/** RegularExpression Id. */
|
||||
int CHARSTRING = 58;
|
||||
int HEXNUM = 58;
|
||||
/** RegularExpression Id. */
|
||||
int QUOTED = 59;
|
||||
int HEXDIGIT = 59;
|
||||
/** RegularExpression Id. */
|
||||
int DECIMAL = 60;
|
||||
int HEXEXP = 60;
|
||||
/** RegularExpression Id. */
|
||||
int UNICODE = 61;
|
||||
int STRING = 61;
|
||||
/** RegularExpression Id. */
|
||||
int CHAR = 62;
|
||||
int CHARSTRING = 62;
|
||||
/** RegularExpression Id. */
|
||||
int LF = 63;
|
||||
int QUOTED = 63;
|
||||
/** RegularExpression Id. */
|
||||
int DECIMAL = 64;
|
||||
/** RegularExpression Id. */
|
||||
int DBCOLON = 65;
|
||||
/** RegularExpression Id. */
|
||||
int SHEBANG = 66;
|
||||
/** RegularExpression Id. */
|
||||
int UNICODE = 67;
|
||||
/** RegularExpression Id. */
|
||||
int CHAR = 68;
|
||||
/** RegularExpression Id. */
|
||||
int LF = 69;
|
||||
|
||||
/** Lexical state. */
|
||||
int DEFAULT = 0;
|
||||
@@ -168,6 +180,7 @@ public interface LuaParserConstants {
|
||||
"\"false\"",
|
||||
"\"for\"",
|
||||
"\"function\"",
|
||||
"\"goto\"",
|
||||
"\"if\"",
|
||||
"\"in\"",
|
||||
"\"local\"",
|
||||
@@ -183,14 +196,19 @@ public interface LuaParserConstants {
|
||||
"<NAME>",
|
||||
"<NUMBER>",
|
||||
"<FLOAT>",
|
||||
"<FNUM>",
|
||||
"<DIGIT>",
|
||||
"<EXP>",
|
||||
"<HEX>",
|
||||
"<HEXNUM>",
|
||||
"<HEXDIGIT>",
|
||||
"<HEXEXP>",
|
||||
"<STRING>",
|
||||
"<CHARSTRING>",
|
||||
"<QUOTED>",
|
||||
"<DECIMAL>",
|
||||
"\"::\"",
|
||||
"<SHEBANG>",
|
||||
"<UNICODE>",
|
||||
"<CHAR>",
|
||||
"<LF>",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user