[Nice-commit] Nice/src/bossa/parser Parser.jj,1.223,1.224
Brought to you by:
bonniot
From: <ar...@us...> - 2003-12-12 20:34:49
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1:/tmp/cvs-serv5547/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Added syntactic sugar for method calls with closures(single block only yet) like: loop(5) { print("abc"); } Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.223 retrieving revision 1.224 diff -C2 -d -r1.223 -r1.224 *** Parser.jj 12 Dec 2003 14:55:01 -0000 1.223 --- Parser.jj 12 Dec 2003 20:34:46 -0000 1.224 *************** *** 1744,1748 **** { ( res = RootShortStatement() ! | res = StatementExpression() ) { return res; } --- 1744,1748 ---- { ( res = RootShortStatement() ! | res = ShortStatementExpression() ) { return res; } *************** *** 2268,2272 **** res=LabeledStatement() | res=Block() ! | res=StatementExpression() ";" | res=IfStatement() | res=WhileStatement() --- 2268,2272 ---- res=LabeledStatement() | res=Block() ! | res=RealStatementExpression() | res=IfStatement() | res=WhileStatement() *************** *** 2471,2481 **** } ! Statement StatementExpression() : ! /* ! * The last expansion of this production accepts more than the legal ! * Java expansions for StatementExpression. This expansion does not ! * use PostfixExpression for performance reasons. ! */ ! { Expression e1; Token first, last; } { { first = getToken(1); } --- 2471,2502 ---- } ! Statement RealStatementExpression() : ! { Expression e1; Token first, last; Statement block; } ! { ! { first = getToken(1); } ! ( ! e1=Pre_crementExpression() ";" ! | ! e1=PrimaryExpression() ! ( ! block=Block() ! { if ( e1 instanceof CallExp && ! (e1 instanceof NewExp) ) ! ((CallExp)e1).addBlockArgument(block, null); ! else ! throw bossa.util.User.error(e1,"Block arguments can only be added to normal function calls"); ! } ! | ! e1=PostfixStatementExpression(e1, first) ";" ! ) ! ) ! { ! last = getToken(0); ! e1.setLocation(Location.make(first, last)); ! return new ExpressionStmt(e1); ! } ! } ! ! Statement ShortStatementExpression() : ! { Expression e1; Token first, last; Statement block; } { { first = getToken(1); } *************** *** 2484,2487 **** --- 2505,2530 ---- | e1=PrimaryExpression() + ( + block=Block() + { if ( e1 instanceof CallExp && ! (e1 instanceof NewExp) ) + ((CallExp)e1).addBlockArgument(block, null); + else + throw bossa.util.User.error(e1,"Block arguments can only be added to normal function calls"); + } + | + e1=PostfixStatementExpression(e1, first) + ) + ) + { + last = getToken(0); + e1.setLocation(Location.make(first, last)); + return new ExpressionStmt(e1); + } + + } + + Expression PostfixStatementExpression(Expression e1, Token first) : + {} + { [ "++" { e1=new IncrementExp(e1, false, true); } *************** *** 2497,2510 **** if(op.image.length()!=1) e2=CallExp.create(symb(op.image.substring(0, 1),op),e1,e2); ! e1=AssignExp.create(e1,e2); } ] ! ) ! { ! last = getToken(0); ! e1.setLocation(Location.make(first, last)); ! return new ExpressionStmt(e1); ! } } --- 2540,2548 ---- if(op.image.length()!=1) e2=CallExp.create(symb(op.image.substring(0, 1),op),e1,e2); ! e1=AssignExp.create(e1,e2); } ] ! { return e1; } } *************** *** 2573,2577 **** LOOKAHEAD( "var" | "let" | monotype() <IDENT>) init=LocalDeclarationList() ! | statexp=StatementExpression() ";" {init.add(statexp);} | ";" ) --- 2611,2615 ---- LOOKAHEAD( "var" | "let" | monotype() <IDENT>) init=LocalDeclarationList() ! | statexp=ShortStatementExpression() ";" {init.add(statexp);} | ";" ) *************** *** 2614,2619 **** { Statement s; List statements=new LinkedList(); } { ! s=StatementExpression() { statements.add(s); } ! ( "," s=StatementExpression() { statements.add(s); } )* { return new Block(statements); } --- 2652,2657 ---- { Statement s; List statements=new LinkedList(); } { ! s=ShortStatementExpression() { statements.add(s); } ! ( "," s=ShortStatementExpression() { statements.add(s); } )* { return new Block(statements); } |