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