From: <fwi...@us...> - 2008-08-06 13:05:18
|
Revision: 5093 http://jython.svn.sourceforge.net/jython/?rev=5093&view=rev Author: fwierzbicki Date: 2008-08-06 13:05:15 +0000 (Wed, 06 Aug 2008) Log Message: ----------- Support "in" as an attribute for Java compatibility, but not as a NAME since this is overkill and causes errors (for example: for x, in ((1,),(2,)): parses "x, in" as a tuple (x,in) if "in" is treated like a name. bad. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-06 12:08:16 UTC (rev 5092) +++ branches/asm/grammar/Python.g 2008-08-06 13:05:15 UTC (rev 5093) @@ -503,9 +503,13 @@ //not in CPython's Grammar file dotted_attr - : NAME (DOT^ NAME)* + : NAME (DOT^ attr)* ; +attr + : NAME + | IN + ; //decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE decorator: AT dotted_attr ( (LPAREN arglist? RPAREN) -> ^(AT dotted_attr ^(Call ^(Args arglist)?)) @@ -771,7 +775,7 @@ dotted_as_names : dotted_as_name (COMMA! dotted_as_name)* ; //dotted_name: NAME ('.' NAME)* -dotted_name : NAME (DOT NAME)* +dotted_name : NAME (DOT attr)* ; //global_stmt: 'global' NAME (',' NAME)* @@ -780,7 +784,7 @@ ; //exec_stmt: 'exec' expr ['in' test [',' test]] -exec_stmt : keyEXEC expr[expr_contextType.Load] (keyIN 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])?)? -> ^(ExecTok[$keyEXEC.start] expr ^(Globals $t1)? ^(Locals $t2)?) ; @@ -815,8 +819,8 @@ ; //for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] -for_stmt : FOR exprlist[expr_contextType.Store] keyIN testlist[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? - -> ^(FOR ^(Target exprlist) ^(InTok[$keyIN.start] testlist) ^(Body $s1) ^(ORELSE $s2)?) +for_stmt : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? + -> ^(FOR ^(Target exprlist) ^(IN testlist) ^(Body $s1) ^(ORELSE $s2)?) ; //try_stmt: ('try' ':' suite @@ -889,8 +893,8 @@ | LESSEQUAL | ALT_NOTEQUAL | NOTEQUAL - | keyIN -> InTok[$keyIN.start] - | NOT keyIN -> NotIn + | IN + | NOT IN -> NotIn | 'is' | 'is' NOT -> IsNot ; @@ -989,7 +993,7 @@ //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME trailer : LPAREN (arglist)? RPAREN -> ^(Call ^(Args arglist)?) | LBRACK subscriptlist RBRACK -> ^(SubscriptList subscriptlist) - | DOT^ NAME {debug("motched DOT^ NAME");} + | DOT^ attr {debug("motched DOT^ NAME");} ; //subscriptlist: subscript (',' subscript)* [','] @@ -1083,8 +1087,8 @@ ; //list_for: 'for' exprlist 'in' testlist_safe [list_iter] -list_for : FOR exprlist[expr_contextType.Load] keyIN testlist[expr_contextType.Load] (list_iter)? - -> ^(ListFor ^(Target exprlist) ^(InTok[$keyIN.start] testlist) ^(Ifs list_iter)?) +list_for : FOR exprlist[expr_contextType.Load] IN testlist[expr_contextType.Load] (list_iter)? + -> ^(ListFor ^(Target exprlist) ^(IN testlist) ^(Ifs list_iter)?) ; //list_if: 'if' test [list_iter] @@ -1098,8 +1102,8 @@ ; //gen_for: 'for' exprlist 'in' or_test [gen_iter] -gen_for: FOR exprlist[expr_contextType.Load] keyIN or_test[expr_contextType.Load] gen_iter? - -> ^(GenFor ^(Target exprlist) ^(InTok[$keyIN.start] or_test) ^(Ifs gen_iter)?) +gen_for: FOR exprlist[expr_contextType.Load] IN or_test[expr_contextType.Load] gen_iter? + -> ^(GenFor ^(Target exprlist) ^(IN or_test) ^(Ifs gen_iter)?) ; //gen_if: 'if' old_test [gen_iter] @@ -1131,7 +1135,6 @@ keyEXEC : {input.LT(1).getText().equals("exec")}? NAME ; //keyFROM : {input.LT(1).getText().equals("from")}? NAME ; //keyGLOBAL : {input.LT(1).getText().equals("global")}? NAME ; -keyIN : {input.LT(1).getText().equals("in")}? NAME ; keyCLASS : {input.LT(1).getText().equals("class")}? NAME ; //keyIS : {input.LT(1).getText().equals("is")}? NAME ; //keyLAMBDA : {input.LT(1).getText().equals("lambda")}? NAME ; @@ -1165,6 +1168,7 @@ FINALLY : 'finally' ; DELETE : 'del' ; TRY : 'try' ; +IN : 'in' ; LPAREN : '(' {implicitLineJoiningLevel++;} ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-06 12:08:16 UTC (rev 5092) +++ branches/asm/grammar/PythonWalker.g 2008-08-06 13:05:15 UTC (rev 5093) @@ -410,9 +410,9 @@ ; dotted_attr returns [exprType etype, PythonTree marker] - : NAME { - $etype = new Name($NAME, $NAME.text, expr_contextType.Load); - $marker = $NAME; + : attr { + $etype = new Name($attr.start, $attr.text, expr_contextType.Load); + $marker = $attr.start; debug("matched NAME in dotted_attr");} | ^(DOT n1=dotted_attr n2=dotted_attr) { $etype = new Attribute($n1.marker, $n1.etype, $n2.text, expr_contextType.Load); @@ -420,6 +420,10 @@ } ; +attr + : NAME + | IN + ; stmts returns [List stypes] scope { List statements; @@ -723,9 +727,9 @@ ; dot_name [StringBuffer buf] - : DOT NAME { + : DOT attr { buf.append("."); - buf.append($NAME.text); + buf.append($attr.text); debug("matched dot_name " + buf); } ; @@ -817,7 +821,7 @@ ; for_stmt - : ^(FOR ^(Target targ=test[expr_contextType.Store]) ^(InTok iter=test[expr_contextType.Load]) ^(Body body=stmts) (^(ORELSE orelse=stmts))?) { + : ^(FOR ^(Target targ=test[expr_contextType.Store]) ^(IN iter=test[expr_contextType.Load]) ^(Body body=stmts) (^(ORELSE orelse=stmts))?) { List o = null; if ($ORELSE != null) { o = $orelse.stypes; @@ -1040,7 +1044,7 @@ | LESSEQUAL {$op = cmpopType.LtE;} | ALT_NOTEQUAL {$op = cmpopType.NotEq;} | NOTEQUAL {$op = cmpopType.NotEq;} - | InTok {$op = cmpopType.In;} + | IN {$op = cmpopType.In;} | NotIn {$op = cmpopType.NotIn;} | 'is' {$op = cmpopType.Is;} | IsNot {$op = cmpopType.IsNot;} @@ -1109,9 +1113,9 @@ $etype = new Name($NAME, $NAME.text, ctype); $marker = $NAME; } - | ^(DOT NAME test[expr_contextType.Load]) { - debug("matched DOT in atom: " + $test.etype + "###" + $NAME.text); - $etype = new Attribute($test.marker, $test.etype, $NAME.text, ctype); + | ^(DOT attr test[expr_contextType.Load]) { + debug("matched DOT in atom: " + $test.etype + "###" + $attr.text); + $etype = new Attribute($test.marker, $test.etype, $attr.text, ctype); $marker = $test.marker; } | ^(SubscriptList subscriptlist test[expr_contextType.Load]) { @@ -1365,7 +1369,7 @@ list_for [List gens] : - ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(InTok iter=test[expr_contextType.Load]) (^(Ifs list_iter[gens]))?) { + ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(IN iter=test[expr_contextType.Load]) (^(Ifs list_iter[gens]))?) { debug("matched list_for"); exprType[] e; if ($Ifs != null && $list_iter.etype != null) { @@ -1391,7 +1395,7 @@ ; gen_for [List gens] - : ^(GenFor ^(Target targ=test[expr_contextType.Store]+) ^(InTok iter=test[expr_contextType.Load]) (^(Ifs gen_iter[gens]))?) { + : ^(GenFor ^(Target targ=test[expr_contextType.Store]+) ^(IN iter=test[expr_contextType.Load]) (^(Ifs gen_iter[gens]))?) { debug("matched gen_for"); exprType[] e; if ($Ifs != null && $gen_iter.etype != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |