Mercurial Hosting > luan
changeset 656:471be4752b9e
compiling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 05 Apr 2016 16:38:51 -0600 |
parents | e2be71451d04 |
children | 8081713bf7d9 |
files | core/src/luan/impl/LuanParser.java |
diffstat | 1 files changed, 42 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
diff -r e2be71451d04 -r 471be4752b9e core/src/luan/impl/LuanParser.java --- a/core/src/luan/impl/LuanParser.java Tue Apr 05 15:28:07 2016 -0600 +++ b/core/src/luan/impl/LuanParser.java Tue Apr 05 16:38:51 2016 -0600 @@ -323,7 +323,7 @@ parser.begin(); if( !Keyword("return",In.NOTHING) ) return parser.failure(null); - Expressions exprs = ExpList(In.NOTHING); + Expressions exprs = exp(ExpStringList(In.NOTHING)); if( exprs==null ) exprs = ExpList.emptyExpList; return parser.success( new ReturnStmt(exprs) ); @@ -338,10 +338,10 @@ Var var = nameVar(RequiredName(In.NOTHING)); while( parser.match( '.' ) ) { Spaces(In.NOTHING); - Expr exp = NameExpr(In.NOTHING); + ExpString exp = NameExpr(In.NOTHING); if( exp==null ) return parser.failure(null); - var = indexVar( expr(var.expr()), exp ); + var = indexVar( var.exp(), exp ); } Settable fnName = var.settable(); @@ -815,7 +815,7 @@ exp = FunctionExpr(in); if( exp != null ) return parser.success(exp); - exp = VarExp(in); + exp = exp(VarExp(in)); if( exp != null ) return parser.success(exp); exp = VarArgs(in); @@ -894,13 +894,13 @@ private boolean Field(List<ExpString> builder) throws ParseException { parser.begin(); - Expr exp = SubExpr(In.NOTHING); + ExpString exp = SubExpr(In.NOTHING); if( exp==null ) exp = NameExpr(In.NOTHING); if( exp!=null && parser.match('=') ) { Spaces(In.NOTHING); ExpString val = RequiredExpr(In.NOTHING).expr(); - String code = "new TableField(" + new ExpString(exp).code + "," + val.code + ")"; + String code = "new TableField(" + exp.code + "," + val.code + ")"; builder.add( new ExpString(code,true,false) ); return parser.success(); } @@ -913,9 +913,9 @@ return parser.failure(); } - private Expressions VarExp(In in) throws ParseException { + private ExpString VarExp(In in) throws ParseException { Var var = VarZ(in); - return var==null ? null : var.expr(); + return var==null ? null : var.exp(); } private Var VarZ(In in) throws ParseException { @@ -924,7 +924,7 @@ if( var==null ) return parser.failure(null); Var var2; - while( (var2=Var2(in,var.expr())) != null ) { + while( (var2=Var2(in,var.exp())) != null ) { var = var2; } return parser.success(var); @@ -934,7 +934,7 @@ if( parser.match('(') ) { In inParens = in.parens(); Spaces(inParens); - Expr exp = expr(exp(RequiredExpr(inParens))); + ExpString exp = RequiredExpr(inParens).expr(); RequiredMatch(')'); Spaces(in); return exprVar(exp); @@ -942,8 +942,8 @@ String name = Name(in); if( name != null ) return nameVar(name); - Expressions exp; - exp = exp(TableExpr(in)); + ExpString exp; + exp = TableExpr(in); if( exp != null ) return exprVar(exp); exp = Literal(in); @@ -952,26 +952,26 @@ return null; } - private Var Var2(In in,Expressions exp1) throws ParseException { + private Var Var2(In in,ExpString exp1) throws ParseException { parser.begin(); - Expr exp2 = SubExpr(in); + ExpString exp2 = SubExpr(in); if( exp2 != null ) - return parser.success(indexVar(expr(exp1),exp2)); + return parser.success(indexVar(exp1,exp2)); if( parser.match('.') ) { Spaces(in); exp2 = NameExpr(in); if( exp2!=null ) - return parser.success(indexVar(expr(exp1),exp2)); + return parser.success(indexVar(exp1,exp2)); return parser.failure(null); } - FnCall fnCall = Args( in, expr(exp1), new ArrayList<ExpString>() ); + ExpString fnCall = Args( in, exp1, new ArrayList<ExpString>() ); if( fnCall != null ) return parser.success(exprVar(fnCall)); return parser.failure(null); } private interface Var { - public Expressions expr() throws ParseException; + public ExpString exp() throws ParseException; public Settable settable() throws ParseException; } @@ -988,16 +988,16 @@ private Var nameVar(final String name) { return new Var() { - public Expr expr() throws ParseException { + public ExpString exp() throws ParseException { int index = stackIndex(name); if( index != -1 ) - return new GetLocalVar(index); + return new ExpString(new GetLocalVar(index)); index = upValueIndex(name); if( index != -1 ) - return new GetUpVar(index); + return new ExpString(new GetUpVar(index)); Expr envExpr = env(); if( envExpr != null ) - return new IndexExpr( envExpr, new ConstExpr(name) ); + return indexExpStr( new ExpString(envExpr), constExpStr(name) ); parser.failure(null); throw parser.exception("name '"+name+"' not defined"); } @@ -1018,10 +1018,10 @@ }; } - private Var exprVar(final Expressions expr) { + private Var exprVar(final ExpString expr) { return new Var() { - public Expressions expr() { + public ExpString exp() { return expr; } @@ -1031,24 +1031,24 @@ }; } - private Var indexVar(final Expr table,final Expr key) { + private Var indexVar(final ExpString table,final ExpString key) { return new Var() { - public Expr expr() { - return new IndexExpr( table, key ); + public ExpString exp() { + return indexExpStr( table, key ); } public Settable settable() { - return new SetTableEntry(table,key); + return new SetTableEntry(expr(LuanParser.exp(table)),expr(LuanParser.exp(key))); } }; } - private FnCall Args(In in,Expr fn,List<ExpString> builder) throws ParseException { + private ExpString Args(In in,ExpString fn,List<ExpString> builder) throws ParseException { parser.begin(); return args(in,builder) - ? parser.success( new FnCall( fn, ExpList.build(expList(builder)) ) ) - : parser.failure((FnCall)null); + ? parser.success( callExpStr( fn, expString(builder) ) ) + : parser.failure((ExpString)null); } private boolean args(In in,List<ExpString> builder) throws ParseException { @@ -1082,11 +1082,6 @@ return parser.failure(); } - private Expressions ExpList(In in) throws ParseException { - List<ExpString> builder = new ArrayList<ExpString>(); - return ExpList(in,builder) ? ExpList.build(expList(builder)) : null; - } - private ExpString ExpStringList(In in) throws ParseException { List<ExpString> builder = new ArrayList<ExpString>(); return ExpList(in,builder) ? expString(builder) : null; @@ -1115,23 +1110,23 @@ return parser.success(); } - private Expr SubExpr(In in) throws ParseException { + private ExpString SubExpr(In in) throws ParseException { parser.begin(); if( !parser.match('[') || parser.test("[") || parser.test("=") ) return parser.failure(null); Spaces(In.NOTHING); - Expr exp = expr(exp(RequiredExpr(In.NOTHING))); + ExpString exp = RequiredExpr(In.NOTHING).expr(); RequiredMatch(']'); Spaces(in); return parser.success(exp); } - private Expr NameExpr(In in) throws ParseException { + private ExpString NameExpr(In in) throws ParseException { parser.begin(); String name = Name(in); if( name==null ) return parser.failure(null); - return parser.success(new ConstExpr(name)); + return parser.success(constExpStr(name)); } private String RequiredName(In in) throws ParseException { @@ -1210,19 +1205,19 @@ "while" )); - private Expr Literal(In in) throws ParseException { + private ExpString Literal(In in) throws ParseException { parser.begin(); if( NilLiteral(in) ) - return parser.success(new ConstExpr(null)); + return parser.success(constExpStr(null)); Boolean b = BooleanLiteral(in); if( b != null ) - return parser.success(new ConstExpr(b)); + return parser.success(constExpStr(b)); Number n = NumberLiteral(in); if( n != null ) - return parser.success(new ConstExpr(n)); + return parser.success(constExpStr(n)); String s = StringLiteral(in); if( s != null ) - return parser.success(new ConstExpr(s)); + return parser.success(constExpStr(s)); return parser.failure(null); } @@ -1556,7 +1551,7 @@ } } } - +/* private static List<Expressions> expList(List<ExpString> esList) { List<Expressions> list = new ArrayList<Expressions>(); for( ExpString es : esList ) { @@ -1564,7 +1559,7 @@ } return list; } - +*/ private static class StmtString { final String code;