changeset 1091:20d5968e65cc

add end_do, end_for, end_function, end_if, end_while
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 02 Jan 2017 21:28:30 -0700
parents 616761e0b9f6
children a26fbde7ee28
files src/luan/impl/LuanParser.java
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
diff -r 616761e0b9f6 -r 20d5968e65cc src/luan/impl/LuanParser.java
--- a/src/luan/impl/LuanParser.java	Fri Dec 30 13:13:16 2016 -0700
+++ b/src/luan/impl/LuanParser.java	Mon Jan 02 21:28:30 2017 -0700
@@ -510,7 +510,7 @@
 		stmt.addAll( nameVar(names.get(0)).exp() );
  		stmt.add( "==null )  break;  " );
 		Stmts loop = RequiredLoopBlock();
-		RequiredKeyword("end");
+		RequiredEnd("end_for");
 		stmt.addAll( loop );
 		stmt.add( "}  " );
 		popSymbols( symbolsSize() - stackStart );
@@ -522,7 +522,7 @@
 		if( !Keyword("do") )
 			return parser.failure(null);
 		Stmts stmt = RequiredBlock();
-		RequiredKeyword("end");
+		RequiredEnd("end_do");
 		return parser.success(stmt);
 	}
 
@@ -591,7 +591,7 @@
 		Expr cnd = RequiredExpr(In.NOTHING).single();
 		RequiredKeyword("do");
 		Stmts loop = RequiredLoopBlock();
-		RequiredKeyword("end");
+		RequiredEnd("end_while");
 		Stmts stmt = new Stmts();
 		stmt.add( "while( Luan.checkBoolean(" );
 		stmt.addAll( cnd );
@@ -661,7 +661,7 @@
 		} else {
 			hasReturn = false;
 		}
-		RequiredKeyword("end");
+		RequiredEnd("end_if");
 		stmt.add( "}  " );
 		stmt.hasReturn = hasReturn;
 		return parser.success( stmt );
@@ -1111,7 +1111,7 @@
 		stmt.addAll( block );
 		stmt.hasReturn = block.hasReturn;
 		Expr fnDef = newFnExp(stmt,name);
-		RequiredKeyword("end");
+		RequiredEnd("end_function");
 		frame = frame.parent;
 		return parser.success(fnDef);
 	}
@@ -1458,6 +1458,11 @@
 			throw parser.exception("'"+s+"' expected");
 	}
 
+	private void RequiredEnd(String keyword) throws ParseException {
+		if( !Keyword("end") && !Keyword(keyword) )
+			throw parser.exception("'"+keyword+"' or 'end' expected");
+	}
+
 	private void RequiredKeyword(String keyword) throws ParseException {
 		if( !Keyword(keyword) )
 			throw parser.exception("'"+keyword+"' expected");
@@ -1478,6 +1483,11 @@
 		"else",
 		"elseif",
 		"end",
+		"end_do",
+		"end_for",
+		"end_function",
+		"end_if",
+		"end_while",
 		"false",
 		"for",
 		"function",