changeset 1093:a656fa45e315

fix multiline statements
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 08 Jan 2017 21:13:45 -0700
parents a26fbde7ee28
children cb4c20fce7d0
files src/luan/impl/LuanParser.java
diffstat 1 files changed, 16 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
diff -r a26fbde7ee28 -r a656fa45e315 src/luan/impl/LuanParser.java
--- a/src/luan/impl/LuanParser.java	Sun Jan 08 17:23:06 2017 -0700
+++ b/src/luan/impl/LuanParser.java	Sun Jan 08 21:13:45 2017 -0700
@@ -1355,6 +1355,7 @@
 			if( !parser.match(')') )
 				throw parser.exception("Expression or ')' expected");
 			Spaces();
+			parser.upSb();
 			return parser.success();
 		}
 		Expr exp = TableExpr();
@@ -1395,7 +1396,7 @@
 				return parser.success();
 			}
 			exp = RequiredExpr(in);
-			exp.addNewLines();
+			exp.prependNewLines();
 			builder.add(exp);
 		}
 		return parser.success();
@@ -1473,6 +1474,7 @@
 		if( !parser.match(keyword) || NameChar() )
 			return parser.failure();
 		Spaces();
+		parser.upSb();
 		return parser.success();
 	}
 
@@ -1508,15 +1510,16 @@
 
 	private Expr Literal() throws ParseException {
 		parser.begin();
+		Expr exp = new Expr(Val.SINGLE,false);
 		if( NilLiteral() ) {
-			Expr exp = new Expr(Val.SINGLE,false);
 			exp.add( "null" );
+			exp.addNewLines();
 			return parser.success(exp);
 		}
 		Boolean b = BooleanLiteral();
 		if( b != null ) {
-			Expr exp = new Expr(Val.SINGLE,false);
 			exp.add( b.toString() );
+			exp.addNewLines();
 			return parser.success(exp);
 		}
 		Number n = NumberLiteral();
@@ -1524,8 +1527,8 @@
 			String s = n.toString();
 			if( n instanceof Long )
 				s += "L";
-			Expr exp = new Expr(Val.SINGLE,false);
 			exp.add( s );
+			exp.addNewLines();
 			return parser.success(exp);
 		}
 		Expr s = StringLiteral();
@@ -1589,6 +1592,7 @@
 		if( n==null || NameChar() )
 			return parser.failure(null);
 		Spaces();
+		parser.upSb();
 		return parser.success(n);
 	}
 
@@ -1696,6 +1700,7 @@
 		)
 			return null;
 		Spaces();
+		s.addNewLines();
 		return s;
 	}
 
@@ -1841,6 +1846,13 @@
 			}
 		}
 
+		void prependNewLines() {
+			if( parser.sb().length() > 0 ) {
+				add( 0, parser.sb().toString() );
+				parser.sb().setLength(0);
+			}
+		}
+
 		ParseList() {
 			addNewLines();
 		}