diff src/luan/interp/LuanParser.java @ 54:f5b27ef14d73

add OutputStmt git-svn-id: https://luan-java.googlecode.com/svn/trunk@55 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 31 Dec 2012 19:45:06 +0000
parents 28dfd91a816c
children 9381b23ea9e1
line wrap: on
line diff
--- a/src/luan/interp/LuanParser.java	Mon Dec 31 07:38:09 2012 +0000
+++ b/src/luan/interp/LuanParser.java	Mon Dec 31 19:45:06 2012 +0000
@@ -221,6 +221,7 @@
 			LocalStmt(stmts),
 			Sequence(
 				FirstOf(
+					OutputStmt(),
 					ReturnStmt(),
 					FunctionStmt(),
 					LocalFunctionStmt(),
@@ -240,6 +241,34 @@
 		);
 	}
 
+	Rule OutputStmt() {
+		Var<Integer> start = new Var<Integer>();
+		Var<ExpList.Builder> builder = new Var<ExpList.Builder>(new ExpList.Builder());
+		return Sequence(
+			start.set(currentIndex()),
+			"%>", Optional( EndOfLine() ),
+			ZeroOrMore(
+				FirstOf(
+					Sequence(
+						OneOrMore(
+							TestNot("<%"),
+							ANY
+						),
+						addToExpList(builder.get(),new ConstExpr(match()))
+					),
+					Sequence(
+						"<%=", Spaces(),
+						Expr(),
+						addToExpList(builder.get()),
+						"%>"
+					)
+				)
+			),
+			"<%", Spaces(),
+			push( new OutputStmt( se(start.get()), builder.get().build() ) )
+		);
+	}
+
 	Rule ReturnStmt() {
 		Var<Integer> start = new Var<Integer>();
 		return Sequence(
@@ -796,6 +825,11 @@
 		return true;
 	}
 
+	boolean addToExpList(ExpList.Builder bld, Expr expr) {
+		bld.add(expr);
+		return true;
+	}
+
 	Rule SubExpr() {
 		return Sequence( '[', incParens(), Spaces(), Expr(), ']', decParens(), Spaces() );
 	}