changeset 616:56b0b9018319

improve ThemeParser error handling
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 29 Dec 2015 22:19:11 -0700
parents abc3198c86dd
children e54c1646eed0
files core/src/luan/impl/ThemeParser.java
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/impl/ThemeParser.java	Thu Dec 17 01:53:48 2015 -0700
+++ b/core/src/luan/impl/ThemeParser.java	Tue Dec 29 22:19:11 2015 -0700
@@ -176,13 +176,13 @@
 	}
 
 	private Stmt parseDef() throws ParseException {
-		int start = parser.currentIndex();
+		int start = parser.begin();
 		if( !parser.match("{define:") )
-			return null;
+			return parser.failure(null);
 		String name = parseName();
 		if( name==null )
 			throw parser.exception("invalid block name");
-		if( !parser.match("}") )
+		if( !parser.match('}') )
 			throw parser.exception("unclosed define tag");
 		String spaces = "";
 		boolean indent = BlankLine();
@@ -199,7 +199,7 @@
 		FnDef fnDef = newFnDef(start,block);
 		frame = frame.parent;
 		Stmt rtn = new SetStmt(fnName,fnDef);
-		return rtn;
+		return parser.success(rtn);
 	}
 
 	private Stmt parseBody(String tagName,final String spaces,boolean afterIndent) throws ParseException {
@@ -316,7 +316,7 @@
 		String name = parseName();
 		if( name==null )
 			throw exception("invalid block name");
-		if( !parser.match("}") )
+		if( !parser.match('}') )
 			return null;
 		if( tagSpaces != null ) {
 			parser.begin();
@@ -351,12 +351,12 @@
 
 	private Stmt parseSimpleTag(String spaces) throws ParseException {
 		int start = parser.begin();
-		if( !parser.match("{") )
+		if( !parser.match('{') )
 			return parser.failure(null);
 		String name = parseName();
 		if( name==null )
 			return parser.failure(null);
-		if( !parser.match("}") )
+		if( !parser.match('}') )
 			return parser.failure(null);
 //		rtn = "<% env." + name + (attrs.isEmpty() ? "()" : table(attrs)) + " %>";
 		Expr env = env();
@@ -397,8 +397,12 @@
 		return parser.match( "\r\n" ) || parser.match( '\r' ) || parser.match( '\n' );
 	}
 
-	private String parseName() {
+	private String parseName() throws ParseException {
 		int start = parser.begin();
+		if( parser.match('/') )
+			throw exception("bad closing tag");
+		if( parser.match("define:") )
+			throw exception("unexpected definition");
 		if( !NameChar() )
 			return parser.failure(null);
 		while( NameChar() );