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