From: <fwi...@us...> - 2011-03-28 01:33:39
|
Revision: 7271 http://jython.svn.sourceforge.net/jython/?rev=7271&view=rev Author: fwierzbicki Date: 2011-03-28 01:33:33 +0000 (Mon, 28 Mar 2011) Log Message: ----------- Merge relevant grammar fixes from trunk. Modified Paths: -------------- branches/Release_2_5maint/jython/grammar/Python.g Modified: branches/Release_2_5maint/jython/grammar/Python.g =================================================================== --- branches/Release_2_5maint/jython/grammar/Python.g 2011-03-28 01:33:05 UTC (rev 7270) +++ branches/Release_2_5maint/jython/grammar/Python.g 2011-03-28 01:33:33 UTC (rev 7271) @@ -205,15 +205,14 @@ * a = [3, * 4] */ +int implicitLineJoiningLevel = 0; +int startPos=-1; //For use in partial parsing. public boolean eofWhileNested = false; public boolean partial = false; public boolean single = false; -int implicitLineJoiningLevel = 0; -int startPos=-1; - //If you want to use another error recovery mechanism change this //and the same one in the parser. private ErrorHandler errorHandler; @@ -268,6 +267,8 @@ } } +//START OF PARSER RULES + //single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE single_input @init { @@ -319,8 +320,9 @@ : (NEWLINE | stmt { - if ($stmt.stypes != null) - {stypes.addAll($stmt.stypes);} + if ($stmt.stypes != null) { + stypes.addAll($stmt.stypes); + } } )* EOF { @@ -447,8 +449,13 @@ //funcdef: [decorators] 'def' NAME parameters ':' suite funcdef -@init { stmt stype = null; } -@after { $funcdef.tree = stype; } +@init { + stmt stype = null; +} + +@after { + $funcdef.tree = stype; +} : decorators? DEF NAME parameters COLON suite[false] { Token t = $DEF; @@ -606,12 +613,16 @@ | (testlist[null] ASSIGN) => lhs=testlist[expr_contextType.Store] ( | ((at=ASSIGN t+=testlist[expr_contextType.Store])+ - -> ^(ASSIGN<Assign>[$lhs.start, actions.makeAssignTargets(actions.castExpr($lhs.tree), $t), - actions.makeAssignValue($t)]) + { + stype = new Assign($lhs.tree, actions.makeAssignTargets( + actions.castExpr($lhs.tree), $t), actions.makeAssignValue($t)); + } ) | ((ay=ASSIGN y2+=yield_expr)+ - -> ^(ASSIGN<Assign>[$lhs.start, actions.makeAssignTargets(actions.castExpr($lhs.tree), $y2), - actions.makeAssignValue($y2)]) + { + stype = new Assign($lhs.start, actions.makeAssignTargets( + actions.castExpr($lhs.tree), $y2), actions.makeAssignValue($y2)); + } ) ) | lhs=testlist[expr_contextType.Load] @@ -626,29 +637,53 @@ augassign returns [operatorType op] : PLUSEQUAL - {$op = operatorType.Add;} + { + $op = operatorType.Add; + } | MINUSEQUAL - {$op = operatorType.Sub;} + { + $op = operatorType.Sub; + } | STAREQUAL - {$op = operatorType.Mult;} + { + $op = operatorType.Mult; + } | SLASHEQUAL - {$op = operatorType.Div;} + { + $op = operatorType.Div; + } | PERCENTEQUAL - {$op = operatorType.Mod;} + { + $op = operatorType.Mod; + } | AMPEREQUAL - {$op = operatorType.BitAnd;} + { + $op = operatorType.BitAnd; + } | VBAREQUAL - {$op = operatorType.BitOr;} + { + $op = operatorType.BitOr; + } | CIRCUMFLEXEQUAL - {$op = operatorType.BitXor;} + { + $op = operatorType.BitXor; + } | LEFTSHIFTEQUAL - {$op = operatorType.LShift;} + { + $op = operatorType.LShift; + } | RIGHTSHIFTEQUAL - {$op = operatorType.RShift;} + { + $op = operatorType.RShift; + } | DOUBLESTAREQUAL - {$op = operatorType.Pow;} + { + $op = operatorType.Pow; + } | DOUBLESLASHEQUAL - {$op = operatorType.FloorDiv;} + { + $op = operatorType.FloorDiv; + } ; //print_stmt: 'print' ( [ test (',' test)* [','] ] | @@ -991,6 +1026,7 @@ : (AS | NAME) expr[expr_contextType.Store] { $etype = actions.castExpr($expr.tree); + actions.checkAssign($etype); } ; @@ -1085,7 +1121,10 @@ [expr_contextType ctype] returns [Token leftTok] : NOT nt=not_test[ctype] -> ^(NOT<UnaryOp>[$NOT, unaryopType.Not, actions.castExpr($nt.tree)]) - | comparison[ctype] {$leftTok = $comparison.leftTok;} + | comparison[ctype] + { + $leftTok = $comparison.leftTok; + } ; //comparison: expr (comp_op expr)* @@ -1116,30 +1155,51 @@ comp_op returns [cmpopType op] : LESS - {$op = cmpopType.Lt;} + { + $op = cmpopType.Lt; + } | GREATER - {$op = cmpopType.Gt;} + { + $op = cmpopType.Gt; + } | EQUAL - {$op = cmpopType.Eq;} + { + $op = cmpopType.Eq; + } | GREATEREQUAL - {$op = cmpopType.GtE;} + { + $op = cmpopType.GtE; + } | LESSEQUAL - {$op = cmpopType.LtE;} + { + $op = cmpopType.LtE; + } | ALT_NOTEQUAL - {$op = cmpopType.NotEq;} + { + $op = cmpopType.NotEq; + } | NOTEQUAL - {$op = cmpopType.NotEq;} + { + $op = cmpopType.NotEq; + } | IN - {$op = cmpopType.In;} + { + $op = cmpopType.In; + } | NOT IN - {$op = cmpopType.NotIn;} + { + $op = cmpopType.NotIn; + } | IS - {$op = cmpopType.Is;} + { + $op = cmpopType.Is; + } | IS NOT - {$op = cmpopType.IsNot;} + { + $op = cmpopType.IsNot; + } ; - //expr: xor_expr ('|' xor_expr)* expr [expr_contextType ect] returns [Token leftTok] @@ -1242,9 +1302,13 @@ shift_op returns [operatorType op] : LEFTSHIFT - {$op = operatorType.LShift;} + { + $op = operatorType.LShift; + } | RIGHTSHIFT - {$op = operatorType.RShift;} + { + $op = operatorType.RShift; + } ; //arith_expr: term (('+'|'-') term)* @@ -1287,9 +1351,13 @@ arith_op returns [operatorType op] : PLUS - {$op = operatorType.Add;} + { + $op = operatorType.Add; + } | MINUS - {$op = operatorType.Sub;} + { + $op = operatorType.Sub; + } ; //term: factor (('*'|'/'|'%'|'//') factor)* @@ -1323,14 +1391,22 @@ term_op returns [operatorType op] - :STAR - {$op = operatorType.Mult;} - |SLASH - {$op = operatorType.Div;} - |PERCENT - {$op = operatorType.Mod;} - |DOUBLESLASH - {$op = operatorType.FloorDiv;} + : STAR + { + $op = operatorType.Mult; + } + | SLASH + { + $op = operatorType.Div; + } + | PERCENT + { + $op = operatorType.Mod; + } + | DOUBLESLASH + { + $op = operatorType.FloorDiv; + } ; //factor: ('+'|'-'|'~') factor | power @@ -1340,11 +1416,17 @@ $factor.tree = $etype; } : PLUS p=factor - {$etype = new UnaryOp($PLUS, unaryopType.UAdd, $p.etype);} + { + $etype = new UnaryOp($PLUS, unaryopType.UAdd, $p.etype); + } | MINUS m=factor - {$etype = actions.negate($MINUS, $m.etype);} + { + $etype = actions.negate($MINUS, $m.etype); + } | TILDE t=factor - {$etype = new UnaryOp($TILDE, unaryopType.Invert, $t.etype);} + { + $etype = new UnaryOp($TILDE, unaryopType.Invert, $t.etype); + } | power { $etype = actions.castExpr($power.tree); @@ -1399,7 +1481,10 @@ // NAME | NUMBER | STRING+) atom returns [Token lparen = null] - : LPAREN {$lparen = $LPAREN;} + : LPAREN + { + $lparen = $LPAREN; + } ( yield_expr -> yield_expr | testlist_gexp @@ -1475,8 +1560,7 @@ } : t+=test[$expr::ctype] ( ((options {k=2;}: c1=COMMA t+=test[$expr::ctype])* (c2=COMMA)? - -> { $c1 != null || $c2 != null }? - ^(COMMA<Tuple>[$testlist_gexp.start, actions.castExprs($t), $expr::ctype]) + -> { $c1 != null || $c2 != null }? ^(COMMA<Tuple>[$testlist_gexp.start, actions.castExprs($t), $expr::ctype]) -> test ) | (gen_for[gens] @@ -1665,11 +1749,11 @@ | STAR s=test[expr_contextType.Load] (COMMA DOUBLESTAR k=test[expr_contextType.Load])? { $starargs=actions.castExpr($s.tree); - $kwargs=actions.castExpr($k.tree); + $kwargs=actions.castExpr($k.tree); } | DOUBLESTAR k=test[expr_contextType.Load] { - $kwargs=actions.castExpr($k.tree); + $kwargs=actions.castExpr($k.tree); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2011-03-29 01:58:31
|
Revision: 7274 http://jython.svn.sourceforge.net/jython/?rev=7274&view=rev Author: fwierzbicki Date: 2011-03-29 01:58:24 +0000 (Tue, 29 Mar 2011) Log Message: ----------- Merge from trunk. Modified Paths: -------------- branches/Release_2_5maint/jython/grammar/Python.g Modified: branches/Release_2_5maint/jython/grammar/Python.g =================================================================== --- branches/Release_2_5maint/jython/grammar/Python.g 2011-03-29 01:57:47 UTC (rev 7273) +++ branches/Release_2_5maint/jython/grammar/Python.g 2011-03-29 01:58:24 UTC (rev 7274) @@ -528,15 +528,24 @@ //fpdef: NAME | '(' fplist ')' fpdef[expr_contextType ctype] +@init { + expr etype = null; +} @after { + if (etype != null) { + $fpdef.tree = etype; + } actions.checkAssign(actions.castExpr($fpdef.tree)); } : NAME - -> ^(NAME<Name>[$NAME, $NAME.text, ctype]) + { + etype = new Name($NAME, $NAME.text, ctype); + } | (LPAREN fpdef[null] COMMA) => LPAREN fplist RPAREN - -> ^(LPAREN<Tuple>[$fplist.start, actions.castExprs($fplist.etypes), expr_contextType.Store]) - | LPAREN fplist RPAREN - -> fplist + { + etype = new Tuple($fplist.start, actions.castExprs($fplist.etypes), expr_contextType.Store); + } + | LPAREN! fplist RPAREN! ; //fplist: fpdef (',' fpdef)* [','] @@ -689,13 +698,26 @@ //print_stmt: 'print' ( [ test (',' test)* [','] ] | // '>>' test [ (',' test)+ [','] ] ) print_stmt +@init { + stmt stype = null; +} + +@after { + $print_stmt.tree = stype; +} : PRINT (t1=printlist - -> ^(PRINT<Print>[$PRINT, null, actions.castExprs($t1.elts), $t1.newline]) + { + stype = new Print($PRINT, null, actions.castExprs($t1.elts), $t1.newline); + } | RIGHTSHIFT t2=printlist2 - -> ^(PRINT<Print>[$PRINT, actions.castExpr($t2.elts.get(0)), actions.castExprs($t2.elts, 1), $t2.newline]) + { + stype = new Print($PRINT, actions.castExpr($t2.elts.get(0)), actions.castExprs($t2.elts, 1), $t2.newline); + } | - -> ^(PRINT<Print>[$PRINT, null, new ArrayList<expr>(), true]) + { + stype = new Print($PRINT, null, new ArrayList<expr>(), true); + } ) ; @@ -742,14 +764,30 @@ //del_stmt: 'del' exprlist del_stmt +@init { + stmt stype = null; +} +@after { + $del_stmt.tree = stype; +} : DELETE del_list - -> ^(DELETE<Delete>[$DELETE, $del_list.etypes]) + { + stype = new Delete($DELETE, $del_list.etypes); + } ; //pass_stmt: 'pass' pass_stmt +@init { + stmt stype = null; +} +@after { + $pass_stmt.tree = stype; +} : PASS - -> ^(PASS<Pass>[$PASS]) + { + stype = new Pass($PASS); + } ; //flow_stmt: break_stmt | continue_stmt | return_stmt | raise_stmt | yield_stmt @@ -763,42 +801,82 @@ //break_stmt: 'break' break_stmt +@init { + stmt stype = null; +} +@after { + $break_stmt.tree = stype; +} : BREAK - -> ^(BREAK<Break>[$BREAK]) + { + stype = new Break($BREAK); + } ; //continue_stmt: 'continue' continue_stmt +@init { + stmt stype = null; +} +@after { + $continue_stmt.tree = stype; +} : CONTINUE { if (!$suite.isEmpty() && $suite::continueIllegal) { errorHandler.error("'continue' not supported inside 'finally' clause", new PythonTree($continue_stmt.start)); } + stype = new Continue($CONTINUE); } - -> ^(CONTINUE<Continue>[$CONTINUE]) ; //return_stmt: 'return' [testlist] return_stmt +@init { + stmt stype = null; +} +@after { + $return_stmt.tree = stype; +} : RETURN (testlist[expr_contextType.Load] - -> ^(RETURN<Return>[$RETURN, actions.castExpr($testlist.tree)]) + { + stype = new Return($RETURN, actions.castExpr($testlist.tree)); + } | - -> ^(RETURN<Return>[$RETURN, null]) + { + stype = new Return($RETURN, null); + } ) ; //yield_stmt: yield_expr yield_stmt +@init { + stmt stype = null; +} +@after { + $yield_stmt.tree = stype; +} : yield_expr - -> ^(YIELD<Expr>[$yield_expr.start, actions.castExpr($yield_expr.tree)]) + { + stype = new Expr($yield_expr.start, actions.castExpr($yield_expr.tree)); + } ; //raise_stmt: 'raise' [test [',' test [',' test]]] raise_stmt +@init { + stmt stype = null; +} +@after { + $raise_stmt.tree = stype; +} : RAISE (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load] (COMMA t3=test[expr_contextType.Load])?)?)? - -> ^(RAISE<Raise>[$RAISE, actions.castExpr($t1.tree), actions.castExpr($t2.tree), actions.castExpr($t3.tree)]) + { + stype = new Raise($RAISE, actions.castExpr($t1.tree), actions.castExpr($t2.tree), actions.castExpr($t3.tree)); + } ; //import_stmt: import_name | import_from @@ -809,8 +887,16 @@ //import_name: 'import' dotted_as_names import_name +@init { + stmt stype = null; +} +@after { + $import_name.tree = stype; +} : IMPORT dotted_as_names - -> ^(IMPORT<Import>[$IMPORT, $dotted_as_names.atypes]) + { + stype = new Import($IMPORT, $dotted_as_names.atypes); + } ; //import_from: ('from' ('.'* dotted_name | '.'+) @@ -906,8 +992,16 @@ //assert_stmt: 'assert' test [',' test] assert_stmt +@init { + stmt stype = null; +} +@after { + $assert_stmt.tree = stype; +} : ASSERT t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])? - -> ^(ASSERT<Assert>[$ASSERT, actions.castExpr($t1.tree), actions.castExpr($t2.tree)]) + { + stype = new Assert($ASSERT, actions.castExpr($t1.tree), actions.castExpr($t2.tree)); + } ; //compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef @@ -923,9 +1017,17 @@ //if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] if_stmt +@init { + stmt stype = null; +} +@after { + $if_stmt.tree = stype; +} : IF test[expr_contextType.Load] COLON ifsuite=suite[false] elif_clause? - -> ^(IF<If>[$IF, actions.castExpr($test.tree), actions.castStmts($ifsuite.stypes), - actions.makeElse($elif_clause.stypes, $elif_clause.tree)]) + { + stype = new If($IF, actions.castExpr($test.tree), actions.castStmts($ifsuite.stypes), + actions.makeElse($elif_clause.stypes, $elif_clause.tree)); + } ; //not in CPython's Grammar file @@ -1032,9 +1134,17 @@ //except_clause: 'except' [test [',' test]] except_clause +@init { + excepthandler extype = null; +} +@after { + $except_clause.tree = extype; +} : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Store])?)? COLON suite[!$suite.isEmpty() && $suite::continueIllegal] - -> ^(EXCEPT<ExceptHandler>[$EXCEPT, actions.castExpr($t1.tree), actions.castExpr($t2.tree), - actions.castStmts($suite.stypes)]) + { + extype = new ExceptHandler($EXCEPT, actions.castExpr($t1.tree), actions.castExpr($t2.tree), + actions.castStmts($suite.stypes)); + } ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2011-03-30 02:58:34
|
Revision: 7276 http://jython.svn.sourceforge.net/jython/?rev=7276&view=rev Author: fwierzbicki Date: 2011-03-30 02:58:28 +0000 (Wed, 30 Mar 2011) Log Message: ----------- Merge with trunk. Modified Paths: -------------- branches/Release_2_5maint/jython/grammar/Python.g Modified: branches/Release_2_5maint/jython/grammar/Python.g =================================================================== --- branches/Release_2_5maint/jython/grammar/Python.g 2011-03-30 02:47:03 UTC (rev 7275) +++ branches/Release_2_5maint/jython/grammar/Python.g 2011-03-30 02:58:28 UTC (rev 7276) @@ -609,7 +609,7 @@ ( (aay=augassign y1=yield_expr { actions.checkAssign(actions.castExpr($lhs.tree)); - stype = new AugAssign($lhs.tree, actions.castExpr($lhs.tree), $aay.op, actions.castExpr($y1.tree)); + stype = new AugAssign($lhs.tree, actions.castExpr($lhs.tree), $aay.op, actions.castExpr($y1.etype)); } ) | (aat=augassign rhs=testlist[expr_contextType.Load] @@ -761,7 +761,6 @@ } ; - //del_stmt: 'del' exprlist del_stmt @init { @@ -860,7 +859,7 @@ } : yield_expr { - stype = new Expr($yield_expr.start, actions.castExpr($yield_expr.tree)); + stype = new Expr($yield_expr.start, actions.castExpr($yield_expr.etype)); } ; @@ -1033,16 +1032,28 @@ //not in CPython's Grammar file elif_clause returns [List stypes] +@init { + stmt stype = null; +} +@after { + if (stype != null) { + $elif_clause.tree = stype; + } +} : else_clause { $stypes = $else_clause.stypes; } | ELIF test[expr_contextType.Load] COLON suite[false] - (e2=elif_clause - -> ^(ELIF<If>[$test.start, actions.castExpr($test.tree), actions.castStmts($suite.stypes), actions.makeElse($e2.stypes, $e2.tree)]) - | - -> ^(ELIF<If>[$test.start, actions.castExpr($test.tree), actions.castStmts($suite.stypes), new ArrayList<stmt>()]) - ) + (e2=elif_clause + { + stype = new If($test.start, actions.castExpr($test.tree), actions.castStmts($suite.stypes), actions.makeElse($e2.stypes, $e2.tree)); + } + | + { + stype = new If($test.start, actions.castExpr($test.tree), actions.castStmts($suite.stypes), new ArrayList<stmt>()); + } + ) ; //not in CPython's Grammar file @@ -1177,9 +1188,19 @@ //test: or_test ['if' or_test 'else' test] | lambdef test[expr_contextType ctype] +@init { + expr etype = null; +} +@after { + if (etype != null) { + $test.tree = etype; + } +} :o1=or_test[ctype] ( (IF or_test[null] ORELSE) => IF o2=or_test[ctype] ORELSE e=test[expr_contextType.Load] - -> ^(IF<IfExp>[$o1.start, actions.castExpr($o2.tree), actions.castExpr($o1.tree), actions.castExpr($e.tree)]) + { + etype = new IfExp($o1.start, actions.castExpr($o2.tree), actions.castExpr($o1.tree), actions.castExpr($e.tree)); + } | -> or_test ) @@ -1229,8 +1250,18 @@ //not_test: 'not' not_test | comparison not_test [expr_contextType ctype] returns [Token leftTok] +@init { + expr etype = null; +} +@after { + if (etype != null) { + $not_test.tree = etype; + } +} : NOT nt=not_test[ctype] - -> ^(NOT<UnaryOp>[$NOT, unaryopType.Not, actions.castExpr($nt.tree)]) + { + etype = new UnaryOp($NOT, unaryopType.Not, actions.castExpr($nt.tree)); + } | comparison[ctype] { $leftTok = $comparison.leftTok; @@ -1591,47 +1622,79 @@ // NAME | NUMBER | STRING+) atom returns [Token lparen = null] +@init { + expr etype = null; +} +@after { + if (etype != null) { + $atom.tree = etype; + } +} : LPAREN { $lparen = $LPAREN; } ( yield_expr - -> yield_expr + { + etype = $yield_expr.etype; + } | testlist_gexp -> testlist_gexp | - -> ^(LPAREN<Tuple>[$LPAREN, new ArrayList<expr>(), $expr::ctype]) + { + etype = new Tuple($LPAREN, new ArrayList<expr>(), $expr::ctype); + } ) RPAREN | LBRACK (listmaker[$LBRACK] -> listmaker | - -> ^(LBRACK<org.python.antlr.ast.List>[$LBRACK, new ArrayList<expr>(), $expr::ctype]) + { + etype = new org.python.antlr.ast.List($LBRACK, new ArrayList<expr>(), $expr::ctype); + } ) RBRACK | LCURLY (dictmaker - -> ^(LCURLY<Dict>[$LCURLY, actions.castExprs($dictmaker.keys), - actions.castExprs($dictmaker.values)]) + { + etype = new Dict($LCURLY, actions.castExprs($dictmaker.keys), + actions.castExprs($dictmaker.values)); + } | - -> ^(LCURLY<Dict>[$LCURLY, new ArrayList<expr>(), new ArrayList<expr>()]) + { + etype = new Dict($LCURLY, new ArrayList<expr>(), new ArrayList<expr>()); + } ) RCURLY | lb=BACKQUOTE testlist[expr_contextType.Load] rb=BACKQUOTE - -> ^(BACKQUOTE<Repr>[$lb, actions.castExpr($testlist.tree)]) + { + etype = new Repr($lb, actions.castExpr($testlist.tree)); + } | NAME - -> ^(NAME<Name>[$NAME, $NAME.text, $expr::ctype]) + { + etype = new Name($NAME, $NAME.text, $expr::ctype); + } | INT - -> ^(INT<Num>[$INT, actions.makeInt($INT)]) + { + etype = new Num($INT, actions.makeInt($INT)); + } | LONGINT - -> ^(LONGINT<Num>[$LONGINT, actions.makeInt($LONGINT)]) + { + etype = new Num($LONGINT, actions.makeInt($LONGINT)); + } | FLOAT - -> ^(FLOAT<Num>[$FLOAT, actions.makeFloat($FLOAT)]) + { + etype = new Num($FLOAT, actions.makeFloat($FLOAT)); + } | COMPLEX - -> ^(COMPLEX<Num>[$COMPLEX, actions.makeComplex($COMPLEX)]) + { + etype = new Num($COMPLEX, actions.makeComplex($COMPLEX)); + } | (S+=STRING)+ - -> ^(STRING<Str>[actions.extractStringToken($S), actions.extractStrings($S, encoding)]) + { + etype = new Str(actions.extractStringToken($S), actions.extractStrings($S, encoding)); + } ; //listmaker: test ( list_for | (',' test)* [','] ) @@ -1669,10 +1732,12 @@ } } : t+=test[$expr::ctype] - ( ((options {k=2;}: c1=COMMA t+=test[$expr::ctype])* (c2=COMMA)? - -> { $c1 != null || $c2 != null }? ^(COMMA<Tuple>[$testlist_gexp.start, actions.castExprs($t), $expr::ctype]) - -> test - ) + ( (options {k=2;}: c1=COMMA t+=test[$expr::ctype])* (c2=COMMA)? + { $c1 != null || $c2 != null }? + { + etype = new Tuple($testlist_gexp.start, actions.castExprs($t), $expr::ctype); + } + | -> test | (gen_for[gens] { Collections.reverse(gens); @@ -1706,19 +1771,35 @@ ; //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME -trailer [Token begin, PythonTree tree] +trailer [Token begin, PythonTree ptree] +@init { + expr etype = null; +} +@after { + if (etype != null) { + $trailer.tree = etype; + } +} : LPAREN - (arglist - -> ^(LPAREN<Call>[$begin, actions.castExpr($tree), actions.castExprs($arglist.args), - actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs]) - | - -> ^(LPAREN<Call>[$begin, actions.castExpr($tree), new ArrayList<expr>(), new ArrayList<keyword>(), null, null]) - ) + (arglist + { + etype = new Call($begin, actions.castExpr($ptree), actions.castExprs($arglist.args), + actions.makeKeywords($arglist.keywords), $arglist.starargs, $arglist.kwargs); + } + | + { + etype = new Call($begin, actions.castExpr($ptree), new ArrayList<expr>(), new ArrayList<keyword>(), null, null); + } + ) RPAREN | LBRACK subscriptlist[$begin] RBRACK - -> ^(LBRACK<Subscript>[$begin, actions.castExpr($tree), actions.castSlice($subscriptlist.tree), $expr::ctype]) + { + etype = new Subscript($begin, actions.castExpr($ptree), actions.castSlice($subscriptlist.tree), $expr::ctype); + } | DOT attr - -> ^(DOT<Attribute>[$begin, actions.castExpr($tree), new Name($attr.tree, $attr.text, expr_contextType.Load), $expr::ctype]) + { + etype = new Attribute($begin, actions.castExpr($ptree), new Name($attr.tree, $attr.text, expr_contextType.Load), $expr::ctype); + } ; //subscriptlist: subscript (',' subscript)* [','] @@ -1739,16 +1820,16 @@ subscript returns [slice sltype] @after { - if ($sltype != null) { - $subscript.tree = $sltype; - } + $subscript.tree = $sltype; } : d1=DOT DOT DOT - -> DOT<Ellipsis>[$d1] + { + $sltype = new Ellipsis($d1); + } | (test[null] COLON) => lower=test[expr_contextType.Load] (c1=COLON (upper1=test[expr_contextType.Load])? (sliceop)?)? { - $sltype = actions.makeSubscript($lower.tree, $c1, $upper1.tree, $sliceop.tree); + $sltype = actions.makeSubscript($lower.tree, $c1, $upper1.tree, $sliceop.tree); } | (COLON) => c2=COLON (upper2=test[expr_contextType.Load])? (sliceop)? @@ -1756,16 +1837,28 @@ $sltype = actions.makeSubscript(null, $c2, $upper2.tree, $sliceop.tree); } | test[expr_contextType.Load] - -> ^(LPAREN<Index>[$test.start, actions.castExpr($test.tree)]) + { + $sltype = new Index($test.start, actions.castExpr($test.tree)); + } ; //sliceop: ':' [test] sliceop +@init { + expr etype = null; +} +@after { + if (etype != null) { + $sliceop.tree = etype; + } +} : COLON (test[expr_contextType.Load] -> test | - -> ^(COLON<Name>[$COLON, "None", expr_contextType.Load]) + { + etype = new Name($COLON, "None", expr_contextType.Load); + } ) ; @@ -1794,9 +1887,19 @@ //testlist: test (',' test)* [','] testlist[expr_contextType ctype] +@init { + expr etype = null; +} +@after { + if (etype != null) { + $testlist.tree = etype; + } +} : (test[null] COMMA) => t+=test[ctype] (options {k=2;}: COMMA t+=test[ctype])* (COMMA)? - -> ^(COMMA<Tuple>[$testlist.start, actions.castExprs($t), ctype]) + { + etype = new Tuple($testlist.start, actions.castExprs($t), ctype); + } | test[ctype] ; @@ -1952,8 +2055,15 @@ //yield_expr: 'yield' [testlist] yield_expr + returns [expr etype] +@after { + //needed for y2+=yield_expr + $yield_expr.tree = $etype; +} : YIELD testlist[expr_contextType.Load]? - -> ^(YIELD<Yield>[$YIELD, actions.castExpr($testlist.tree)]) + { + $etype = new Yield($YIELD, actions.castExpr($testlist.tree)); + } ; AS : 'as' ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |