From: <fwi...@us...> - 2008-06-17 15:12:50
|
Revision: 4662 http://jython.svn.sourceforge.net/jython/?rev=4662&view=rev Author: fwierzbicki Date: 2008-06-17 08:12:43 -0700 (Tue, 17 Jun 2008) Log Message: ----------- Slowly adding more needed params to Python.g from PythonWalker.g. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-06-17 02:47:21 UTC (rev 4661) +++ branches/asm/grammar/Python.g 2008-06-17 15:12:43 UTC (rev 4662) @@ -81,12 +81,12 @@ Module; Interactive; Expression; + NameTok; Test; Msg; Import; ImportFrom; Level; - NameTok; Body; Bases; Arguments; @@ -535,7 +535,7 @@ //funcdef: [decorators] 'def' NAME parameters ':' suite funcdef : decorators? DEF NAME parameters COLON suite - -> ^(DEF ^(NameTok NAME) parameters ^(Body suite) ^(Decorators decorators?)) + -> ^(DEF NAME parameters ^(Body suite) ^(Decorators decorators?)) ; //parameters: '(' [varargslist] ')' @@ -612,13 +612,20 @@ @after { PythonTree pt = ((PythonTree)$assigns.tree); int children = pt.getChildCount(); + PythonTree child; if (children == 1) { + child = pt; pt.token = new CommonToken(Value, "Value"); } else { - PythonTree c = (PythonTree)pt.getChild(children - 1); - c.token = new CommonToken(Value, "Value"); + child = (PythonTree)pt.getChild(children - 1); + child.token = new CommonToken(Value, "Value"); } - } + child.token = new CommonToken(Value, "Value"); + PythonTree targ = (PythonTree)child.getChild(0); + if (targ instanceof Context) { + ((Context)targ).setContext(expr_contextType.Load); + } +} : assign_testlist+ | assign_yield+ ; @@ -743,11 +750,11 @@ // 'import' ('*' | '(' import_as_names ')' | import_as_names)) import_from: 'from' (DOT* dotted_name | DOT+) 'import' (STAR - -> ^(ImportFrom 'from' ^(Level DOT*)? ^(NameTok dotted_name)? ^(Import STAR)) + -> ^(ImportFrom 'from' ^(Level DOT*)? ^(Value dotted_name)? ^(Import STAR)) | import_as_names - -> ^(ImportFrom 'from' ^(Level DOT*)? ^(NameTok dotted_name)? ^(Import import_as_names)) + -> ^(ImportFrom 'from' ^(Level DOT*)? ^(Value dotted_name)? ^(Import import_as_names)) | LPAREN import_as_names RPAREN - -> ^(ImportFrom 'from' ^(Level DOT*)? ^(NameTok dotted_name)? ^(Import import_as_names)) + -> ^(ImportFrom 'from' ^(Level DOT*)? ^(Value dotted_name)? ^(Import import_as_names)) ) ; @@ -782,7 +789,7 @@ ; //exec_stmt: 'exec' expr ['in' test [',' test]] -exec_stmt : keyEXEC expr ('in' t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? +exec_stmt : keyEXEC expr[expr_contextType.Load] ('in' t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? -> ^(keyEXEC expr ^(Globals $t1)? ^(Locals $t2)?) ; @@ -840,14 +847,14 @@ ; //with_var: ('as' | NAME) expr -with_var: (keyAS | NAME) expr +with_var: (keyAS | NAME) expr[expr_contextType.Load] ; //except_clause: 'except' [test [',' test]] except_clause : 'except' (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? COLON suite //Note: passing the 'except' keyword on so we can pass the same offset // as CPython. - -> ^(ExceptHandler 'except' ^(Type $t1)? ^(NameTok $t2)? ^(Body suite)) + -> ^(ExceptHandler 'except' ^(Type $t1)? ^(Value $t2)? ^(Body suite)) ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT @@ -856,8 +863,9 @@ ; //test: or_test ['if' or_test 'else' test] | lambdef -test[expr_contextType ect]: o1=or_test - ( ('if' or_test 'else') => 'if' o2=or_test 'else' test[expr_contextType.Load] +test[expr_contextType ctype] + :o1=or_test[ctype] + ( ('if' or_test[expr_contextType.Load] 'else') => 'if' o2=or_test[ctype] 'else' test[expr_contextType.Load] -> ^(IfExp ^(Test $o2) ^(Body $o1) ^(OrElse test)) | -> or_test ) @@ -865,20 +873,20 @@ ; //or_test: and_test ('or' and_test)* -or_test : and_test (OR^ and_test)* +or_test[expr_contextType ctype] : and_test[ctype] (OR^ and_test[ctype])* ; //and_test: not_test ('and' not_test)* -and_test : not_test (AND^ not_test)* +and_test[expr_contextType ctype] : not_test[ctype] (AND^ not_test[ctype])* ; //not_test: 'not' not_test | comparison -not_test : NOT^ not_test - | comparison +not_test[expr_contextType ctype] : NOT^ not_test[ctype] + | comparison[ctype] ; //comparison: expr (comp_op expr)* -comparison: expr (comp_op^ expr)* +comparison[expr_contextType ctype]: expr[ctype] (comp_op^ expr[ctype])* ; //comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' @@ -896,9 +904,17 @@ ; //expr: xor_expr ('|' xor_expr)* -expr : xor_expr (VBAR^ xor_expr)* - ; +expr[expr_contextType ect] +scope { + expr_contextType ctype; +} +@init { + $expr::ctype = ect; +} + : xor_expr (VBAR^ xor_expr)* + ; + //xor_expr: and_expr ('^' and_expr)* xor_expr : and_expr (CIRCUMFLEX^ and_expr)* ; @@ -1001,19 +1017,19 @@ ; //exprlist: expr (',' expr)* [','] -exprlist[expr_contextType ctype]: (expr COMMA) => expr (options {k=2;}: COMMA expr)* (COMMA)? -> ^(Tuple ^(Elts expr+)) - | expr +exprlist[expr_contextType ctype]: (expr[expr_contextType.Load] COMMA) => expr[ctype] (options {k=2;}: COMMA expr[ctype])* (COMMA)? -> ^(Tuple ^(Elts expr+)) + | expr[ctype] ; //XXX: I'm hoping I can get rid of this -- but for now I need an exprlist that does not produce tuples // at least for del_stmt -exprlist2 : expr (options {k=2;}: COMMA expr)* (COMMA)? +exprlist2 : expr[expr_contextType.Load] (options {k=2;}: COMMA expr[expr_contextType.Load])* (COMMA)? -> expr+ ; //testlist: test (',' test)* [','] testlist[expr_contextType ctype] - : test[expr_contextType.Load] (options {k=2;}: c1=COMMA test[expr_contextType.Load])* (c2=COMMA)? + : test[ctype] (options {k=2;}: c1=COMMA test[ctype])* (c2=COMMA)? -> { $c1 != null || $c2 != null }? ^(Tuple ^(Elts test+)) -> test ; @@ -1029,7 +1045,7 @@ //classdef: 'class' NAME ['(' [testlist] ')'] ':' suite classdef: CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite - -> ^(CLASS ^(NameTok NAME) ^(Bases testlist)? ^(Body suite)) + -> ^(CLASS NAME ^(Bases testlist)? ^(Body suite)) ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) @@ -1075,7 +1091,7 @@ ; //gen_for: 'for' exprlist 'in' or_test [gen_iter] -gen_for: 'for' exprlist[expr_contextType.Load] 'in' or_test gen_iter? +gen_for: 'for' exprlist[expr_contextType.Load] 'in' or_test[expr_contextType.Load] gen_iter? -> ^(GenFor ^(Target exprlist) ^(Iter or_test) ^(Ifs gen_iter)?) ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-06-17 02:47:21 UTC (rev 4661) +++ branches/asm/grammar/PythonWalker.g 2008-06-17 15:12:43 UTC (rev 4662) @@ -277,7 +277,7 @@ ; funcdef - : ^(DEF ^(NameTok NAME) ^(Arguments varargslist?) ^(Body stmts) ^(Decorators decorators?)) { + : ^(DEF NAME ^(Arguments varargslist?) ^(Body stmts) ^(Decorators decorators?)) { $stmts::statements.add(makeFunctionDef($DEF, $NAME, $varargslist.args, $stmts.stypes, $decorators.etypes)); } ; @@ -615,9 +615,9 @@ aliasType[] n = (aliasType[])nms.toArray(new aliasType[nms.size()]); $stmts::statements.add(new Import($tok, n)); } - | ^(ImportFrom tok='from' (^(Level dots))? (^(NameTok dotted_name))? ^(Import STAR)) { + | ^(ImportFrom tok='from' (^(Level dots))? (^(Value dotted_name))? ^(Import STAR)) { String name = ""; - if ($NameTok != null) { + if ($Value != null) { name = $dotted_name.result; } int level = 0; @@ -627,9 +627,9 @@ aliasType[] n = (aliasType[])nms.toArray(new aliasType[nms.size()]); $stmts::statements.add(new ImportFrom($tok, name, new aliasType[]{new aliasType($STAR, "*", null)}, level)); } - | ^(ImportFrom tok='from' (^(Level dots))? (^(NameTok dotted_name))? ^(Import import_as_name[nms]+)) { + | ^(ImportFrom tok='from' (^(Level dots))? (^(Value dotted_name))? ^(Import import_as_name[nms]+)) { String name = ""; - if ($NameTok != null) { + if ($Value != null) { name = $dotted_name.result; } int level = 0; @@ -816,7 +816,7 @@ ; except_clause[List handlers] - : ^(ExceptHandler 'except' (^(Type type=test[expr_contextType.Load]))? (^(NameTok name=test[expr_contextType.Store]))? ^(Body stmts)) { + : ^(ExceptHandler 'except' (^(Type type=test[expr_contextType.Load]))? (^(Value name=test[expr_contextType.Store]))? ^(Body stmts)) { stmtType[] b; if ($stmts.start != null) { b = (stmtType[])$stmts.stypes.toArray(new stmtType[$stmts.stypes.size()]); @@ -826,7 +826,7 @@ t = $type.etype; } exprType n = null; - if ($NameTok != null) { + if ($Value != null) { n = $name.etype; } handlers.add(new excepthandlerType($ExceptHandler, t, n, b, $ExceptHandler.getLine(), $ExceptHandler.getCharPositionInLine())); @@ -1071,9 +1071,9 @@ $marker = $BACKQUOTE; } | ^(NameTok NAME) { - debug("matched Name " + $NAME.text); - $etype = new Name($NAME, $NAME.text, ctype); - $marker = $NAME; + debug("matched Name " + $NAME.text); + $etype = new Name($NAME, $NAME.text, ctype); + $marker = $NAME; } | ^(DOT NAME test[expr_contextType.Load]) { debug("matched DOT in atom: " + $test.etype + "###" + $NAME.text); @@ -1231,7 +1231,7 @@ ; classdef - : ^(CLASS ^(NameTok classname=NAME) (^(Bases bases))? ^(Body stmts)) { + : ^(CLASS classname=NAME (^(Bases bases))? ^(Body stmts)) { List b; if ($Bases != null) { b = $bases.names; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |