From: <fwi...@us...> - 2008-07-23 18:39:12
|
Revision: 4989 http://jython.svn.sourceforge.net/jython/?rev=4989&view=rev Author: fwierzbicki Date: 2008-07-23 18:39:09 +0000 (Wed, 23 Jul 2008) Log Message: ----------- Offset fixes for Try/Catch and Call. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-07-23 01:58:01 UTC (rev 4988) +++ branches/asm/grammar/Python.g 2008-07-23 18:39:09 UTC (rev 4989) @@ -818,11 +818,11 @@ // ['else' ':' suite] // ['finally' ':' suite] | // 'finally' ':' suite)) -try_stmt : 'try' COLON trysuite=suite +try_stmt : TRY COLON trysuite=suite ( (except_clause+ (ORELSE COLON elsesuite=suite)? (FINALLY COLON finalsuite=suite)? - -> ^(TryExcept 'try' ^(Body $trysuite) except_clause+ ^(ORELSE $elsesuite)? ^(FINALLY $finalsuite)?)) + -> ^(TryExcept[$TRY] ^(Body $trysuite) except_clause+ ^(ORELSE $elsesuite)? ^(FINALLY $finalsuite)?)) | (FINALLY COLON finalsuite=suite - -> ^(TryFinally 'try' ^(Body $trysuite) ^(FINALLY $finalsuite))) + -> ^(TryFinally[$TRY] ^(Body $trysuite) ^(FINALLY $finalsuite))) ) ; @@ -1158,6 +1158,7 @@ ASSERT : 'assert' ; FINALLY : 'finally' ; DELETE : 'del' ; +TRY : 'try' ; LPAREN : '(' {implicitLineJoiningLevel++;} ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-07-23 01:58:01 UTC (rev 4988) +++ branches/asm/grammar/PythonWalker.g 2008-07-23 18:39:09 UTC (rev 4989) @@ -389,6 +389,7 @@ } else { c = makeCall($Call, $dotted_attr.etype, $arglist.args, $arglist.keywords, $arglist.starargs, $arglist.kwargs); } + c.setCharStopIndex($Call.getCharStopIndex()); decs.add(c); } } @@ -470,6 +471,7 @@ } else { c = makeCall($test.marker, $test.etype, $arglist.args, $arglist.keywords, $arglist.starargs, $arglist.kwargs); } + c.setCharStopIndex($Call.getCharStopIndex()); $etype = c; } ; @@ -814,7 +816,7 @@ @init { List handlers = new ArrayList(); } - : ^(TryExcept tok='try' ^(Body body=stmts) except_clause[handlers]+ (^(ORELSE orelse=stmts))? (^(FINALLY fin=stmts))?) { + : ^(TryExcept ^(Body body=stmts) except_clause[handlers]+ (^(ORELSE orelse=stmts))? (^(FINALLY fin=stmts))?) { List o = null; List f = null; if ($ORELSE != null) { @@ -823,11 +825,11 @@ if ($FINALLY != null) { f = $fin.stypes; } - stmtType te = makeTryExcept($tok, $body.stypes, handlers, o, f); + stmtType te = makeTryExcept($TryExcept, $body.stypes, handlers, o, f); $stmts::statements.add(te); } - | ^(TryFinally tok='try' ^(Body body=stmts) ^(FINALLY fin=stmts)) { - TryFinally tf = makeTryFinally($tok, $body.stypes, $fin.stypes); + | ^(TryFinally ^(Body body=stmts) ^(FINALLY fin=stmts)) { + TryFinally tf = makeTryFinally($TryFinally, $body.stypes, $fin.stypes); $stmts::statements.add(tf); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-05 23:46:35
|
Revision: 5087 http://jython.svn.sourceforge.net/jython/?rev=5087&view=rev Author: fwierzbicki Date: 2008-08-05 23:46:30 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Finish out "IN" as a token. 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-05 23:44:49 UTC (rev 5086) +++ branches/asm/grammar/Python.g 2008-08-05 23:46:30 UTC (rev 5087) @@ -777,7 +777,7 @@ ; //exec_stmt: 'exec' expr ['in' test [',' test]] -exec_stmt : keyEXEC expr[expr_contextType.Load] ('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)?) ; @@ -886,8 +886,8 @@ | LESSEQUAL | ALT_NOTEQUAL | NOTEQUAL - | 'in' - | NOT 'in' -> NotIn + | IN + | NOT IN -> NotIn | 'is' | 'is' NOT -> IsNot ; @@ -1126,7 +1126,7 @@ 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 ; +keyIN : {input.LT(1).getText().equals("in")}? NAME ; //keyIS : {input.LT(1).getText().equals("is")}? NAME ; //keyLAMBDA : {input.LT(1).getText().equals("lambda")}? NAME ; //keyNOT : {input.LT(1).getText().equals("not")}? NAME ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-05 23:44:49 UTC (rev 5086) +++ branches/asm/grammar/PythonWalker.g 2008-08-05 23:46:30 UTC (rev 5087) @@ -1040,7 +1040,7 @@ | LESSEQUAL {$op = cmpopType.LtE;} | ALT_NOTEQUAL {$op = cmpopType.NotEq;} | NOTEQUAL {$op = cmpopType.NotEq;} - | 'in' {$op = cmpopType.In;} + | IN {$op = cmpopType.In;} | NotIn {$op = cmpopType.NotIn;} | 'is' {$op = cmpopType.Is;} | IsNot {$op = cmpopType.IsNot;} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-06 02:19:56
|
Revision: 5088 http://jython.svn.sourceforge.net/jython/?rev=5088&view=rev Author: fwierzbicki Date: 2008-08-06 02:19:54 +0000 (Wed, 06 Aug 2008) Log Message: ----------- fix for Java integration ("in" and "class" can now be used as non-keywords). 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-05 23:46:30 UTC (rev 5087) +++ branches/asm/grammar/Python.g 2008-08-06 02:19:54 UTC (rev 5088) @@ -82,6 +82,9 @@ Interactive; Expression; NameTok; + ExecTok; + InTok; + ClassTok; Test; Msg; Level; @@ -777,8 +780,8 @@ ; //exec_stmt: 'exec' expr ['in' test [',' test]] -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)?) +exec_stmt : keyEXEC expr[expr_contextType.Load] (keyIN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? + -> ^(ExecTok[$keyEXEC.start] expr ^(Globals $t1)? ^(Locals $t2)?) ; //assert_stmt: 'assert' test [',' test] @@ -812,8 +815,8 @@ ; //for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] -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)?) +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)?) ; //try_stmt: ('try' ':' suite @@ -886,8 +889,8 @@ | LESSEQUAL | ALT_NOTEQUAL | NOTEQUAL - | IN - | NOT IN -> NotIn + | keyIN -> InTok[$keyIN.start] + | NOT keyIN -> NotIn | 'is' | 'is' NOT -> IsNot ; @@ -1033,8 +1036,8 @@ ; //classdef: 'class' NAME ['(' [testlist] ')'] ':' suite -classdef: CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite - -> ^(CLASS NAME ^(Bases testlist)? ^(Body suite)) +classdef: keyCLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite + -> ^(ClassTok[$keyCLASS.start] NAME ^(Bases testlist)? ^(Body suite)) ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) @@ -1080,8 +1083,8 @@ ; //list_for: 'for' exprlist 'in' testlist_safe [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_for : FOR exprlist[expr_contextType.Load] keyIN testlist[expr_contextType.Load] (list_iter)? + -> ^(ListFor ^(Target exprlist) ^(InTok[$keyIN.start] testlist) ^(Ifs list_iter)?) ; //list_if: 'if' test [list_iter] @@ -1095,8 +1098,8 @@ ; //gen_for: 'for' exprlist 'in' or_test [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_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_if: 'if' old_test [gen_iter] @@ -1118,7 +1121,7 @@ //and 'exec'. //keyAND : {input.LT(1).getText().equals("and")}? NAME ; -keyAS : {input.LT(1).getText().equals("as")}? NAME ; +keyAS : {input.LT(1).getText().equals("as")}? NAME ; //keyDEF : {input.LT(1).getText().equals("def")}? NAME ; //keyDEL : {input.LT(1).getText().equals("del")}? NAME ; //keyELIF : {input.LT(1).getText().equals("elif")}? NAME ; @@ -1126,7 +1129,8 @@ 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 ; +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 ; //keyNOT : {input.LT(1).getText().equals("not")}? NAME ; @@ -1138,7 +1142,6 @@ //keyYIELD : {input.LT(1).getText().equals("yield")}? NAME ; DEF : 'def' ; -CLASS : 'class' ; PRINT : 'print' ; BREAK : 'break' ; CONTINUE : 'continue' ; @@ -1150,7 +1153,6 @@ FOR : 'for' ; ORELSE : 'else' ; ELIF : 'elif' ; -IN : 'in' ; IF : 'if' ; WHILE : 'while' ; WITH : 'with' ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-05 23:46:30 UTC (rev 5087) +++ branches/asm/grammar/PythonWalker.g 2008-08-06 02:19:54 UTC (rev 5088) @@ -748,7 +748,7 @@ //Using NAME instead of 'exec' for Java integration exec_stmt - : ^(NAME exec=test[expr_contextType.Load] (^(Globals globals=test[expr_contextType.Load]))? (^(Locals locals=test[expr_contextType.Load]))?) { + : ^(ExecTok exec=test[expr_contextType.Load] (^(Globals globals=test[expr_contextType.Load]))? (^(Locals locals=test[expr_contextType.Load]))?) { exprType g = null; if ($Globals != null) { g = $globals.etype; @@ -757,7 +757,7 @@ if ($Locals != null) { loc = $locals.etype; } - $stmts::statements.add(new Exec($NAME, $exec.etype, g, loc)); + $stmts::statements.add(new Exec($ExecTok, $exec.etype, g, loc)); } ; @@ -817,7 +817,7 @@ ; for_stmt - : ^(FOR ^(Target targ=test[expr_contextType.Store]) ^(IN iter=test[expr_contextType.Load]) ^(Body body=stmts) (^(ORELSE orelse=stmts))?) { + : ^(FOR ^(Target targ=test[expr_contextType.Store]) ^(InTok iter=test[expr_contextType.Load]) ^(Body body=stmts) (^(ORELSE orelse=stmts))?) { List o = null; if ($ORELSE != null) { o = $orelse.stypes; @@ -1040,7 +1040,7 @@ | LESSEQUAL {$op = cmpopType.LtE;} | ALT_NOTEQUAL {$op = cmpopType.NotEq;} | NOTEQUAL {$op = cmpopType.NotEq;} - | IN {$op = cmpopType.In;} + | InTok {$op = cmpopType.In;} | NotIn {$op = cmpopType.NotIn;} | 'is' {$op = cmpopType.Is;} | IsNot {$op = cmpopType.IsNot;} @@ -1265,14 +1265,14 @@ ; classdef - : ^(CLASS classname=NAME (^(Bases bases))? ^(Body stmts)) { + : ^(ClassTok classname=NAME (^(Bases bases))? ^(Body stmts)) { List b; if ($Bases != null) { b = $bases.names; } else { b = new ArrayList(); } - $stmts::statements.add(makeClassDef($CLASS, $classname, b, $stmts.stypes)); + $stmts::statements.add(makeClassDef($ClassTok, $classname, b, $stmts.stypes)); } ; @@ -1365,7 +1365,7 @@ list_for [List gens] : - ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(IN iter=test[expr_contextType.Load]) (^(Ifs list_iter[gens]))?) { + ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(InTok iter=test[expr_contextType.Load]) (^(Ifs list_iter[gens]))?) { debug("matched list_for"); exprType[] e; if ($Ifs != null && $list_iter.etype != null) { @@ -1391,7 +1391,7 @@ ; gen_for [List gens] - : ^(GenFor ^(Target targ=test[expr_contextType.Store]+) ^(IN iter=test[expr_contextType.Load]) (^(Ifs gen_iter[gens]))?) { + : ^(GenFor ^(Target targ=test[expr_contextType.Store]+) ^(InTok 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. |
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. |
From: <fwi...@us...> - 2008-08-11 05:37:18
|
Revision: 5145 http://jython.svn.sourceforge.net/jython/?rev=5145&view=rev Author: fwierzbicki Date: 2008-08-11 05:37:15 +0000 (Mon, 11 Aug 2008) Log Message: ----------- Properly handle tuples in subscripts (last test_grammar problem!) 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-11 05:35:18 UTC (rev 5144) +++ branches/asm/grammar/Python.g 2008-08-11 05:37:15 UTC (rev 5145) @@ -829,8 +829,9 @@ ; //subscriptlist: subscript (',' subscript)* [','] -subscriptlist : subscript (options {greedy=true;}:COMMA subscript)* (COMMA)? - -> subscript+ +subscriptlist : subscript (options {greedy=true;}:c1=COMMA subscript)* (c2=COMMA)? + -> { $c1 != null || $c2 != null }? ^(Tuple ^(Elts subscript+)) + -> subscript ; //subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop] Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-11 05:35:18 UTC (rev 5144) +++ branches/asm/grammar/PythonWalker.g 2008-08-11 05:37:15 UTC (rev 5145) @@ -982,33 +982,37 @@ $marker = $test.marker; } | ^(SubscriptList subscriptlist test[expr_contextType.Load]) { - //XXX: only handling one subscript for now. - sliceType s; + sliceType s = null; List sltypes = $subscriptlist.sltypes; - if (sltypes.size() == 0) { - s = null; - } else if (sltypes.size() == 1){ - s = (sliceType)sltypes.get(0); - } else { + boolean extslice = false; + if ($subscriptlist.isTuple) { sliceType[] st; - //FIXME: here I am using ClassCastException to decide if sltypes is populated with Index - // only. Clearly this is not the best way to do this but it's late. Somebody do - // something better please :) -- (hopefully a note to self) - try { - Iterator iter = sltypes.iterator(); - List etypes = new ArrayList(); - while (iter.hasNext()) { - Index i = (Index)iter.next(); + Iterator iter = sltypes.iterator(); + List etypes = new ArrayList(); + while (iter.hasNext()) { + Object o = iter.next(); + if (o instanceof Index) { + Index i = (Index)o; etypes.add(i.value); + } else { + extslice = true; + break; } + } + if (!extslice) { exprType[] es = (exprType[])etypes.toArray(new exprType[etypes.size()]); exprType t = new Tuple($SubscriptList, es, expr_contextType.Load); s = new Index($SubscriptList, t); - } catch (ClassCastException cc) { - st = (sliceType[])sltypes.toArray(new sliceType[sltypes.size()]); - s = new ExtSlice($SubscriptList, st); } + } else if (sltypes.size() == 1) { + s = (sliceType)sltypes.get(0); + } else if (sltypes.size() != 0) { + extslice = true; } + if (extslice) { + sliceType[] st = (sliceType[])sltypes.toArray(new sliceType[sltypes.size()]); + s = new ExtSlice($SubscriptList, st); + } $etype = new Subscript($test.marker, $test.etype, s, ctype); $marker = $test.marker; } @@ -1082,13 +1086,18 @@ } ; -subscriptlist returns [List sltypes] +subscriptlist returns [List sltypes, boolean isTuple] @init { List subs = new ArrayList(); } - : subscript[subs]+ { + : subscript[subs] { $sltypes = subs; + $isTuple = false; } + | ^(Tuple ^(Elts subscript[subs]+)) { + $sltypes = subs; + $isTuple = true; + } ; subscript [List subs] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-11 12:45:01
|
Revision: 5149 http://jython.svn.sourceforge.net/jython/?rev=5149&view=rev Author: fwierzbicki Date: 2008-08-11 12:44:54 +0000 (Mon, 11 Aug 2008) Log Message: ----------- Switch to for-each syntax in walker. 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-11 07:03:25 UTC (rev 5148) +++ branches/asm/grammar/Python.g 2008-08-11 12:44:54 UTC (rev 5149) @@ -178,7 +178,6 @@ import org.python.core.PyUnicode; import java.math.BigInteger; -import java.util.Iterator; } @members { Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-11 07:03:25 UTC (rev 5148) +++ branches/asm/grammar/PythonWalker.g 2008-08-11 12:44:54 UTC (rev 5149) @@ -987,10 +987,8 @@ boolean extslice = false; if ($subscriptlist.isTuple) { sliceType[] st; - Iterator iter = sltypes.iterator(); List etypes = new ArrayList(); - while (iter.hasNext()) { - Object o = iter.next(); + for (Object o : sltypes) { if (o instanceof Index) { Index i = (Index)o; etypes.add(i.value); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |