changeset 82:8ea2e94f3318

add -> operator git-svn-id: https://luan-java.googlecode.com/svn/trunk@83 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 18 Feb 2013 06:29:50 +0000
parents 9df729fa4419
children b84f66704026
files src/luan/interp/LuanParser.java
diffstat 1 files changed, 63 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
diff -r 9df729fa4419 -r 8ea2e94f3318 src/luan/interp/LuanParser.java
--- a/src/luan/interp/LuanParser.java	Sat Feb 16 06:58:00 2013 +0000
+++ b/src/luan/interp/LuanParser.java	Mon Feb 18 06:29:50 2013 +0000
@@ -727,33 +727,67 @@
 	@Cached
 	Rule Var(boolean inParens) {
 		Var<Integer> start = new Var<Integer>();
+		Var<ExpList.Builder> builder = new Var<ExpList.Builder>();
 		return Sequence(
 			start.set(currentIndex()),
-			FirstOf(
-				Sequence(
-					'(', Spaces(true), Expr(true), ')', Spaces(inParens),
-					push(expr(pop())),
-					push(null)  // marker
-				),
-				Sequence(
-					push(null),  // marker
-					Name(inParens)
-				)
-			),
+			VarStart(inParens),
 			ZeroOrMore(
 				makeVarExp(start.get()),
 				FirstOf(
-					SubExpr(inParens),
-					Sequence( '.', Spaces(inParens), NameExpr(inParens) ),
+					VarExt(inParens),
+					Sequence(
+						builder.set(new ExpList.Builder()),
+						Args(inParens,start,builder)
+					),
 					Sequence(
-						Args(inParens,start),
-						push(null)  // marker
+						"->", Spaces(inParens),
+						builder.set(new ExpList.Builder()),
+						addToExpList(builder.get()),
+						VarExpB(inParens),
+						Args(inParens,start,builder)
 					)
 				)
 			)
 		);
 	}
 
+	@Cached
+	Rule VarExpB(boolean inParens) {
+		Var<Integer> start = new Var<Integer>();
+		return Sequence(
+			start.set(currentIndex()),
+			VarStart(inParens),
+			ZeroOrMore(
+				makeVarExp(start.get()),
+				VarExt(inParens)
+			),
+			makeVarExp(start.get())
+		);
+	}
+
+	@Cached
+	Rule VarExt(boolean inParens) {
+		return FirstOf(
+			SubExpr(inParens),
+			Sequence( '.', Spaces(inParens), NameExpr(inParens) )
+		);
+	}
+
+	@Cached
+	Rule VarStart(boolean inParens) {
+		return FirstOf(
+			Sequence(
+				'(', Spaces(true), Expr(true), ')', Spaces(inParens),
+				push(expr(pop())),
+				push(null)  // marker
+			),
+			Sequence(
+				push(null),  // marker
+				Name(inParens)
+			)
+		);
+	}
+
 	Expr env() {
 		int index = stackIndex(_ENV);
 		if( index != -1 )
@@ -782,22 +816,23 @@
 	}
 
 	// function should be on top of the stack
-	Rule Args(boolean inParens,Var<Integer> start) {
+	Rule Args(boolean inParens,Var<Integer> start,Var<ExpList.Builder> builder) {
 		return Sequence(
 			FirstOf(
 				Sequence(
-					'(', Spaces(true), Expressions(true), ')', Spaces(inParens)
+					'(', Spaces(true), Optional(ExpList(true,builder)), ')', Spaces(inParens)
 				),
 				Sequence(
 					TableExpr(inParens),
-					push( new ExpList.SingleExpList(expr(pop())) )
+					addToExpList(builder.get())
 				),
 				Sequence(
 					StringLiteral(inParens),
-					push( new ExpList.SingleExpList(new ConstExpr(pop())) )
+					addToExpList(builder.get())
 				)
 			),
-			push( new FnCall( se(start.get()), expr(pop(1)), (Expressions)pop() ) )
+			push( new FnCall( se(start.get()), expr(pop()), builder.get().build() ) ),
+			push(null)  // marker
 		);
 	}
 
@@ -813,13 +848,19 @@
 	Rule ExpList(boolean inParens) {
 		Var<ExpList.Builder> builder = new Var<ExpList.Builder>(new ExpList.Builder());
 		return Sequence(
+			ExpList(inParens,builder),
+			push( builder.get().build() )
+		);
+	}
+
+	Rule ExpList(boolean inParens,Var<ExpList.Builder> builder) {
+		return Sequence(
 			Expr(inParens),
 			addToExpList(builder.get()),
 			ZeroOrMore(
 				',', Spaces(inParens), Expr(inParens),
 				addToExpList(builder.get())
-			),
-			push( builder.get().build() )
+			)
 		);
 	}