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. |