From: <fwi...@us...> - 2008-01-07 20:25:02
|
Revision: 4003 http://jython.svn.sourceforge.net/jython/?rev=4003&view=rev Author: fwierzbicki Date: 2008-01-07 12:24:57 -0800 (Mon, 07 Jan 2008) Log Message: ----------- parse the dots in import. Modified Paths: -------------- trunk/sandbox/ast/fails trunk/sandbox/ast/grammar/Python.g trunk/sandbox/ast/grammar/PythonWalker.g trunk/sandbox/ast/regr Modified: trunk/sandbox/ast/fails =================================================================== --- trunk/sandbox/ast/fails 2008-01-07 17:09:33 UTC (rev 4002) +++ trunk/sandbox/ast/fails 2008-01-07 20:24:57 UTC (rev 4003) @@ -6,8 +6,6 @@ ./run $RELEASE25/Lib/idlelib/FormatParagraph.py echo $RELEASE25/Lib/idlelib/PyParse.py ./run $RELEASE25/Lib/idlelib/PyParse.py -echo $RELEASE25/Lib/msilib/schema.py -./run $RELEASE25/Lib/msilib/schema.py # Most of the problems in plat-* have to do with backslash followed by # newline after a one line function def. This will take some lexer @@ -57,8 +55,6 @@ ./run ./run $RELEASE25/Lib/test/test_compile.py echo ./run $RELEASE25/Lib/test/test_hexoct.py ./run $RELEASE25/Lib/test/test_hexoct.py -echo $RELEASE25/Lib/test/crashers/weakref_in_del.py -./run $RELEASE25/Lib/test/crashers/weakref_in_del.py echo $RELEASE25/Lib/test/test_complex.py ./run $RELEASE25/Lib/test/test_complex.py echo $RELEASE25/Lib/test/test_complex_args.py Modified: trunk/sandbox/ast/grammar/Python.g =================================================================== --- trunk/sandbox/ast/grammar/Python.g 2008-01-07 17:09:33 UTC (rev 4002) +++ trunk/sandbox/ast/grammar/Python.g 2008-01-07 20:24:57 UTC (rev 4003) @@ -83,6 +83,7 @@ Msg; Import; ImportFrom; + Level; Name; Body; ClassDef; @@ -451,11 +452,11 @@ // 'import' ('*' | '(' import_as_names ')' | import_as_names)) import_from: 'from' (DOT* dotted_name | DOT+) 'import' (STAR - -> ^(ImportFrom dotted_name ^(Import STAR)) + -> ^(ImportFrom ^(Level DOT*)? ^(Name dotted_name)? ^(Import STAR)) | import_as_names - -> ^(ImportFrom dotted_name ^(Import import_as_names)) + -> ^(ImportFrom ^(Level DOT*)? ^(Name dotted_name)? ^(Import import_as_names)) | LPAREN import_as_names RPAREN - -> ^(ImportFrom dotted_name ^(Import import_as_names)) + -> ^(ImportFrom ^(Level DOT*)? ^(Name dotted_name)? ^(Import import_as_names)) ) ; Modified: trunk/sandbox/ast/grammar/PythonWalker.g =================================================================== --- trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-07 17:09:33 UTC (rev 4002) +++ trunk/sandbox/ast/grammar/PythonWalker.g 2008-01-07 20:24:57 UTC (rev 4003) @@ -644,18 +644,47 @@ aliasType[] n = (aliasType[])nms.toArray(new aliasType[nms.size()]); $stmts::statements.add(new Import($Import, n)); } - | ^(ImportFrom dotted_name ^(Import STAR)) { - //XXX here + | ^(ImportFrom (^(Level dots))? (^(Name dotted_name))? ^(Import STAR)) { + String name = ""; + if ($Name != null) { + name = $dotted_name.result; + } + int level = 0; + if ($Level != null) { + level = $dots.level; + } aliasType[] n = (aliasType[])nms.toArray(new aliasType[nms.size()]); - $stmts::statements.add(new ImportFrom($Import, $dotted_name.result, new aliasType[]{new aliasType($STAR, "*", null)}, 0)); + $stmts::statements.add(new ImportFrom($Import, name, new aliasType[]{new aliasType($STAR, "*", null)}, level)); } - | ^(ImportFrom dotted_name ^(Import import_as_name[nms]+)) { - //XXX here + | ^(ImportFrom (^(Level dots))? (^(Name dotted_name))? ^(Import import_as_name[nms]+)) { + String name = ""; + if ($Name != null) { + name = $dotted_name.result; + } + int level = 0; + if ($Level != null) { + level = $dots.level; + } aliasType[] n = (aliasType[])nms.toArray(new aliasType[nms.size()]); - $stmts::statements.add(new ImportFrom($Import, $dotted_name.result, n, 0)); + $stmts::statements.add(new ImportFrom($Import, name, n, level)); } ; + +//XXX: surely there is a simler way to count these dots. +dots returns [int level] +@init { + StringBuffer buf = new StringBuffer(); +} + : dot[buf]+ { + $level = buf.length(); + } + ; + +dot[StringBuffer buf] + : DOT{buf.append(".");} + ; + import_as_name[List nms] : ^(Alias name=NAME (^(Asname asname=NAME))?) { String as = null; Modified: trunk/sandbox/ast/regr =================================================================== --- trunk/sandbox/ast/regr 2008-01-07 17:09:33 UTC (rev 4002) +++ trunk/sandbox/ast/regr 2008-01-07 20:24:57 UTC (rev 4003) @@ -479,7 +479,7 @@ ./run $RELEASE25/Lib/mimify.py ./run $RELEASE25/Lib/modulefinder.py ./run $RELEASE25/Lib/msilib/__init__.py -#./run $RELEASE25/Lib/msilib/schema.py +./run $RELEASE25/Lib/msilib/schema.py ./run $RELEASE25/Lib/msilib/sequence.py ./run $RELEASE25/Lib/msilib/text.py ./run $RELEASE25/Lib/multifile.py @@ -822,7 +822,7 @@ ./run $RELEASE25/Lib/test/crashers/nasty_eq_vs_dict.py ./run $RELEASE25/Lib/test/crashers/recursion_limit_too_high.py ./run $RELEASE25/Lib/test/crashers/recursive_call.py -#./run $RELEASE25/Lib/test/crashers/weakref_in_del.py +./run $RELEASE25/Lib/test/crashers/weakref_in_del.py ./run $RELEASE25/Lib/test/doctest_aliases.py ./run $RELEASE25/Lib/test/double_const.py echo Lib/test/f This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |