changeset 1574:f118ead273a1

LuanParser.longString
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 20 Dec 2020 13:17:27 -0700
parents c6b50b7b958c
children 0160650180bc
files src/luan/modules/parsers/LuanParser.java
diffstat 1 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
diff -r c6b50b7b958c -r f118ead273a1 src/luan/modules/parsers/LuanParser.java
--- a/src/luan/modules/parsers/LuanParser.java	Sat Dec 12 21:01:04 2020 -0700
+++ b/src/luan/modules/parsers/LuanParser.java	Sun Dec 20 13:17:27 2020 -0700
@@ -62,6 +62,17 @@
 	}
 
 	private String string() throws ParseException {
+		String s;
+		s = quotedString();
+		if( s != null )
+			return s;
+		s = longString();
+		if( s != null )
+			return s;
+		return null;
+	}
+
+	private String quotedString() throws ParseException {
 		parser.begin();
 		if( !parser.match('"') )
 			return parser.failure(null);
@@ -123,6 +134,38 @@
 		throw exception("unclosed string");
 	}
 
+	private String longString() throws ParseException {
+		parser.begin();
+		if( !parser.match('[') )
+			return parser.failure(null);
+		int start = parser.currentIndex();
+		while( parser.match('=') );
+		int nEquals = parser.currentIndex() - start;
+		if( !parser.match('[') )
+			return parser.failure(null);
+		endOfLine();
+		start = parser.currentIndex();
+		while( !longBracketsEnd(nEquals) ) {
+			if( !(endOfLine() || parser.anyChar()) )
+				throw exception("Unclosed long string");
+		}
+		String s = parser.text.substring( start, parser.currentIndex() - nEquals - 2 );
+		return parser.success(s);
+	}
+
+	private boolean longBracketsEnd(int nEquals) {
+		parser.begin();
+		if( !parser.match(']') )
+			return parser.failure();
+		while( nEquals-- > 0 ) {
+			if( !parser.match('=') )
+				return parser.failure();
+		}
+		if( !parser.match(']') )
+			return parser.failure();
+		return parser.success();
+	}
+
 	private Number number() {
 		parser.begin();
 		if( parser.match("double") ) {