From: <fwi...@us...> - 2008-12-31 22:55:28
|
Revision: 5820 http://jython.svn.sourceforge.net/jython/?rev=5820&view=rev Author: fwierzbicki Date: 2008-12-31 21:37:59 +0000 (Wed, 31 Dec 2008) Log Message: ----------- test216 -> test_codeop_jy.py (plus more like this test) Also cleaned up test_codeop.py so we are more like CPython, we are close to deleting our local version of test_codeop.py. Improved trailing \ support in grammar Added a number of checks for invalid del statements. Modified Paths: -------------- trunk/jython/Lib/test/test_codeop.py trunk/jython/Lib/test/test_codeop_jy.py trunk/jython/grammar/Python.g trunk/jython/grammar/PythonPartial.g trunk/jython/src/org/python/antlr/GrammarActions.java Removed Paths: ------------- trunk/jython/bugtests/test216.py trunk/jython/bugtests/test216s1.py Modified: trunk/jython/Lib/test/test_codeop.py =================================================================== --- trunk/jython/Lib/test/test_codeop.py 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/Lib/test/test_codeop.py 2008-12-31 21:37:59 UTC (rev 5820) @@ -86,22 +86,12 @@ av("def x():\n\n pass\n") av("def x():\n pass\n \n") av("def x():\n pass\n \n") - ##next 4 added for Jython - av("\n\ndef x():\n pass\n") - av("def x():\n\n pass\n") # failed under Jython 2.1 - av("def x():\n pass\n \n") - av("def x():\n pass\n \n") - # this failed under 2.2.1 - av("def x():\n try: pass\n finally: [a for a in (1,2)]\n") - av("pass\n") av("3**3\n") av("if 9==3:\n pass\nelse:\n pass\n") av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") - #next 2 added for Jython - av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") av("#a\n#b\na = 3\n") av("#a\n\n \na=3\n") @@ -132,7 +122,6 @@ ai("if 9==3:\n pass\nelse:") ai("if 9==3:\n pass\nelse:\n") ai("if 9==3:\n pass\nelse:\n pass") - ai("if 1:") ai("if 1:\n") ai("if 1:\n pass\n if 1:\n pass\n else:") @@ -148,7 +137,7 @@ #ai("def x():\n pass\n ") ai("\n\ndef x():\n pass") - #ai("a = 9+ \\") + ai("a = 9+ \\") #ai("a = 'a\\") ai("a = '''xy") @@ -157,7 +146,7 @@ ai("(","eval") ai("(\n\n\n","eval") ai("(9+","eval") - #ai("9+ \\","eval") + ai("9+ \\","eval") #ai("lambda z: \\","eval") def test_invalid(self): @@ -175,21 +164,18 @@ ai("\n\n if 1: pass\n\npass") - ai("a = 9+ \\\n") + #ai("a = 9+ \\\n") ai("a = 'a\\ ") ai("a = 'a\\\n") - #XXX: eval is hopelessly permissive right now -- but the rest of this - # test_jy_compile is really important to me for flagging new bugs - - # so commenting out these for now. - #ai("a = 1","eval") + ai("a = 1","eval") #ai("a = (","eval") - #ai("]","eval") - #ai("())","eval") - #ai("[}","eval") - #ai("9+","eval") - #ai("lambda z:","eval") - #ai("a b","eval") + ai("]","eval") + ai("())","eval") + ai("[}","eval") + ai("9+","eval") + ai("lambda z:","eval") + ai("a b","eval") def test_filename(self): self.assertEquals(compile_command("a = 1\n", "abc").co_filename, Modified: trunk/jython/Lib/test/test_codeop_jy.py =================================================================== --- trunk/jython/Lib/test/test_codeop_jy.py 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/Lib/test/test_codeop_jy.py 2008-12-31 21:37:59 UTC (rev 5820) @@ -65,6 +65,12 @@ av("def x():\n pass\n \n") av("def x():\n pass\n \n") + # this failed under 2.2.1 + av("def x():\n try: pass\n finally: [a for a in (1,2)]\n") + + av("if 9==3:\n pass\nelse:\n pass\n") + av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") + av("pass\n") av("3**3\n") @@ -160,6 +166,11 @@ ai("lambda z:","eval") ai("a b","eval") ai("return 2.3") + ai("del 1") + ai("del ()") + ai("del (1,)") + ai("del [1]") + ai("del '1'") def test_filename(self): self.assertEquals(compile_("a = 1\n", "abc").co_filename, Deleted: trunk/jython/bugtests/test216.py =================================================================== --- trunk/jython/bugtests/test216.py 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/bugtests/test216.py 2008-12-31 21:37:59 UTC (rev 5820) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -try: - import test216s1 -except SyntaxError: - pass -else: - raise support.TestError("Should raise SyntaxError") Deleted: trunk/jython/bugtests/test216s1.py =================================================================== --- trunk/jython/bugtests/test216s1.py 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/bugtests/test216s1.py 2008-12-31 21:37:59 UTC (rev 5820) @@ -1,11 +0,0 @@ -class Foo: - pass - -f = Foo() -f.bar = {} - -#f.bar("A") -#del f.bar("A") - -#f.bar("A") = 1 -del [1] \ No newline at end of file Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/grammar/Python.g 2008-12-31 21:37:59 UTC (rev 5820) @@ -73,6 +73,7 @@ tokens { INDENT; DEDENT; + TRAILBACKSLASH; //For dangling backslashes when partial parsing. } @header { @@ -1779,9 +1780,21 @@ */ CONTINUED_LINE : '\\' ('\r')? '\n' (' '|'\t')* { $channel=HIDDEN; } - ( nl=NEWLINE {emit(new CommonToken(NEWLINE,nl.getText()));} + ( nl=NEWLINE { + if (!partial) { + emit(new CommonToken(NEWLINE,nl.getText())); + } + } | - ) + ) { + if (input.LA(1) == -1) { + if (partial) { + emit(new CommonToken(TRAILBACKSLASH,"\\")); + } else { + throw new ParseException("unexpected character after line continuation character"); + } + } + } ; /** Treat a sequence of blank lines as a single blank line. If Modified: trunk/jython/grammar/PythonPartial.g =================================================================== --- trunk/jython/grammar/PythonPartial.g 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/grammar/PythonPartial.g 2008-12-31 21:37:59 UTC (rev 5820) @@ -73,49 +73,24 @@ } @members { - boolean debugOn = false; + private ErrorHandler errorHandler = new FailFastHandler(); - private void debug(String message) { - if (debugOn) { - System.out.println(message); + protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException { + if (errorHandler.mismatch(this, input, ttype, follow)) { + super.mismatch(input, ttype, follow); } } - /* - protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException { - throw new MismatchedTokenException(ttype, input); - } - protected void mismatch(IntStream input, RecognitionException e, BitSet follow) throws RecognitionException { - throw e; - } + protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) + throws RecognitionException { - protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) - throws RecognitionException - { - mismatch(input, ttype, follow); - return null; + Object o = errorHandler.recoverFromMismatchedToken(this, input, ttype, follow); + if (o != null) { + return o; + } + return super.recoverFromMismatchedToken(input, ttype, follow); } - */ - public void emitErrorMessage(String msg) { - //System.err.print("[EMITTING] "); - } - - public void reportError(RecognitionException e) { - //System.err.print("[REPORTING] "); - // if we've already reported an error and have not matched a token - // yet successfully, don't report any errors. - if ( state.errorRecovery ) { - System.err.print("[SPURIOUS] "); - return; - } - state.syntaxErrors++; // don't count spurious - state.errorRecovery = true; - - displayRecognitionError(this.getTokenNames(), e); - } - - } @rulecatch { @@ -187,7 +162,7 @@ | assert_stmt ; -expr_stmt : testlist {debug("matched expr_stmt");} +expr_stmt : testlist ( augassign yield_expr | augassign testlist | assigns @@ -338,12 +313,12 @@ ) ; -test: or_test {debug("matched test: or_test");} +test: or_test ( (IF or_test ELSE) => IF or_test ELSE test)? | lambdef ; -or_test : and_test (OR and_test)* {debug("matched or_test");} +or_test : and_test (OR and_test)* ; and_test : not_test (AND not_test)* @@ -369,7 +344,7 @@ | IS NOT ; -expr : xor_expr (VBAR xor_expr)* {debug("matched expr");} +expr : xor_expr (VBAR xor_expr)* ; xor_expr : and_expr (CIRCUMFLEX and_expr)* @@ -391,6 +366,7 @@ | MINUS factor | TILDE factor | power + | TRAILBACKSLASH ; power : atom (trailer)* (options {greedy=true;}:DOUBLESTAR factor)? @@ -409,7 +385,7 @@ | LONGINT | FLOAT | COMPLEX - | (STRING)+ {debug("matched STRING");} + | (STRING)+ | STRINGPART ; @@ -449,7 +425,7 @@ ; testlist - : test (options {k=2;}: COMMA test)* (COMMA)? {debug("matched testlist");} + : test (options {k=2;}: COMMA test)* (COMMA)? ; dictmaker : test COLON test (options {k=2;}:COMMA test COLON test)* (COMMA)? Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2008-12-31 21:36:03 UTC (rev 5819) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2008-12-31 21:37:59 UTC (rev 5820) @@ -637,16 +637,40 @@ } } - List<expr> makeDeleteList(List e) { - List<expr> exprs = castExprs(e); - for(expr expr : exprs) { - if (expr instanceof Call) { - errorHandler.error("can't delete function call", expr); - } + List<expr> makeDeleteList(List deletes) { + List<expr> exprs = castExprs(deletes); + for(expr e : exprs) { + checkDelete(e); } return exprs; } + void checkDelete(expr e) { + //System.out.println("trying to del " + e); + if (e instanceof Call) { + errorHandler.error("can't delete function call", e); + } else if (e instanceof Num) { + errorHandler.error("can't delete number", e); + } else if (e instanceof Str) { + errorHandler.error("can't delete string", e); + } else if (e instanceof Tuple) { + //XXX: performance problem? Any way to do this better? + List<expr> elts = ((Tuple)e).getInternalElts(); + if (elts.size() == 0) { + errorHandler.error("can't delete ()", e); + } + for (int i=0;i<elts.size();i++) { + checkDelete(elts.get(i)); + } + } else if (e instanceof org.python.antlr.ast.List) { + //XXX: performance problem? Any way to do this better? + List<expr> elts = ((org.python.antlr.ast.List)e).getInternalElts(); + for (int i=0;i<elts.size();i++) { + checkDelete(elts.get(i)); + } + } + } + slice makeSubscript(PythonTree lower, Token colon, PythonTree upper, PythonTree sliceop) { boolean isSlice = false; expr s = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |