changeset 714:7a322e942c15

fix line numbers
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 20 May 2016 18:35:20 -0600
parents a21e9594307d
children a82d385ec2c3
files core/src/luan/impl/LuanParser.java
diffstat 1 files changed, 26 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
diff -r a21e9594307d -r 7a322e942c15 core/src/luan/impl/LuanParser.java
--- a/core/src/luan/impl/LuanParser.java	Fri May 20 17:03:57 2016 -0600
+++ b/core/src/luan/impl/LuanParser.java	Fri May 20 18:35:20 2016 -0600
@@ -403,15 +403,21 @@
 				Spaces();
 				return parser.success(expString(builder));
 			} else {
+				Expr exp = new Expr(Val.SINGLE,false);
 				int i = parser.currentIndex();
 				do {
 					if( parser.match( "%>" ) )
 						throw parser.exception("'%>' unexpected");
-					if( !parser.anyChar() )
+					if( !(EndOfLine() || parser.anyChar()) )
 						throw parser.exception("Unclosed template expression");
 				} while( !parser.test( "<%" ) );
 				String match = parser.textFrom(i);
-				builder.add( constExpStr(match) );
+				String rtns = parser.sb().toString();
+				parser.sb().setLength(0);
+				exp.addAll( constExpStr(match) );
+				if( rtns.length() > 0 )
+					exp.add(rtns);
+				builder.add(exp);
 			}
 		}
 	}
@@ -1342,9 +1348,9 @@
 			builder.add(exp);
 			return parser.success();
 		}
-		String s = StringLiteral();
-		if( s != null ) {
-			builder.add( constExpStr(s) );
+		exp = StringLiteral();
+		if( exp != null ) {
+			builder.add(exp);
 			return parser.success();
 		}
 		return parser.failure();
@@ -1498,20 +1504,15 @@
 			exp.add( s );
 			return parser.success(exp);
 		}
-		String s = StringLiteral();
+		Expr s = StringLiteral();
 		if( s != null )
-			return parser.success(constExpStr(s));
+			return parser.success(s);
 		return parser.failure(null);
 	}
 
 	private static int STR_LIM = 65000;
 
 	private Expr constExpStr(String s) {
-		int n = 0;
-		int from = 0;
-		while( (from = s.indexOf('\n',from) + 1) != 0 ) {
-			n++;
-		}
 		s = s
 			.replace("\\","\\\\")
 			.replace("\"","\\\"")
@@ -1536,8 +1537,6 @@
 			s = sb.toString();
 		} else
 			s = "\"" + s + "\"";
-		while( n-- > 0 )
-			s += "\n";
 		Expr exp = new Expr(Val.SINGLE,false);
 		exp.add( s );
 		return exp;
@@ -1665,8 +1664,8 @@
 		return Digit() || parser.anyOf("abcdefABCDEF");
 	}
 
-	private String StringLiteral() throws ParseException {
-		String s;
+	private Expr StringLiteral() throws ParseException {
+		Expr s;
 		if( (s=QuotedString('"'))==null
 			&& (s=QuotedString('\''))==null
 			&& (s=LongString())==null
@@ -1676,7 +1675,7 @@
 		return s;
 	}
 
-	private String LongString() throws ParseException {
+	private Expr LongString() throws ParseException {
 		parser.begin();
 		if( !parser.match('[') )
 			return parser.failure(null);
@@ -1685,18 +1684,22 @@
 		int nEquals = parser.currentIndex() - start;
 		if( !parser.match('[') )
 			return parser.failure(null);
-		if( EndOfLine() )
-			parser.upSb();
+		EndOfLine();
 		start = parser.currentIndex();
 		while( !LongBracketsEnd(nEquals) ) {
-			if( !parser.anyChar() )
+			if( !(EndOfLine() || parser.anyChar()) )
 				throw parser.exception("Unclosed long string");
 		}
 		String s = parser.text.substring( start, parser.currentIndex() - nEquals - 2 );
-		return parser.success(s);
+		String rtns = parser.sb().toString();
+		parser.sb().setLength(0);
+		Expr exp = constExpStr(s);
+		if( rtns.length() > 0 )
+			exp.add(rtns);
+		return parser.success(exp);
 	}
 
-	private String QuotedString(char quote) throws ParseException {
+	private Expr QuotedString(char quote) throws ParseException {
 		parser.begin();
 		if( !parser.match(quote) )
 			return parser.failure(null);
@@ -1711,7 +1714,7 @@
 				buf.append(parser.lastChar());
 			}
 		}
-		return parser.success(buf.toString());
+		return parser.success(constExpStr(buf.toString()));
 	}
 
 	private Character EscSeq() {