changeset 1096:5dc601c4ed6d

fix parser errors
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 05 Mar 2017 15:25:23 -0700
parents 2443152dc2f1
children b2e4a22ffa5d
files src/luan/impl/LuanParser.java
diffstat 1 files changed, 43 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/impl/LuanParser.java	Tue Feb 21 20:27:17 2017 -0700
+++ b/src/luan/impl/LuanParser.java	Sun Mar 05 15:25:23 2017 -0700
@@ -1263,8 +1263,20 @@
 
 	private Var nameVar(final String name) {
 		return new Var() {
+			private Expr exp = null;
 
 			public Expr exp() throws ParseException {
+				if( exp == null ) {
+					String sp = parser.sb().toString();
+					parser.sb().setLength(0);
+					exp = calcExp();
+					if( sp.length() > 0 )
+						exp.add(sp);
+				}
+				return exp;
+			}
+
+			private Expr calcExp() throws ParseException {
 				Sym sym = getSym(name);
 				if( sym != null )
 					return sym.exp();
@@ -1438,6 +1450,7 @@
 		if( keywords.contains(match) )
 			return parser.failure(null);
 		Spaces();
+		parser.upSb();
 		return parser.success(match);
 	}
 
@@ -1919,32 +1932,41 @@
 	}
 
 	private Expr expString(List<Expr> list) {
-		Expr exp = new Expr(Val.ARRAY,false);
 		switch(list.size()) {
 		case 0:
-			exp.add("LuanFunction.NOTHING");
-			return exp;
+			{
+				Expr exp = new Expr(Val.ARRAY,false);
+				exp.add("LuanFunction.NOTHING");
+				return exp;
+			}
 		case 1:
-			return list.get(0);
-		default:
-			int lastI = list.size() - 1;
-			exp.add( "new Object[]{" );
-			for( int i=0; i<lastI; i++ ) {
-				exp.addAll( list.get(i).single() );
-				exp.add( "," );
+			{
+				Expr exp = list.get(0);
+				exp.prependNewLines();
+				return exp;
 			}
-			Expr last = list.get(lastI);
-			if( last.valType==Val.SINGLE ) {
-				exp.addAll( last );
-				exp.add( "}" );
-			} else {
-				exp.add( "}" );
-				exp.add( 0, "LuanImpl.concatArgs(" );
-				exp.add( "," );
-				exp.addAll( last );
-				exp.add( ")" );
+		default:
+			{
+				Expr exp = new Expr(Val.ARRAY,false);
+				int lastI = list.size() - 1;
+				exp.add( "new Object[]{" );
+				for( int i=0; i<lastI; i++ ) {
+					exp.addAll( list.get(i).single() );
+					exp.add( "," );
+				}
+				Expr last = list.get(lastI);
+				if( last.valType==Val.SINGLE ) {
+					exp.addAll( last );
+					exp.add( "}" );
+				} else {
+					exp.add( "}" );
+					exp.add( 0, "LuanImpl.concatArgs(" );
+					exp.add( "," );
+					exp.addAll( last );
+					exp.add( ")" );
+				}
+				return exp;
 			}
-			return exp;
 		}
 	}