diff core/src/luan/impl/LuanParser.java @ 655:e2be71451d04

compile TableExpr
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 05 Apr 2016 15:28:07 -0600
parents ea7dbd2dfa65
children 471be4752b9e
line wrap: on
line diff
--- a/core/src/luan/impl/LuanParser.java	Tue Apr 05 14:16:14 2016 -0600
+++ b/core/src/luan/impl/LuanParser.java	Tue Apr 05 15:28:07 2016 -0600
@@ -867,43 +867,45 @@
 		return parser.success( new VarArgs() );
 	}
 
-	private Expr TableExpr(In in) throws ParseException {
+	private ExpString TableExpr(In in) throws ParseException {
 		parser.begin();
 		if( !parser.match('{') )
 			return parser.failure(null);
 		Spaces(In.NOTHING);
-		List<TableExpr.Field> fields = new ArrayList<TableExpr.Field>();
-		List<Expressions> builder = new ArrayList<Expressions>();
-		Field(fields,builder);
+		List<ExpString> builder = new ArrayList<ExpString>();
+		Field(builder);
 		while( FieldSep() ) {
 			Spaces(In.NOTHING);
-			Field(fields,builder);
+			Field(builder);
 		}
-		Expressions exp = exp(TemplateExpressions(In.NOTHING));
+		ExpString exp = TemplateExpressions(In.NOTHING);
 		if( exp != null )
 			builder.add(exp);
 		if( !parser.match('}') )
 			throw parser.exception("Expected table element or '}'");
 		Spaces(in);
-		return parser.success( new TableExpr( fields.toArray(new TableExpr.Field[0]), ExpList.build(builder) ) );
+		String code = "LuanImpl.table(" + expString(builder).code + ")";
+		return parser.success( new ExpString(code,true,false) );
 	}
 
 	private boolean FieldSep() throws ParseException {
 		return parser.anyOf(",;") || EndOfLine();
 	}
 
-	private boolean Field(List<TableExpr.Field> fields,List<Expressions> builder) throws ParseException {
+	private boolean Field(List<ExpString> builder) throws ParseException {
 		parser.begin();
 		Expr exp = SubExpr(In.NOTHING);
 		if( exp==null )
 			exp = NameExpr(In.NOTHING);
 		if( exp!=null && parser.match('=') ) {
 			Spaces(In.NOTHING);
-			fields.add( new TableExpr.Field( exp, required(expr(exp(ExprZ(In.NOTHING)))) ) );
+			ExpString val = RequiredExpr(In.NOTHING).expr();
+			String code = "new TableField(" + new ExpString(exp).code + "," + val.code + ")";
+			builder.add( new ExpString(code,true,false) );
 			return parser.success();
 		}
 		parser.rollback();
-		Expressions exprs = exp(ExprZ(In.NOTHING));
+		ExpString exprs = ExprZ(In.NOTHING);
 		if( exprs != null ) {
 			builder.add(exprs);
 			return parser.success();
@@ -941,7 +943,7 @@
 		if( name != null )
 			return nameVar(name);
 		Expressions exp;
-		exp = TableExpr(in);
+		exp = exp(TableExpr(in));
 		if( exp != null )
 			return exprVar(exp);
 		exp = Literal(in);
@@ -1060,9 +1062,9 @@
 			Spaces(in);
 			return parser.success();
 		}
-		Expr exp = TableExpr(in);
+		ExpString exp = TableExpr(in);
 		if( exp != null ) {
-			builder.add(new ExpString(exp));
+			builder.add(exp);
 			return parser.success();
 		}
 		String s = StringLiteral(in);
@@ -1502,6 +1504,7 @@
 			String classCode = ""
 				+"package luan.impl;\n"
 				+"import luan.Luan;\n"
+				+"import luan.LuanFunction;\n"
 				+"import luan.LuanException;\n"
 				+"\n"
 				+"public class " + className +" implements " + superClass + " {\n"