You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <zy...@us...> - 2008-08-18 07:17:50
|
Revision: 5196 http://jython.svn.sourceforge.net/jython/?rev=5196&view=rev Author: zyasoft Date: 2008-08-18 07:17:46 +0000 (Mon, 18 Aug 2008) Log Message: ----------- Strings are UTF-8 encoded in the runtime constant pool, meaning that naively (and that is a reasonable strategy here), we need up to 4 bytes per codepoint. So allocate string constants up to 16000 bytes and combine as necessary. This resolves one Pygments problem (and the one we can directly do anything about, the other is isolated surrogates in unistring.Cs). Modified Paths: -------------- branches/asm/src/org/python/compiler/Code.java Modified: branches/asm/src/org/python/compiler/Code.java =================================================================== --- branches/asm/src/org/python/compiler/Code.java 2008-08-18 02:39:57 UTC (rev 5195) +++ branches/asm/src/org/python/compiler/Code.java 2008-08-18 07:17:46 UTC (rev 5196) @@ -504,7 +504,8 @@ if (cst instanceof String) { String value = (String) cst; final int len = value.length(); - final int maxlen = 32767; + // 65535 / 4 (max utf-8 expansion for non BMP characters) + final int maxlen = 16000; if (len > maxlen) { new_("java/lang/StringBuilder"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-08-18 02:40:00
|
Revision: 5195 http://jython.svn.sourceforge.net/jython/?rev=5195&view=rev Author: leosoto Date: 2008-08-18 02:39:57 +0000 (Mon, 18 Aug 2008) Log Message: ----------- PyArray#array_fromunicode: Worked around the issue described on #1105 (wrong exposed bytecode when receiving a PyUnicode argument on a exposed method), by receiving a PyObject and doing the type-check manually Modified Paths: -------------- branches/asm/src/org/python/core/PyArray.java Modified: branches/asm/src/org/python/core/PyArray.java =================================================================== --- branches/asm/src/org/python/core/PyArray.java 2008-08-18 02:12:34 UTC (rev 5194) +++ branches/asm/src/org/python/core/PyArray.java 2008-08-18 02:39:57 UTC (rev 5195) @@ -978,7 +978,10 @@ } @ExposedMethod - final void array_fromunicode(PyUnicode input) { + final void array_fromunicode(PyObject input) { + if (!(input instanceof PyUnicode)) { + throw Py.ValueError("fromunicode argument must be an unicode object"); + } if (!"u".equals(typecode)) { throw Py.ValueError("fromunicode() may only be called on type 'u' arrays"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-08-18 02:12:37
|
Revision: 5194 http://jython.svn.sourceforge.net/jython/?rev=5194&view=rev Author: leosoto Date: 2008-08-18 02:12:34 +0000 (Mon, 18 Aug 2008) Log Message: ----------- PythonInterpreter#cflags initialization moved to PythonInterpreter itself. Fixes a crash on modjy Modified Paths: -------------- branches/asm/src/org/python/util/InteractiveInterpreter.java branches/asm/src/org/python/util/PythonInterpreter.java Modified: branches/asm/src/org/python/util/InteractiveInterpreter.java =================================================================== --- branches/asm/src/org/python/util/InteractiveInterpreter.java 2008-08-17 15:24:17 UTC (rev 5193) +++ branches/asm/src/org/python/util/InteractiveInterpreter.java 2008-08-18 02:12:34 UTC (rev 5194) @@ -14,7 +14,6 @@ } public InteractiveInterpreter(PyObject locals, PySystemState systemState) { super(locals, systemState); - cflags = new CompilerFlags(); } /** Modified: branches/asm/src/org/python/util/PythonInterpreter.java =================================================================== --- branches/asm/src/org/python/util/PythonInterpreter.java 2008-08-17 15:24:17 UTC (rev 5193) +++ branches/asm/src/org/python/util/PythonInterpreter.java 2008-08-18 02:12:34 UTC (rev 5194) @@ -16,7 +16,7 @@ protected PySystemState systemState; PyObject locals; - protected CompilerFlags cflags = null; + protected CompilerFlags cflags = new CompilerFlags(); /** * Initializes the jython runtime. This should only be called once, and This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-17 15:24:20
|
Revision: 5193 http://jython.svn.sourceforge.net/jython/?rev=5193&view=rev Author: nriley Date: 2008-08-17 15:24:17 +0000 (Sun, 17 Aug 2008) Log Message: ----------- Better comment for PySystemState method hack: depends on "functions" in __dict__ appearing as methods. Modified Paths: -------------- branches/asm/src/org/python/core/PySystemState.java Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-08-17 02:23:19 UTC (rev 5192) +++ branches/asm/src/org/python/core/PySystemState.java 2008-08-17 15:24:17 UTC (rev 5193) @@ -214,7 +214,7 @@ if (ret != null) { if (ret instanceof PyMethod) { if (__dict__.__finditem__(name) instanceof PyReflectedFunction) - return ret; // xxx hack + return ret; // xxx depends on nonstandard __dict__ } else if (ret == PyAttributeDeleted.INSTANCE) { return null; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-17 02:23:21
|
Revision: 5192 http://jython.svn.sourceforge.net/jython/?rev=5192&view=rev Author: nriley Date: 2008-08-17 02:23:19 +0000 (Sun, 17 Aug 2008) Log Message: ----------- Option to enable bytecode verifier. Modified Paths: -------------- branches/asm/src/shell/jython Modified: branches/asm/src/shell/jython =================================================================== --- branches/asm/src/shell/jython 2008-08-17 00:02:42 UTC (rev 5191) +++ branches/asm/src/shell/jython 2008-08-17 02:23:19 UTC (rev 5192) @@ -118,6 +118,10 @@ java_args=("${java_args[@]}" -javaagent:"$agent_path" -Dprofile.properties="$props_path") ;; + # Don't put Jython on the boot classpath (enables the verifier) + --verify) + verify_requested=true + ;; # Run under JDB --jdb) if [ -z "$JAVA_HOME" ] ; then @@ -169,8 +173,8 @@ fi fi -if [ -n "$profile_requested" ] ; then - echo "Running with instrumented profiler" +if [ -n "$profile_requested" -o -n "$verify_requested" ] ; then + [ -n "$profile_requested" ] && echo "Running with instrumented profiler" java_args=("${java_args[@]}" -classpath "$CP$CP_DELIMITER$CLASSPATH") else if [ -z $help_requested ] ; then @@ -190,6 +194,7 @@ echo "-Jarg : pass argument through to Java VM (e.g. -J-Xmx512m)" >&2 echo "--jdb : run under JDB" >&2 echo "--profile: run with the Java Interactive Profiler (http://jiprof.sf.net)" >&2 + echo "--verify : enable bytecode verifier for Jython classes (for development)" >&2 echo "-- : pass remaining arguments through to Jython" >&2 echo "Jython launcher environment variables:" >&2 echo "JAVA_HOME : Java installation directory" >&2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-17 00:02:48
|
Revision: 5191 http://jython.svn.sourceforge.net/jython/?rev=5191&view=rev Author: fwierzbicki Date: 2008-08-17 00:02:42 +0000 (Sun, 17 Aug 2008) Log Message: ----------- check for Py.None in runCode as well as null for locals and globals. Fixes test_decorators.py Modified Paths: -------------- branches/asm/src/org/python/core/Py.java Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-08-16 22:46:04 UTC (rev 5190) +++ branches/asm/src/org/python/core/Py.java 2008-08-17 00:02:42 UTC (rev 5191) @@ -1178,15 +1178,15 @@ public static PyObject runCode(PyCode code, PyObject locals, PyObject globals) { PyFrame f; - if (locals == null) { - if (globals != null) { + if (locals == null || locals == Py.None) { + if (globals != null && globals != Py.None) { locals = globals; } else { locals = Py.getFrame().getLocals(); } } - if (globals == null) { + if (globals == null || globals == Py.None) { globals = Py.getFrame().f_globals; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-16 22:46:09
|
Revision: 5190 http://jython.svn.sourceforge.net/jython/?rev=5190&view=rev Author: fwierzbicki Date: 2008-08-16 22:46:04 +0000 (Sat, 16 Aug 2008) Log Message: ----------- Fix comment/newline parsing problems in interactive (single) parsing. Modified Paths: -------------- branches/asm/src/org/python/antlr/PythonTokenSource.java Modified: branches/asm/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-16 19:31:55 UTC (rev 5189) +++ branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-16 22:46:04 UTC (rev 5190) @@ -146,7 +146,6 @@ } private void generateNewline(Token t) { - // Imaginary newline before EOF CommonToken newline = new CommonToken(PythonLexer.NEWLINE, "\n"); newline.setLine(t.getLine()); newline.setCharPositionInLine(t.getCharPositionInLine()); @@ -158,9 +157,11 @@ stream.consume(); if (t.getType() == Token.EOF) { - Token prev = stream.LT(-1); - if (!inSingle && (prev == null || prev.getType() != PythonLexer.NEWLINE)) { - generateNewline(t); + if (!inSingle) { + Token prev = stream.LT(-1); + if (prev == null || prev.getType() != PythonLexer.NEWLINE) { + generateNewline(t); + } } handleDedents(-1, (CommonToken)t); @@ -168,7 +169,7 @@ } else if (t.getType() == PythonLexer.NEWLINE) { // save NEWLINE in the queue //System.out.println("found newline: "+t+" stack is "+stackString()); - updateLastTokenAddedIndex(t); + enqueueHiddens(t); tokens.addElement(t); Token newline = t; @@ -176,7 +177,7 @@ t = stream.LT(1); stream.consume(); - updateLastTokenAddedIndex(t); + enqueueHiddens(t); // compute cpos as the char pos of next non-WS token in line int cpos = t.getCharPositionInLine(); // column dictates indent/dedent @@ -222,11 +223,24 @@ } private void enqueue(Token t) { - updateLastTokenAddedIndex(t); + enqueueHiddens(t); tokens.addElement(t); } - private void updateLastTokenAddedIndex(Token t) { + private void enqueueHiddens(Token t) { + if (inSingle && t.getType() == Token.EOF) { + if (stream.size() > lastTokenAddedIndex + 1) { + Token hidden = stream.get(lastTokenAddedIndex + 1); + if (hidden.getType() == PythonLexer.COMMENT) { + String text = hidden.getText(); + int i = text.indexOf("\n"); + while(i != -1) { + generateNewline(hidden); + i = text.indexOf("\n", i + 1); + } + } + } + } List hiddenTokens = stream.getTokens(lastTokenAddedIndex + 1,t.getTokenIndex() - 1); if (hiddenTokens != null) { tokens.addAll(hiddenTokens); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-16 19:31:58
|
Revision: 5189 http://jython.svn.sourceforge.net/jython/?rev=5189&view=rev Author: fwierzbicki Date: 2008-08-16 19:31:55 +0000 (Sat, 16 Aug 2008) Log Message: ----------- Shouldn't be discarding hidden tokens. Modified Paths: -------------- branches/asm/src/org/python/antlr/ExpressionParser.java branches/asm/src/org/python/antlr/InteractiveParser.java branches/asm/src/org/python/antlr/ModuleParser.java branches/asm/src/org/python/core/ParserFacade.java branches/asm/tests/java/org/python/antlr/PythonPartialTester.java branches/asm/tests/java/org/python/antlr/PythonTreeTester.java Modified: branches/asm/src/org/python/antlr/ExpressionParser.java =================================================================== --- branches/asm/src/org/python/antlr/ExpressionParser.java 2008-08-16 13:56:28 UTC (rev 5188) +++ branches/asm/src/org/python/antlr/ExpressionParser.java 2008-08-16 19:31:55 UTC (rev 5189) @@ -26,7 +26,6 @@ PythonLexer lexer = new PyLexer(this.charStream); lexer.setErrorHandler(errorHandler); CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); Modified: branches/asm/src/org/python/antlr/InteractiveParser.java =================================================================== --- branches/asm/src/org/python/antlr/InteractiveParser.java 2008-08-16 13:56:28 UTC (rev 5188) +++ branches/asm/src/org/python/antlr/InteractiveParser.java 2008-08-16 19:31:55 UTC (rev 5189) @@ -31,7 +31,6 @@ PythonLexer lexer = new PyLexer(new NoCloseReaderStream(bufreader)); lexer.setErrorHandler(errorHandler); CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename, true); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); Modified: branches/asm/src/org/python/antlr/ModuleParser.java =================================================================== --- branches/asm/src/org/python/antlr/ModuleParser.java 2008-08-16 13:56:28 UTC (rev 5188) +++ branches/asm/src/org/python/antlr/ModuleParser.java 2008-08-16 19:31:55 UTC (rev 5189) @@ -30,7 +30,6 @@ PythonLexer lexer = new PyLexer(this.charStream); lexer.setErrorHandler(errorHandler); CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-08-16 13:56:28 UTC (rev 5188) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-08-16 19:31:55 UTC (rev 5189) @@ -170,7 +170,6 @@ lexer = new BaseParser.PyLexer(cs); lexer.partial = true; CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); tokens = new CommonTokenStream(indentedSource); PythonPartialParser parser = new PythonPartialParser(tokens); Modified: branches/asm/tests/java/org/python/antlr/PythonPartialTester.java =================================================================== --- branches/asm/tests/java/org/python/antlr/PythonPartialTester.java 2008-08-16 13:56:28 UTC (rev 5188) +++ branches/asm/tests/java/org/python/antlr/PythonPartialTester.java 2008-08-16 19:31:55 UTC (rev 5189) @@ -16,7 +16,6 @@ CharStream input = new ANTLRFileStream(args[0]); PythonLexer lexer = new BaseParser.PyLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); //PythonTokenSource indentedSource = new PythonTokenSource(tokens); PythonTokenSource indentedSource = new PythonTokenSource(tokens, "<test>"); tokens = new CommonTokenStream(indentedSource); Modified: branches/asm/tests/java/org/python/antlr/PythonTreeTester.java =================================================================== --- branches/asm/tests/java/org/python/antlr/PythonTreeTester.java 2008-08-16 13:56:28 UTC (rev 5188) +++ branches/asm/tests/java/org/python/antlr/PythonTreeTester.java 2008-08-16 19:31:55 UTC (rev 5189) @@ -33,7 +33,6 @@ PythonLexer lexer = new ModuleParser.PyLexer(input); lexer.setErrorHandler(eh); CommonTokenStream tokens = new CommonTokenStream(lexer); - tokens.discardOffChannelTokens(true); PythonTokenSource indentedSource = new PythonTokenSource(tokens, args[0]); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-16 13:56:31
|
Revision: 5188 http://jython.svn.sourceforge.net/jython/?rev=5188&view=rev Author: fwierzbicki Date: 2008-08-16 13:56:28 +0000 (Sat, 16 Aug 2008) Log Message: ----------- Method not used. Modified Paths: -------------- branches/asm/src/org/python/core/ParserFacade.java Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-08-16 06:22:40 UTC (rev 5187) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-08-16 13:56:28 UTC (rev 5188) @@ -90,11 +90,6 @@ else return Py.JavaError(t); } - public static PythonTree parse(String string, String kind) { - return parse(new ByteArrayInputStream(StringUtil.toBytes(string)), - kind, "<string>", null); - } - public static modType parse(InputStream stream, String kind, String filename, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-08-16 06:22:42
|
Revision: 5187 http://jython.svn.sourceforge.net/jython/?rev=5187&view=rev Author: zyasoft Date: 2008-08-16 06:22:40 +0000 (Sat, 16 Aug 2008) Log Message: ----------- input and raw_input now appropriately raise a RuntimeError if sys.stdin/stdout are deleted (via the facade of PySystemState.PyAttributeDeleted) Modified Paths: -------------- branches/asm/src/org/python/core/__builtin__.java Modified: branches/asm/src/org/python/core/__builtin__.java =================================================================== --- branches/asm/src/org/python/core/__builtin__.java 2008-08-16 06:18:30 UTC (rev 5186) +++ branches/asm/src/org/python/core/__builtin__.java 2008-08-16 06:22:40 UTC (rev 5187) @@ -1025,7 +1025,11 @@ } public static String raw_input(PyObject prompt, PyObject file) { - Py.print(prompt); + PyObject stdout = Py.getSystemState().stdout; + if (stdout instanceof PyAttributeDeleted) { + throw Py.RuntimeError("[raw_]input: lost sys.stdout"); + } + Py.print(stdout, prompt); String data = readline(file).toString(); if (data.endsWith("\n")) { return data.substring(0, data.length() - 1); @@ -1038,7 +1042,11 @@ } public static String raw_input(PyObject prompt) { - return raw_input(prompt, Py.getSystemState().stdin); + PyObject stdin = Py.getSystemState().stdin; + if (stdin instanceof PyAttributeDeleted) { + throw Py.RuntimeError("[raw_]input: lost sys.stdin"); + } + return raw_input(prompt, stdin); } public static String raw_input() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-16 06:18:32
|
Revision: 5186 http://jython.svn.sourceforge.net/jython/?rev=5186&view=rev Author: nriley Date: 2008-08-16 06:18:30 +0000 (Sat, 16 Aug 2008) Log Message: ----------- Update Eclipse classpath to Antlr 3.1 final. Modified Paths: -------------- branches/asm/.classpath Modified: branches/asm/.classpath =================================================================== --- branches/asm/.classpath 2008-08-16 06:09:33 UTC (rev 5185) +++ branches/asm/.classpath 2008-08-16 06:18:30 UTC (rev 5186) @@ -15,6 +15,6 @@ <classpathentry kind="lib" path="extlibs/servlet-api-2.5.jar"/> <classpathentry kind="lib" path="build/jarjar"/> <classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/> - <classpathentry kind="lib" path="extlibs/antlr-runtime-3.1b2.jar"/> + <classpathentry kind="lib" path="extlibs/antlr-runtime-3.1.jar"/> <classpathentry kind="output" path="bugtests/classes"/> </classpath> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-16 06:09:36
|
Revision: 5185 http://jython.svn.sourceforge.net/jython/?rev=5185&view=rev Author: nriley Date: 2008-08-16 06:09:33 +0000 (Sat, 16 Aug 2008) Log Message: ----------- Permit removal/modification of attributes on PySystemState; add __name__. Modified Paths: -------------- branches/asm/Lib/test/test_sys_jy.py branches/asm/src/org/python/core/PySystemState.java branches/asm/src/org/python/core/__builtin__.java Modified: branches/asm/Lib/test/test_sys_jy.py =================================================================== --- branches/asm/Lib/test/test_sys_jy.py 2008-08-16 05:35:48 UTC (rev 5184) +++ branches/asm/Lib/test/test_sys_jy.py 2008-08-16 06:09:33 UTC (rev 5185) @@ -4,11 +4,11 @@ import test.test_support class SysTest(unittest.TestCase): - + def test_platform(self): self.assertEquals(sys.platform[:4], "java", "sys.platform is not java") - + def test_exit_arg(self): "sys.exit can be called with args" try: @@ -25,8 +25,43 @@ tb = sys.exc_info()[2] if tb.tb_lineno == 0: self.fail("Traceback lineno was zero") - + def test_name(self): + "sys.__name__ can be reassigned/deleted" + self.assertEquals(sys.__name__, 'sys') + sys.__name__ = 'foo' + self.assert_('foo' in str(sys)) + del sys.__name__ + self.assert_('foo' not in str(sys)) + sys.__name__ = 'sys' + + def test_readonly(self): + def deleteClass(): del sys.__class__ + self.assertRaises(TypeError, deleteClass) + + def deleteDict(): del sys.__dict__ + self.assertRaises(TypeError, deleteDict) + + def assignClass(): sys.__class__ = object + self.assertRaises(TypeError, assignClass) + + def assignDict(): sys.__dict__ = {} + self.assertRaises(TypeError, assignDict) + + def test_resetmethod(self): + gde = sys.getdefaultencoding + sys.getdefaultencoding = 5 + self.assertEquals(sys.getdefaultencoding, 5) + del sys.getdefaultencoding + self.assertRaises(AttributeError, getattr, sys, 'getdefaultencoding') + sys.getdefaultencoding = gde + + def test_reload(self): + gde = sys.getdefaultencoding + del sys.getdefaultencoding + reload(sys) + self.assert_(type(sys.getdefaultencoding) == type(gde)) + def test_main(): test.test_support.run_unittest(SysTest) Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-08-16 05:35:48 UTC (rev 5184) +++ branches/asm/src/org/python/core/PySystemState.java 2008-08-16 06:09:33 UTC (rev 5185) @@ -129,6 +129,8 @@ public PyObject last_type = Py.None; public PyObject last_traceback = Py.None; + public PyObject __name__ = new PyString("sys"); + public PyObject __dict__; private int recursionlimit = 1000; @@ -168,13 +170,22 @@ PyModule __builtin__ = new PyModule("__builtin__", builtins); modules.__setitem__("__builtin__", __builtin__); - if (getType() != null) { - __dict__ = new PyStringMap(); - __dict__.invoke("update", getType().fastGetDict()); - __dict__.__setitem__("displayhook", __displayhook__); - __dict__.__setitem__("excepthook", __excepthook__); - } + __dict__ = new PyStringMap(); + + // This isn't right either, because __dict__ can be directly + // accessed from Python, for example: + // + // >>> sys.__dict__['settrace'] + // <java function settrace 81> + + __dict__.invoke("update", getType().fastGetDict()); + __dict__.__setitem__("displayhook", __displayhook__); + __dict__.__setitem__("excepthook", __excepthook__); } + + void reload() throws PyIgnoreMethodTag { + __dict__.invoke("update", getType().fastGetDict()); + } // xxx fix this accessors public PyObject __findattr_ex__(String name) { @@ -200,33 +211,43 @@ } PyObject ret = super.__findattr_ex__(name); - if (ret != null) return ret; + if (ret != null) { + if (ret instanceof PyMethod) { + if (__dict__.__finditem__(name) instanceof PyReflectedFunction) + return ret; // xxx hack + } else if (ret == PyAttributeDeleted.INSTANCE) { + return null; + } + else return ret; + } return __dict__.__finditem__(name); } public void __setattr__(String name, PyObject value) { - PyType selftype = getType(); - if (selftype == null) + if (name == "__dict__" || name == "__class__") + throw Py.TypeError("readonly attribute"); + PyObject ret = getType().lookup(name); // xxx fix fix fix + if (ret != null && ret.jtryset(this, value)) { return; - PyObject ret = selftype.lookup(name); // xxx fix fix fix - if (ret != null) { - ret.jtryset(this, value); - return; } - if (__dict__ == null) { - __dict__ = new PyStringMap(); - } __dict__.__setitem__(name, value); - //throw Py.AttributeError(name); } public void __delattr__(String name) { - if (__dict__ != null) { + if (name == "__dict__" || name == "__class__") + throw Py.TypeError("readonly attribute"); + PyObject ret = getType().lookup(name); // xxx fix fix fix + if (ret != null) { + ret.jtryset(this, PyAttributeDeleted.INSTANCE); + } + try { __dict__.__delitem__(name); - return; + } catch (PyException pye) { // KeyError + if (ret == null) { + throw Py.AttributeError(name); + } } - throw Py.AttributeError("del '"+name+"'"); } // xxx @@ -235,7 +256,7 @@ } public String toString() { - return "sys module"; + return "<module '" + __name__ + "' (built-in)>"; } public int getrecursionlimit() { @@ -945,3 +966,22 @@ } } } + +/** + * Value of a class or instance variable when the corresponding + * attribute is deleted. Used only in PySystemState for now. + */ +class PyAttributeDeleted extends PyObject { + final static PyAttributeDeleted INSTANCE = new PyAttributeDeleted(); + private PyAttributeDeleted() {} + public String toString() { return ""; } + public Object __tojava__(Class c) { + if (c == PyObject.class) + return this; + // we can't quite "delete" non-PyObject attributes; settle for + // null or nothing + if (c.isPrimitive()) + return Py.NoConversion; + return null; + } +} Modified: branches/asm/src/org/python/core/__builtin__.java =================================================================== --- branches/asm/src/org/python/core/__builtin__.java 2008-08-16 05:35:48 UTC (rev 5184) +++ branches/asm/src/org/python/core/__builtin__.java 2008-08-16 06:09:33 UTC (rev 5185) @@ -1075,7 +1075,8 @@ } public static PyObject reload(PySystemState o) { - // fake it like imp.reload(PyJavaClass) does + // reinitialize methods + o.reload(); return o; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-08-16 05:35:51
|
Revision: 5184 http://jython.svn.sourceforge.net/jython/?rev=5184&view=rev Author: zyasoft Date: 2008-08-16 05:35:48 +0000 (Sat, 16 Aug 2008) Log Message: ----------- Fixes for and in test_builtin: * test_builtin.test_cmp because we let Jython compare objects with cycles in them, unlike CPython * test_builtin.test_general_eval - Jython can use arbitrary maps for globals; this was discussed for CPython. Not in current 2.6, perhaps because it touched a lot of code or issues with performance (see http://bugs.python.org/issue1402289) * __builtin__#eval/compile - Now validate that locals or globals are in fact mapping objects, as well as ensure that locals().keys() is a PyList (to avoid throwing a CheckCastException) * Py#compile_flags - if passed in a String to compile, ensure it does not contain a null byte Modified Paths: -------------- branches/asm/Lib/test/test_builtin.py branches/asm/src/org/python/core/Py.java branches/asm/src/org/python/core/__builtin__.java Modified: branches/asm/Lib/test/test_builtin.py =================================================================== --- branches/asm/Lib/test/test_builtin.py 2008-08-15 23:03:17 UTC (rev 5183) +++ branches/asm/Lib/test/test_builtin.py 2008-08-16 05:35:48 UTC (rev 5184) @@ -209,15 +209,15 @@ self.assertEqual(cmp(-1, 1), -1) self.assertEqual(cmp(1, -1), 1) self.assertEqual(cmp(1, 1), 0) - # verify that circular objects are not handled + # verify that circular objects are handled for Jython a = []; a.append(a) b = []; b.append(b) from UserList import UserList c = UserList(); c.append(c) - self.assertRaises(RuntimeError, cmp, a, b) - self.assertRaises(RuntimeError, cmp, b, c) - self.assertRaises(RuntimeError, cmp, c, a) - self.assertRaises(RuntimeError, cmp, a, c) + self.assertEqual(cmp(a, b), 0) + self.assertEqual(cmp(b, c), 0) + self.assertEqual(cmp(c, a), 0) + self.assertEqual(cmp(a, c), 0) # okay, now break the cycles a.pop(); b.pop(); c.pop() self.assertRaises(TypeError, cmp) @@ -330,7 +330,9 @@ self.assertEqual(eval('dir()', g, m), list('xyz')) self.assertEqual(eval('globals()', g, m), g) self.assertEqual(eval('locals()', g, m), m) - self.assertRaises(TypeError, eval, 'a', m) + + # Jython allows arbitrary mappings for globals + self.assertEqual(eval('a', m), 12) class A: "Non-mapping" pass Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-08-15 23:03:17 UTC (rev 5183) +++ branches/asm/src/org/python/core/Py.java 2008-08-16 05:35:48 UTC (rev 5184) @@ -1682,6 +1682,11 @@ String filename, String type, CompilerFlags cflags) { + + if (data.contains("\0")) { + throw Py.TypeError("compile() expected string without null bytes"); + } + byte[] bytes; if (cflags.dont_imply_dedent) { bytes = StringUtil.toBytes(data + "\n"); Modified: branches/asm/src/org/python/core/__builtin__.java =================================================================== --- branches/asm/src/org/python/core/__builtin__.java 2008-08-15 23:03:17 UTC (rev 5183) +++ branches/asm/src/org/python/core/__builtin__.java 2008-08-16 05:35:48 UTC (rev 5184) @@ -479,14 +479,12 @@ public static PyObject dir() { PyObject l = locals(); PyList ret; - - if (l instanceof PyStringMap) { - ret = ((PyStringMap) l).keys(); - } else if (l instanceof PyDictionary) { - ret = ((PyDictionary) l).keys(); + PyObject retObj = l.invoke("keys"); + try { + ret = (PyList) retObj; + } catch (ClassCastException e) { + throw Py.TypeError("Expected keys() to be a list, not '" + retObj.getType().fastGetName() + "'"); } - - ret = (PyList) l.invoke("keys"); ret.sort(); return ret; } @@ -499,7 +497,25 @@ return new PyEnumerate(seq); } + private static boolean PyMapping_check(PyObject o, boolean rw) { + return o == null || + o == Py.None || + (o instanceof PyDictionary) || + (o.__findattr__("__getitem__") != null && + (!rw || o.__findattr__("__setitem__") != null)); + } + + private static void verify_mappings(PyObject globals, PyObject locals, boolean rw) { + if (!PyMapping_check(globals, rw)) { + throw Py.TypeError("globals must be a mapping"); + } + if (!PyMapping_check(locals, rw)) { + throw Py.TypeError("locals must be a mapping"); + } + } + public static PyObject eval(PyObject o, PyObject globals, PyObject locals) { + verify_mappings(globals, locals, false); PyCode code; if (o instanceof PyCode) { code = (PyCode) o; @@ -529,6 +545,7 @@ } public static void execfile_flags(String name, PyObject globals, PyObject locals, CompilerFlags cflags) { + verify_mappings(globals, locals, true); java.io.FileInputStream file; try { file = new java.io.FileInputStream(new RelativeFile(name)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-08-15 23:03:20
|
Revision: 5183 http://jython.svn.sourceforge.net/jython/?rev=5183&view=rev Author: leosoto Date: 2008-08-15 23:03:17 +0000 (Fri, 15 Aug 2008) Log Message: ----------- Reverted r5182, as the implementation of unicodedata.normalize required Java 1.6. Sorry! Modified Paths: -------------- branches/asm/src/org/python/modules/Setup.java Removed Paths: ------------- branches/asm/src/org/python/modules/unicodedata.java Modified: branches/asm/src/org/python/modules/Setup.java =================================================================== --- branches/asm/src/org/python/modules/Setup.java 2008-08-15 20:15:50 UTC (rev 5182) +++ branches/asm/src/org/python/modules/Setup.java 2008-08-15 23:03:17 UTC (rev 5183) @@ -55,7 +55,6 @@ "_hashlib", "_functools:org.python.modules._functools._functools", "_csv:org.python.modules._csv._csv", - "_systemrestart", - "unicodedata" + "_systemrestart" }; } Deleted: branches/asm/src/org/python/modules/unicodedata.java =================================================================== --- branches/asm/src/org/python/modules/unicodedata.java 2008-08-15 20:15:50 UTC (rev 5182) +++ branches/asm/src/org/python/modules/unicodedata.java 2008-08-15 23:03:17 UTC (rev 5183) @@ -1,25 +0,0 @@ -package org.python.modules; -import java.text.Normalizer; -import java.text.Normalizer.Form; - -import org.python.core.Py; -import org.python.core.PyUnicode; - -/** - * Incomplete unicodedata module. - * - * This should be replaced by a unicodedata module compiled in the same way - * as CPython's unicodedata is generated. In the meantime, this implements some - * commonly used functions which allows Jython run some popular software (such - * as Django). - */ -public class unicodedata { - - /** - * Return the normal form 'form' for the Unicode string unistr. Valid - * values for form are 'NFC', 'NFKC', 'NFD', and 'NFKD'. - */ - public static PyUnicode normalize(String form, String unistr) { - return Py.newUnicode(Normalizer.normalize(unistr, Form.valueOf(form))); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-08-15 20:15:52
|
Revision: 5182 http://jython.svn.sourceforge.net/jython/?rev=5182&view=rev Author: leosoto Date: 2008-08-15 20:15:50 +0000 (Fri, 15 Aug 2008) Log Message: ----------- A start for unicodedata. Only implements normalize() Modified Paths: -------------- branches/asm/src/org/python/modules/Setup.java Added Paths: ----------- branches/asm/src/org/python/modules/unicodedata.java Modified: branches/asm/src/org/python/modules/Setup.java =================================================================== --- branches/asm/src/org/python/modules/Setup.java 2008-08-15 19:44:57 UTC (rev 5181) +++ branches/asm/src/org/python/modules/Setup.java 2008-08-15 20:15:50 UTC (rev 5182) @@ -55,6 +55,7 @@ "_hashlib", "_functools:org.python.modules._functools._functools", "_csv:org.python.modules._csv._csv", - "_systemrestart" + "_systemrestart", + "unicodedata" }; } Added: branches/asm/src/org/python/modules/unicodedata.java =================================================================== --- branches/asm/src/org/python/modules/unicodedata.java (rev 0) +++ branches/asm/src/org/python/modules/unicodedata.java 2008-08-15 20:15:50 UTC (rev 5182) @@ -0,0 +1,25 @@ +package org.python.modules; +import java.text.Normalizer; +import java.text.Normalizer.Form; + +import org.python.core.Py; +import org.python.core.PyUnicode; + +/** + * Incomplete unicodedata module. + * + * This should be replaced by a unicodedata module compiled in the same way + * as CPython's unicodedata is generated. In the meantime, this implements some + * commonly used functions which allows Jython run some popular software (such + * as Django). + */ +public class unicodedata { + + /** + * Return the normal form 'form' for the Unicode string unistr. Valid + * values for form are 'NFC', 'NFKC', 'NFD', and 'NFKD'. + */ + public static PyUnicode normalize(String form, String unistr) { + return Py.newUnicode(Normalizer.normalize(unistr, Form.valueOf(form))); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-15 19:45:01
|
Revision: 5181 http://jython.svn.sourceforge.net/jython/?rev=5181&view=rev Author: fwierzbicki Date: 2008-08-15 19:44:57 +0000 (Fri, 15 Aug 2008) Log Message: ----------- Refactor: put repeated code into one method. Modified Paths: -------------- branches/asm/src/org/python/antlr/PythonTokenSource.java Modified: branches/asm/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-15 18:37:14 UTC (rev 5180) +++ branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-15 19:44:57 UTC (rev 5181) @@ -168,11 +168,7 @@ } else if (t.getType() == PythonLexer.NEWLINE) { // save NEWLINE in the queue //System.out.println("found newline: "+t+" stack is "+stackString()); - List hiddenTokens = stream.getTokens(lastTokenAddedIndex + 1,t.getTokenIndex() - 1); - if (hiddenTokens!=null) { - tokens.addAll(hiddenTokens); - } - lastTokenAddedIndex = t.getTokenIndex(); + updateLastTokenAddedIndex(t); tokens.addElement(t); Token newline = t; @@ -180,11 +176,7 @@ t = stream.LT(1); stream.consume(); - hiddenTokens = stream.getTokens(lastTokenAddedIndex + 1,t.getTokenIndex() - 1); - if (hiddenTokens!=null) { - tokens.addAll(hiddenTokens); - } - lastTokenAddedIndex = t.getTokenIndex(); + updateLastTokenAddedIndex(t); // compute cpos as the char pos of next non-WS token in line int cpos = t.getCharPositionInLine(); // column dictates indent/dedent @@ -230,12 +222,16 @@ } private void enqueue(Token t) { + updateLastTokenAddedIndex(t); + tokens.addElement(t); + } + + private void updateLastTokenAddedIndex(Token t) { List hiddenTokens = stream.getTokens(lastTokenAddedIndex + 1,t.getTokenIndex() - 1); if (hiddenTokens != null) { tokens.addAll(hiddenTokens); } lastTokenAddedIndex = t.getTokenIndex(); - tokens.addElement(t); } private void handleIndents(int cpos, CommonToken t) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-15 18:37:17
|
Revision: 5180 http://jython.svn.sourceforge.net/jython/?rev=5180&view=rev Author: fwierzbicki Date: 2008-08-15 18:37:14 +0000 (Fri, 15 Aug 2008) Log Message: ----------- don't allow assignment to yields. Fixes 2 doctests in test_generator as long as we ignore the exact error message. Modified Paths: -------------- branches/asm/Lib/test/test_generators.py branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/Lib/test/test_generators.py =================================================================== --- branches/asm/Lib/test/test_generators.py 2008-08-15 17:55:20 UTC (rev 5179) +++ branches/asm/Lib/test/test_generators.py 2008-08-15 18:37:14 UTC (rev 5180) @@ -1537,12 +1537,12 @@ ... SyntaxError: assignment to yield expression not possible (<doctest test.test_generators.__test__.coroutine[23]>, line 1) ->>> def f(): (yield bar) = y +>>> def f(): (yield bar) = y #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... SyntaxError: can't assign to yield expression (<doctest test.test_generators.__test__.coroutine[24]>, line 1) ->>> def f(): (yield bar) += y +>>> def f(): (yield bar) += y #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... SyntaxError: augmented assignment to yield expression not possible (<doctest test.test_generators.__test__.coroutine[25]>, line 1) Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-15 17:55:20 UTC (rev 5179) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-15 18:37:14 UTC (rev 5180) @@ -491,6 +491,8 @@ errorHandler.error("can't assign to generator expression", e); } else if (e instanceof Num) { errorHandler.error("can't assign to number", e); + } else if (e instanceof Yield) { + errorHandler.error("can't assign to yield expression", e); } else if (e instanceof Tuple) { //XXX: performance problem? Any way to do this better? exprType[] elts = ((Tuple)e).elts; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-15 17:55:25
|
Revision: 5179 http://jython.svn.sourceforge.net/jython/?rev=5179&view=rev Author: fwierzbicki Date: 2008-08-15 17:55:20 +0000 (Fri, 15 Aug 2008) Log Message: ----------- small name change. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/src/org/python/antlr/GrammarActions.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-15 11:43:53 UTC (rev 5178) +++ branches/asm/grammar/Python.g 2008-08-15 17:55:20 UTC (rev 5179) @@ -888,11 +888,11 @@ )? )? { if ($a2 != null) { if ($a1.tree.getType() == GenFor) { - actions.throwGenExpNotSoleArg($a1.tree); + actions.errorGenExpNotSoleArg($a1.tree); } for (int i=0;i<$a2.size();i++) { if (((PythonTree)$a2.get(i)).getType() == GenFor) { - actions.throwGenExpNotSoleArg(((argument_return)$a2.get(i)).tree); + actions.errorGenExpNotSoleArg(((argument_return)$a2.get(i)).tree); } } } @@ -909,7 +909,7 @@ : t1=test[expr_contextType.Load] ( (ASSIGN t2=test[expr_contextType.Load]) -> ^(Keyword ^(Arg $t1) ^(Value $t2)?) | gen_for { if (!first) { - actions.throwGenExpNotSoleArg($gen_for.tree); + actions.errorGenExpNotSoleArg($gen_for.tree); } } -> ^(GenFor $t1 gen_for) Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-15 11:43:53 UTC (rev 5178) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-15 17:55:20 UTC (rev 5179) @@ -96,7 +96,7 @@ this.errorHandler = eh; } - void throwGenExpNotSoleArg(PythonTree t) { + void errorGenExpNotSoleArg(PythonTree t) { errorHandler.error("Generator expression must be parenthesized if not sole argument", t); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-15 11:43:58
|
Revision: 5178 http://jython.svn.sourceforge.net/jython/?rev=5178&view=rev Author: fwierzbicki Date: 2008-08-15 11:43:53 +0000 (Fri, 15 Aug 2008) Log Message: ----------- Use same lexer and token source for parsing and partial parsing. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonPartial.g branches/asm/src/org/python/antlr/InteractiveParser.java branches/asm/src/org/python/core/ParserFacade.java branches/asm/tests/java/org/python/antlr/PythonPartialTester.java Removed Paths: ------------- branches/asm/src/org/python/antlr/PythonPartialTokenSource.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-14 18:48:37 UTC (rev 5177) +++ branches/asm/grammar/Python.g 2008-08-15 11:43:53 UTC (rev 5178) @@ -236,13 +236,17 @@ * 4] */ +//For use in partial parsing. +public boolean eofWhileNested = false; +public boolean partial = false; + +int implicitLineJoiningLevel = 0; +int startPos=-1; + //If you want to use another error recovery mechanisms change this //and the same one in the parser. private ErrorHandler errorHandler; -int implicitLineJoiningLevel = 0; -int startPos=-1; - public void setErrorHandler(ErrorHandler eh) { this.errorHandler = eh; } @@ -261,6 +265,9 @@ state.tokenStartLine = input.getLine(); state.text = null; if ( input.LA(1)==CharStream.EOF ) { + if (implicitLineJoiningLevel > 0) { + eofWhileNested = true; + } return Token.EOF_TOKEN; } try { @@ -1124,6 +1131,13 @@ } ; +STRINGPART + : {partial}?=> ('r'|'u'|'ur'|'R'|'U'|'UR'|'uR'|'Ur')? + ( '\'\'\'' ~('\'\'\'')* + | '"""' ~('"""')* + ) + ; + /** the two '"'? cause a warning -- is there a way to avoid that? */ fragment TRIQUOTE Modified: branches/asm/grammar/PythonPartial.g =================================================================== --- branches/asm/grammar/PythonPartial.g 2008-08-14 18:48:37 UTC (rev 5177) +++ branches/asm/grammar/PythonPartial.g 2008-08-15 11:43:53 UTC (rev 5178) @@ -64,10 +64,8 @@ grammar PythonPartial; -tokens { - INDENT; - DEDENT; - ENDMARKER; +options { + tokenVocab=Python; } @header { @@ -188,12 +186,12 @@ } single_input : NEWLINE - | simple_stmt {debug("matched simple_stmt");} + | simple_stmt | compound_stmt NEWLINE? ; //eval_input: testlist NEWLINE* ENDMARKER -eval_input : LEADING_WS? (NEWLINE)* testlist? (NEWLINE)* ENDMARKER +eval_input : LEADING_WS? (NEWLINE)* testlist? (NEWLINE)* EOF ; decorators: decorator+ @@ -206,7 +204,7 @@ : NAME (DOT NAME)* ; -funcdef : decorators? 'def' NAME parameters COLON suite +funcdef : decorators? DEF NAME parameters COLON suite ; parameters : LPAREN (varargslist)? RPAREN @@ -236,7 +234,7 @@ | compound_stmt ; -simple_stmt : small_stmt (options {greedy=true;}:SEMI small_stmt)* (SEMI)? (NEWLINE|ENDMARKER) +simple_stmt : small_stmt (options {greedy=true;}:SEMI small_stmt)* (SEMI)? (NEWLINE|EOF) ; small_stmt : expr_stmt @@ -284,17 +282,17 @@ | DOUBLESLASHEQUAL ; -print_stmt : 'print' (printlist | RIGHTSHIFT printlist)? +print_stmt : PRINT (printlist | RIGHTSHIFT printlist)? ; printlist returns [boolean newline] : test (options {k=2;}: COMMA test)* (COMMA)? ; -del_stmt : 'del' exprlist +del_stmt : DELETE exprlist ; -pass_stmt : 'pass' +pass_stmt : PASS ; flow_stmt : break_stmt @@ -304,29 +302,29 @@ | yield_stmt ; -break_stmt : 'break' +break_stmt : BREAK ; -continue_stmt : 'continue' +continue_stmt : CONTINUE ; -return_stmt : 'return' (testlist)? +return_stmt : RETURN (testlist)? ; yield_stmt : yield_expr ; -raise_stmt: 'raise' (test (COMMA test (COMMA test)?)?)? +raise_stmt: RAISE (test (COMMA test (COMMA test)?)?)? ; import_stmt : import_name | import_from ; -import_name : 'import' dotted_as_names +import_name : IMPORT dotted_as_names ; -import_from: 'from' (DOT* dotted_name | DOT+) 'import' +import_from: FROM (DOT* dotted_name | DOT+) IMPORT (STAR | import_as_names | LPAREN import_as_names RPAREN @@ -336,10 +334,10 @@ import_as_names : import_as_name (COMMA import_as_name)* (COMMA)? ; -import_as_name : NAME ('as' NAME)? +import_as_name : NAME (AS NAME)? ; -dotted_as_name : dotted_name ('as' NAME)? +dotted_as_name : dotted_name (AS NAME)? ; dotted_as_names : dotted_as_name (COMMA dotted_as_name)* @@ -347,13 +345,13 @@ dotted_name : NAME (DOT NAME)* ; -global_stmt : 'global' NAME (COMMA NAME)* +global_stmt : GLOBAL NAME (COMMA NAME)* ; -exec_stmt : 'exec' expr ('in' test (COMMA test)?)? +exec_stmt : EXEC expr (IN test (COMMA test)?)? ; -assert_stmt : 'assert' test (COMMA test)? +assert_stmt : ASSERT test (COMMA test)? ; compound_stmt : if_stmt @@ -365,39 +363,44 @@ | classdef ; -if_stmt: 'if' test COLON suite elif_clause* ('else' COLON suite)? +if_stmt: IF test COLON suite elif_clause* (ORELSE COLON suite)? ; -elif_clause : 'elif' test COLON suite +elif_clause : ELIF test COLON suite ; -while_stmt : 'while' test COLON suite ('else' COLON suite)? +while_stmt : WHILE test COLON suite (ORELSE COLON suite)? ; -for_stmt : 'for' exprlist 'in' testlist COLON suite ('else' COLON suite)? +for_stmt : FOR exprlist IN testlist COLON suite (ELSE COLON suite)? ; -try_stmt : 'try' COLON suite - ( except_clause+ ('else' COLON suite)? ('finally' COLON suite)? - | 'finally' COLON suite +try_stmt : TRY COLON suite + ( except_clause+ (ELSE COLON suite)? (FINALLY COLON suite)? + | FINALLY COLON suite )? ; -with_stmt: 'with' test (with_var)? COLON suite +with_stmt: WITH test (with_var)? COLON suite ; -with_var: ('as' | NAME) expr +with_var: (AS | NAME) expr ; -except_clause : 'except' (test (COMMA test)?)? COLON suite +except_clause : EXCEPT (test (COMMA test)?)? COLON suite ; suite : simple_stmt - | NEWLINE ((INDENT (stmt)+ (DEDENT|ENDMARKER))|ENDMARKER) + | NEWLINE (EOF + |DEDENT EOF + |INDENT (stmt)+ (DEDENT + |EOF + ) + ) ; test: or_test {debug("matched test: or_test");} - ( ('if' or_test 'else') => 'if' or_test 'else' test)? + ( (IF or_test ELSE) => IF or_test ELSE test)? | lambdef ; @@ -421,10 +424,10 @@ | LESSEQUAL | ALT_NOTEQUAL | NOTEQUAL - | 'in' - | NOT 'in' - | 'is' - | 'is' NOT + | IN + | NOT IN + | IS + | IS NOT ; expr : xor_expr (VBAR xor_expr)* {debug("matched expr");} @@ -484,7 +487,7 @@ ; -lambdef: 'lambda' (varargslist)? COLON test +lambdef: LABMDA (varargslist)? COLON test ; trailer : LPAREN (arglist)? RPAREN @@ -513,7 +516,7 @@ dictmaker : test COLON test (options {k=2;}:COMMA test COLON test)* (COMMA)? ; -classdef: 'class' NAME (LPAREN testlist? RPAREN)? COLON suite +classdef: CLASS NAME (LPAREN testlist? RPAREN)? COLON suite ; arglist : argument (COMMA argument)* @@ -533,270 +536,24 @@ | list_if ; -list_for : 'for' exprlist 'in' testlist (list_iter)? +list_for : FOR exprlist IN testlist (list_iter)? ; -list_if : 'if' test (list_iter)? +list_if : IF test (list_iter)? ; gen_iter: gen_for | gen_if ; -gen_for: 'for' exprlist 'in' or_test gen_iter? +gen_for: FOR exprlist IN or_test gen_iter? ; -gen_if: 'if' test gen_iter? +gen_if: IF test gen_iter? ; -yield_expr : 'yield' testlist? +yield_expr : YIELD testlist? ; +//XXX: +//testlist1: test (',' test)* -LPAREN : '(' {implicitLineJoiningLevel++;} ; - -RPAREN : ')' {implicitLineJoiningLevel--;} ; - -LBRACK : '[' {implicitLineJoiningLevel++;} ; - -RBRACK : ']' {implicitLineJoiningLevel--;} ; - -COLON : ':' ; - -COMMA : ',' ; - -SEMI : ';' ; - -PLUS : '+' ; - -MINUS : '-' ; - -STAR : '*' ; - -SLASH : '/' ; - -VBAR : '|' ; - -AMPER : '&' ; - -LESS : '<' ; - -GREATER : '>' ; - -ASSIGN : '=' ; - -PERCENT : '%' ; - -BACKQUOTE : '`' ; - -LCURLY : '{' {implicitLineJoiningLevel++;} ; - -RCURLY : '}' {implicitLineJoiningLevel--;} ; - -CIRCUMFLEX : '^' ; - -TILDE : '~' ; - -EQUAL : '==' ; - -NOTEQUAL : '!=' ; - -ALT_NOTEQUAL: '<>' ; - -LESSEQUAL : '<=' ; - -LEFTSHIFT : '<<' ; - -GREATEREQUAL : '>=' ; - -RIGHTSHIFT : '>>' ; - -PLUSEQUAL : '+=' ; - -MINUSEQUAL : '-=' ; - -DOUBLESTAR : '**' ; - -STAREQUAL : '*=' ; - -DOUBLESLASH : '//' ; - -SLASHEQUAL : '/=' ; - -VBAREQUAL : '|=' ; - -PERCENTEQUAL : '%=' ; - -AMPEREQUAL : '&=' ; - -CIRCUMFLEXEQUAL : '^=' ; - -LEFTSHIFTEQUAL : '<<=' ; - -RIGHTSHIFTEQUAL : '>>=' ; - -DOUBLESTAREQUAL : '**=' ; - -DOUBLESLASHEQUAL : '//=' ; - -DOT : '.' ; - -AT : '@' ; - -AND : 'and' ; - -OR : 'or' ; - -NOT : 'not' ; - -FLOAT - : '.' DIGITS (Exponent)? - | DIGITS '.' Exponent - | DIGITS ('.' (DIGITS (Exponent)?)? | Exponent) - ; - -LONGINT - : INT ('l'|'L') - ; - -fragment -Exponent - : ('e' | 'E') ( '+' | '-' )? DIGITS - ; - -INT : // Hex - '0' ('x' | 'X') ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' )+ - | // Octal - '0' ( '0' .. '7' )* - | '1'..'9' DIGITS* - ; - -COMPLEX - : DIGITS+ ('j'|'J') - | FLOAT ('j'|'J') - ; - -fragment -DIGITS : ( '0' .. '9' )+ ; - -NAME: ( 'a' .. 'z' | 'A' .. 'Z' | '_') - ( 'a' .. 'z' | 'A' .. 'Z' | '_' | '0' .. '9' )* - ; - -/** Match various string types. Note that greedy=false implies ''' - * should make us exit loop not continue. - */ -STRING - : ('r'|'u'|'ur')? - ( '\'\'\'' (options {greedy=false;}:TRIAPOS)* '\'\'\'' - | '"""' (options {greedy=false;}:TRIQUOTE)* '"""' - | '"' (ESC|~('\\'|'\n'|'"'))* '"' - | '\'' (ESC|~('\\'|'\n'|'\''))* '\'' - ) - ; - -STRINGPART - : ('r'|'u'|'ur')? - ( '\'\'\'' ~('\'\'\'')* - | '"""' ~('"""')* - ) - ; - -/** the two '"'? cause a warning -- is there a way to avoid that? */ -fragment -TRIQUOTE - : '"'? '"'? (ESC|~('\\'|'"'))+ - ; - -/** the two '\''? cause a warning -- is there a way to avoid that? */ -fragment -TRIAPOS - : '\''? '\''? (ESC|~('\\'|'\''))+ - ; - -fragment -ESC - : '\\' . - ; - -/** Consume a newline and any whitespace at start of next line - * unless the next line contains only white space, in that case - * emit a newline. - */ -CONTINUED_LINE - : '\\' ('\r')? '\n' (' '|'\t')* { $channel=HIDDEN; } - ( nl=NEWLINE {emit(new ClassicToken(NEWLINE,nl.getText()));} - | - ) - ; - -/** Treat a sequence of blank lines as a single blank line. If - * nested within a (..), {..}, or [..], then ignore newlines. - * If the first newline starts in column one, they are to be ignored. - * - * Frank Wierzbicki added: Also ignore FORMFEEDS (\u000C). - */ -NEWLINE - : (('\u000C')?('\r')? '\n' )+ - {if ( startPos==0 || implicitLineJoiningLevel>0 ) - $channel=HIDDEN; - } - ; - -WS : {startPos>0}?=> (' '|'\t'|'\u000C')+ {$channel=HIDDEN;} - ; - -/** Grab everything before a real symbol. Then if newline, kill it - * as this is a blank line. If whitespace followed by comment, kill it - * as it's a comment on a line by itself. - * - * Ignore leading whitespace when nested in [..], (..), {..}. - */ -LEADING_WS -@init { - int spaces = 0; -} - : {startPos==0}?=> - ( {implicitLineJoiningLevel>0}? ( ' ' | '\t' )+ {$channel=HIDDEN;} - | ( ' ' { spaces++; } - | '\t' { spaces += 8; spaces -= (spaces \% 8); } - )+ - { - // make a string of n spaces where n is column number - 1 - char[] indentation = new char[spaces]; - for (int i=0; i<spaces; i++) { - indentation[i] = ' '; - } - String s = new String(indentation); - emit(new ClassicToken(LEADING_WS,new String(indentation))); - } - // kill trailing newline if present and then ignore - ( ('\r')? '\n' {if (state.token!=null) state.token.setChannel(HIDDEN); else $channel=HIDDEN;})* - // {state.token.setChannel(99); } - ) - ; - -/** Comments not on line by themselves are turned into newlines. - - b = a # end of line comment - - or - - a = [1, # weird - 2] - - This rule is invoked directly by nextToken when the comment is in - first column or when comment is on end of nonwhitespace line. - - Only match \n here if we didn't start on left edge; let NEWLINE return that. - Kill if newlines if we live on a line by ourselves - - Consume any leading whitespace if it starts on left edge. - */ -COMMENT -@init { - $channel=HIDDEN; -} - : {startPos==0}?=> (' '|'\t')* '#' (~'\n')* '\n'+ - | {startPos>0}?=> '#' (~'\n')* // let NEWLINE handle \n unless char pos==0 for '#' - ; - Modified: branches/asm/src/org/python/antlr/InteractiveParser.java =================================================================== --- branches/asm/src/org/python/antlr/InteractiveParser.java 2008-08-14 18:48:37 UTC (rev 5177) +++ branches/asm/src/org/python/antlr/InteractiveParser.java 2008-08-15 11:43:53 UTC (rev 5178) @@ -21,17 +21,6 @@ private BufferedReader bufreader; - public static class PPLexer extends PythonPartialLexer { - public PPLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - public InteractiveParser(BufferedReader br, String filename) { this.bufreader = br; this.filename = filename; Deleted: branches/asm/src/org/python/antlr/PythonPartialTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonPartialTokenSource.java 2008-08-14 18:48:37 UTC (rev 5177) +++ branches/asm/src/org/python/antlr/PythonPartialTokenSource.java 2008-08-15 11:43:53 UTC (rev 5178) @@ -1,220 +0,0 @@ -package org.python.antlr; - -/* - [The "BSD licence"] - Copyright (c) 2004 Terence Parr and Loring Craymer - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. The name of the author may not be used to endorse or promote products - derived from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -import org.antlr.runtime.*; -import java.util.*; - -/** This file is a copy of PythonTokenSource with some comments removed - * so I can play with it to implement interactive mode partial parsing. - */ - -public class PythonPartialTokenSource implements TokenSource { - public static final int MAX_INDENTS = 100; - public static final int FIRST_CHAR_POSITION = 0; - - /** The stack of indent levels (column numbers) */ - int[] indentStack = new int[MAX_INDENTS]; - /** stack pointer */ - int sp=-1; // grow upwards - - /** The queue of tokens */ - Vector tokens = new Vector(); - - /** We pull real tokens from this lexer */ - CommonTokenStream stream; - - int lastTokenAddedIndex = -1; - - boolean atEnd = false; - - public PythonPartialTokenSource(PythonLexer lexer) { - } - - public PythonPartialTokenSource(CommonTokenStream stream) { - this.stream = stream; - // "state" of indent level is FIRST_CHAR_POSITION - push(FIRST_CHAR_POSITION); - } - - public Token nextToken() { - // if something in queue, just remove and return it - if ( tokens.size()>0 ) { - Token t = (Token)tokens.firstElement(); - tokens.removeElementAt(0); - //System.out.println(t); - return t; - } - - insertImaginaryIndentDedentTokens(); - - return nextToken(); - } - - protected void insertImaginaryIndentDedentTokens() - { - Token t = stream.LT(1); - stream.consume(); - if ( t.getType()==Token.EOF ) { - atEnd = true; - Token em = new CommonToken(PythonPartialParser.ENDMARKER,""); - em.setCharPositionInLine(t.getCharPositionInLine()); - em.setLine(t.getLine()); - tokens.addElement(em); - } - - // if not a NEWLINE, doesn't signal indent/dedent work; just enqueue - if ( t.getType()!=PythonPartialLexer.NEWLINE ) { - List hiddenTokens = stream.getTokens(lastTokenAddedIndex+1,t.getTokenIndex()-1); - if ( hiddenTokens!=null ) { - tokens.addAll(hiddenTokens); - } - lastTokenAddedIndex = t.getTokenIndex(); - tokens.addElement(t); - return; - } - - // save NEWLINE in the queue - //System.out.println("found newline: "+t+" stack is "+stackString()); - List hiddenTokens = stream.getTokens(lastTokenAddedIndex+1,t.getTokenIndex()-1); - if ( hiddenTokens!=null ) { - tokens.addAll(hiddenTokens); - } - lastTokenAddedIndex = t.getTokenIndex(); - tokens.addElement(t); - - // grab first token of next line - t = stream.LT(1); - stream.consume(); - - hiddenTokens = stream.getTokens(lastTokenAddedIndex+1,t.getTokenIndex()-1); - if ( hiddenTokens!=null ) { - tokens.addAll(hiddenTokens); - } - lastTokenAddedIndex = t.getTokenIndex(); - - // compute cpos as the char pos of next non-WS token in line - int cpos = t.getCharPositionInLine(); // column dictates indent/dedent - if ( t.getType()==Token.EOF ) { - atEnd = true; - Token em = new CommonToken(PythonPartialParser.ENDMARKER,""); - em.setCharPositionInLine(t.getCharPositionInLine()); - em.setLine(t.getLine()); - tokens.addElement(em); - - cpos = -1; // pretend EOF always happens at left edge - } - else if ( t.getType()==PythonPartialLexer.LEADING_WS ) { - cpos = t.getText().length(); - } - - //System.out.println("next token is: "+t); - - // compare to last indent level - int lastIndent = peek(); - //System.out.println("cpos, lastIndent = "+cpos+", "+lastIndent); - if ( cpos > lastIndent ) { // they indented; track and gen INDENT - push(cpos); - //System.out.println("push("+cpos+"): "+stackString()); - Token indent = new CommonToken(PythonPartialParser.INDENT,""); - indent.setCharPositionInLine(t.getCharPositionInLine()); - indent.setLine(t.getLine()); - tokens.addElement(indent); - } - else if ( cpos < lastIndent ) { // they dedented - // how far back did we dedent? - int prevIndex = findPreviousIndent(cpos); - //System.out.println("dedented; prevIndex of cpos="+cpos+" is "+prevIndex); - // generate DEDENTs for each indent level we backed up over - for (int d=sp-1; d>=prevIndex; d--) { - Token tok; - if (atEnd) { - tok = new CommonToken(PythonPartialParser.ENDMARKER,""); - } else { - tok = new CommonToken(PythonPartialParser.DEDENT,""); - } - tok.setCharPositionInLine(t.getCharPositionInLine()); - tok.setLine(t.getLine()); - tokens.addElement(tok); - } - sp = prevIndex; // pop those off indent level - } - if ( t.getType()!=PythonPartialLexer.LEADING_WS ) { // discard WS - tokens.addElement(t); - } - } - - // T O K E N S T A C K M E T H O D S - - protected void push(int i) { - if (sp>=MAX_INDENTS) { - throw new IllegalStateException("stack overflow"); - } - sp++; - indentStack[sp] = i; - } - - protected int pop() { - if (sp<0) { - throw new IllegalStateException("stack underflow"); - } - int top = indentStack[sp]; - sp--; - return top; - } - - protected int peek() { - return indentStack[sp]; - } - - /** Return the index on stack of previous indent level == i else -1 */ - protected int findPreviousIndent(int i) { - for (int j=sp-1; j>=0; j--) { - if ( indentStack[j]==i ) { - return j; - } - } - return FIRST_CHAR_POSITION; - } - - public String stackString() { - StringBuffer buf = new StringBuffer(); - for (int j=sp; j>=0; j--) { - buf.append(" "); - buf.append(indentStack[j]); - } - return buf.toString(); - } - - //FIXME: needed this for the Antlr 3.1b interface change. - public String getSourceName() { - return "XXX-need-real-name.py"; - } - -} Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-08-14 18:48:37 UTC (rev 5177) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-08-15 11:43:53 UTC (rev 5178) @@ -16,6 +16,7 @@ import org.antlr.runtime.CharStream; import org.antlr.runtime.CommonTokenStream; +import org.python.antlr.BaseParser; import org.python.antlr.ExpressionParser; import org.python.antlr.InteractiveParser; import org.python.antlr.ParseException; @@ -24,9 +25,9 @@ import org.python.antlr.PythonParser; import org.python.antlr.PythonTree; import org.python.antlr.PythonTree; -import org.python.antlr.PythonPartialLexer; +import org.python.antlr.PythonLexer; import org.python.antlr.PythonPartialParser; -import org.python.antlr.PythonPartialTokenSource; +import org.python.antlr.PythonTokenSource; import org.python.antlr.ast.modType; import org.python.core.io.StreamIO; import org.python.core.io.TextIOInputStream; @@ -158,7 +159,7 @@ } } catch (Throwable t) { PyException p = fixParseError(bufreader, t, filename); - if (validPartialSentence(bufreader, kind)) { + if (validPartialSentence(bufreader, kind, filename)) { return null; } throw p; @@ -166,15 +167,16 @@ return node; } - private static boolean validPartialSentence(BufferedReader bufreader, String kind) { - PythonPartialLexer lexer = null; + private static boolean validPartialSentence(BufferedReader bufreader, String kind, String filename) { + PythonLexer lexer = null; try { bufreader.reset(); CharStream cs = new NoCloseReaderStream(bufreader); - lexer = new InteractiveParser.PPLexer(cs); + lexer = new BaseParser.PyLexer(cs); + lexer.partial = true; CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.discardOffChannelTokens(true); - PythonPartialTokenSource indentedSource = new PythonPartialTokenSource(tokens); + PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); tokens = new CommonTokenStream(indentedSource); PythonPartialParser parser = new PythonPartialParser(tokens); if (kind.equals("single")) { Modified: branches/asm/tests/java/org/python/antlr/PythonPartialTester.java =================================================================== --- branches/asm/tests/java/org/python/antlr/PythonPartialTester.java 2008-08-14 18:48:37 UTC (rev 5177) +++ branches/asm/tests/java/org/python/antlr/PythonPartialTester.java 2008-08-15 11:43:53 UTC (rev 5178) @@ -10,26 +10,15 @@ */ public class PythonPartialTester { - public static class PPLexer extends PythonPartialLexer { - public PPLexer(CharStream lexer) { - super(lexer); - } - - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - public void parse(String[] args) throws Exception { try { PythonTree result = null; CharStream input = new ANTLRFileStream(args[0]); - PythonPartialLexer lexer = new PPLexer(input); + PythonLexer lexer = new BaseParser.PyLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.discardOffChannelTokens(true); //PythonTokenSource indentedSource = new PythonTokenSource(tokens); - PythonPartialTokenSource indentedSource = new PythonPartialTokenSource(tokens); + PythonTokenSource indentedSource = new PythonTokenSource(tokens, "<test>"); tokens = new CommonTokenStream(indentedSource); PythonPartialParser parser = new PythonPartialParser(tokens); parser.single_input(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-14 18:48:41
|
Revision: 5177 http://jython.svn.sourceforge.net/jython/?rev=5177&view=rev Author: fwierzbicki Date: 2008-08-14 18:48:37 +0000 (Thu, 14 Aug 2008) Log Message: ----------- Ignoring exception message details. This actually allows more of this test to run (the doctests don't run if any of the regular tests fail). This reveals more legitimate failures than before. Modified Paths: -------------- branches/asm/Lib/test/test_syntax.py Modified: branches/asm/Lib/test/test_syntax.py =================================================================== --- branches/asm/Lib/test/test_syntax.py 2008-08-14 17:51:34 UTC (rev 5176) +++ branches/asm/Lib/test/test_syntax.py 2008-08-14 18:48:37 UTC (rev 5177) @@ -1,3 +1,6 @@ +#XXX: The details of the exception messages have been excluded. +# This should be revisited, since matching some of these +# exception messages is sensible. """This module tests SyntaxErrors. Here's an example of the sort of thing that is tested. @@ -29,11 +32,12 @@ TODO(jhylton): "assignment to None" is inconsistent with other messages ->>> obj.None = 1 -Traceback (most recent call last): -SyntaxError: assignment to None (<doctest test.test_syntax[1]>, line 1) +#XXX: None as a dotted name is specifically allowed in Jython for Java compatibility. +#>>> obj.None = 1 +#Traceback (most recent call last): +#SyntaxError: assignment to None (<doctest test.test_syntax[1]>, line 1) ->>> None = 1 +>>> None = 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: assignment to None (<doctest test.test_syntax[2]>, line 1) @@ -41,19 +45,19 @@ error to assign to the empty list? It will always raise some error at runtime. ->>> () = 1 +>>> () = 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to () (<doctest test.test_syntax[3]>, line 1) ->>> f() = 1 +>>> f() = 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to function call (<doctest test.test_syntax[4]>, line 1) ->>> del f() +>>> del f() #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't delete function call (<doctest test.test_syntax[5]>, line 1) ->>> a + 1 = 2 +>>> a + 1 = 2 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to operator (<doctest test.test_syntax[6]>, line 1) @@ -61,15 +65,15 @@ Traceback (most recent call last): SyntaxError: can't assign to generator expression (<doctest test.test_syntax[7]>, line 1) ->>> 1 = 1 +>>> 1 = 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to literal (<doctest test.test_syntax[8]>, line 1) ->>> "abc" = 1 +>>> "abc" = 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to literal (<doctest test.test_syntax[9]>, line 1) ->>> `1` = 1 +>>> `1` = 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to repr (<doctest test.test_syntax[10]>, line 1) @@ -78,21 +82,21 @@ This test just checks a couple of cases rather than enumerating all of them. ->>> (a, "b", c) = (1, 2, 3) +>>> (a, "b", c) = (1, 2, 3) #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to literal (<doctest test.test_syntax[11]>, line 1) ->>> [a, b, c + 1] = [1, 2, 3] +>>> [a, b, c + 1] = [1, 2, 3] #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to operator (<doctest test.test_syntax[12]>, line 1) ->>> a if 1 else b = 1 +>>> a if 1 else b = 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: can't assign to conditional expression (<doctest test.test_syntax[13]>, line 1) From compiler_complex_args(): ->>> def f(None=1): +>>> def f(None=1): #doctest: +IGNORE_EXCEPTION_DETAIL ... pass Traceback (most recent call last): SyntaxError: assignment to None (<doctest test.test_syntax[14]>, line 1) @@ -100,30 +104,30 @@ From ast_for_arguments(): ->>> def f(x, y=1, z): +>>> def f(x, y=1, z): #doctest: +IGNORE_EXCEPTION_DETAIL ... pass Traceback (most recent call last): SyntaxError: non-default argument follows default argument (<doctest test.test_syntax[15]>, line 1) ->>> def f(x, None): +>>> def f(x, None): #doctest: +IGNORE_EXCEPTION_DETAIL ... pass Traceback (most recent call last): SyntaxError: assignment to None (<doctest test.test_syntax[16]>, line 1) ->>> def f(*None): +>>> def f(*None): #doctest: +IGNORE_EXCEPTION_DETAIL ... pass Traceback (most recent call last): SyntaxError: assignment to None (<doctest test.test_syntax[17]>, line 1) ->>> def f(**None): +>>> def f(**None): #doctest: +IGNORE_EXCEPTION_DETAIL ... pass Traceback (most recent call last): SyntaxError: assignment to None (<doctest test.test_syntax[18]>, line 1) -From ast_for_funcdef(): +From ast_for_funcdef(): #doctest: +IGNORE_EXCEPTION_DETAIL ->>> def None(x): +>>> def None(x): #doctest: +IGNORE_EXCEPTION_DETAIL ... pass Traceback (most recent call last): SyntaxError: assignment to None (<doctest test.test_syntax[19]>, line 1) @@ -136,7 +140,7 @@ >>> L = range(10) >>> f(x for x in L) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ->>> f(x for x in L, 1) +>>> f(x for x in L, 1) #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: Generator expression must be parenthesized if not sole argument (<doctest test.test_syntax[23]>, line 1) >>> f((x for x in L), 1) @@ -169,7 +173,7 @@ ... i235, i236, i237, i238, i239, i240, i241, i242, i243, ... i244, i245, i246, i247, i248, i249, i250, i251, i252, ... i253, i254, i255) -Traceback (most recent call last): +Traceback (most recent call last): #doctest: +IGNORE_EXCEPTION_DETAIL SyntaxError: more than 255 arguments (<doctest test.test_syntax[25]>, line 1) The actual error cases counts positional arguments, keyword arguments, @@ -203,36 +207,36 @@ ... i235, i236, i237, i238, i239, i240, i241, i242, i243, ... (x for x in i244), i245, i246, i247, i248, i249, i250, i251, ... i252=1, i253=1, i254=1, i255=1) -Traceback (most recent call last): +Traceback (most recent call last): #doctest: +IGNORE_EXCEPTION_DETAIL SyntaxError: more than 255 arguments (<doctest test.test_syntax[26]>, line 1) ->>> f(lambda x: x[0] = 3) +>>> f(lambda x: x[0] = 3) #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: lambda cannot contain assignment (<doctest test.test_syntax[27]>, line 1) The grammar accepts any test (basically, any expression) in the keyword slot of a call site. Test a few different options. ->>> f(x()=2) +>>> f(x()=2) #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: keyword can't be an expression (<doctest test.test_syntax[28]>, line 1) ->>> f(a or b=1) +>>> f(a or b=1) #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: keyword can't be an expression (<doctest test.test_syntax[29]>, line 1) ->>> f(x.y=1) +>>> f(x.y=1) #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: keyword can't be an expression (<doctest test.test_syntax[30]>, line 1) From ast_for_expr_stmt(): ->>> (x for x in x) += 1 +>>> (x for x in x) += 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: augmented assignment to generator expression not possible (<doctest test.test_syntax[31]>, line 1) ->>> None += 1 +>>> None += 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: assignment to None (<doctest test.test_syntax[32]>, line 1) ->>> f() += 1 +>>> f() += 1 #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): SyntaxError: illegal expression for augmented assignment (<doctest test.test_syntax[33]>, line 1) @@ -253,7 +257,7 @@ Start simple, a continue in a finally should not be allowed. - >>> def test(): + >>> def test(): #doctest: +IGNORE_EXCEPTION_DETAIL ... for abc in range(10): ... try: ... pass @@ -266,7 +270,7 @@ This is essentially a continue in a finally which should not be allowed. - >>> def test(): + >>> def test(): #doctest: +IGNORE_EXCEPTION_DETAIL ... for abc in range(10): ... try: ... pass @@ -279,7 +283,7 @@ ... SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[37]>, line 7) - >>> def foo(): + >>> def foo(): #doctest: +IGNORE_EXCEPTION_DETAIL ... try: ... pass ... finally: @@ -288,7 +292,7 @@ ... SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[38]>, line 5) - >>> def foo(): + >>> def foo(): #doctest: +IGNORE_EXCEPTION_DETAIL ... for a in (): ... try: pass ... finally: continue @@ -296,7 +300,7 @@ ... SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[39]>, line 4) - >>> def foo(): + >>> def foo(): #doctest: +IGNORE_EXCEPTION_DETAIL ... for a in (): ... try: pass ... finally: @@ -307,7 +311,7 @@ ... SyntaxError: 'continue' not supported inside 'finally' clause (<doctest test.test_syntax[40]>, line 6) - >>> def foo(): + >>> def foo(): #doctest: +IGNORE_EXCEPTION_DETAIL ... for a in (): ... try: pass ... finally: @@ -324,7 +328,7 @@ so we need to be sure that a break is actually inside a loop. If it isn't, there should be a syntax error. - >>> try: + >>> try: #doctest: +IGNORE_EXCEPTION_DETAIL ... print 1 ... break ... print 2 @@ -338,37 +342,38 @@ In 2.5 there was a missing exception and an assert was triggered in a debug build. The number of blocks must be greater than CO_MAXBLOCKS. SF #1565514 - >>> while 1: - ... while 2: - ... while 3: - ... while 4: - ... while 5: - ... while 6: - ... while 8: - ... while 9: - ... while 10: - ... while 11: - ... while 12: - ... while 13: - ... while 14: - ... while 15: - ... while 16: - ... while 17: - ... while 18: - ... while 19: - ... while 20: - ... while 21: - ... while 22: - ... break - Traceback (most recent call last): - ... - SystemError: too many statically nested blocks +### XXX: commented out -- jython lacks this limit -- should it have it? +# >>> while 1: +# ... while 2: +# ... while 3: +# ... while 4: +# ... while 5: +# ... while 6: +# ... while 8: +# ... while 9: +# ... while 10: +# ... while 11: +# ... while 12: +# ... while 13: +# ... while 14: +# ... while 15: +# ... while 16: +# ... while 17: +# ... while 18: +# ... while 19: +# ... while 20: +# ... while 21: +# ... while 22: +# ... break +# Traceback (most recent call last): +# ... +# SystemError: too many statically nested blocks This tests assignment-context; there was a bug in Python 2.5 where compiling a complex 'if' (one with 'elif') would fail to notice an invalid suite, leading to spurious errors. - >>> if 1: + >>> if 1: #doctest: +IGNORE_EXCEPTION_DETAIL ... x() = 1 ... elif 1: ... pass @@ -376,7 +381,7 @@ ... SyntaxError: can't assign to function call (<doctest test.test_syntax[44]>, line 2) - >>> if 1: + >>> if 1: #doctest: +IGNORE_EXCEPTION_DETAIL ... pass ... elif 1: ... x() = 1 @@ -384,7 +389,7 @@ ... SyntaxError: can't assign to function call (<doctest test.test_syntax[45]>, line 4) - >>> if 1: + >>> if 1: #doctest: +IGNORE_EXCEPTION_DETAIL ... x() = 1 ... elif 1: ... pass @@ -394,7 +399,7 @@ ... SyntaxError: can't assign to function call (<doctest test.test_syntax[46]>, line 2) - >>> if 1: + >>> if 1: #doctest: +IGNORE_EXCEPTION_DETAIL ... pass ... elif 1: ... x() = 1 @@ -404,7 +409,7 @@ ... SyntaxError: can't assign to function call (<doctest test.test_syntax[47]>, line 4) - >>> if 1: + >>> if 1: #doctest: +IGNORE_EXCEPTION_DETAIL ... pass ... elif 1: ... pass @@ -483,12 +488,18 @@ self._check_error(source, "nested scope") def test_unexpected_indent(self): - self._check_error("foo()\n bar()\n", "unexpected indent", - subclass=IndentationError) + if test_support.is_jython: + self._check_error("foo()\n bar()\n") + else: + self._check_error("foo()\n bar()\n", "unexpected indent", + subclass=IndentationError) def test_no_indent(self): - self._check_error("if 1:\nfoo()", "expected an indented block", - subclass=IndentationError) + if test_support.is_jython: + self._check_error("if 1:\nfoo()") + else: + self._check_error("if 1:\nfoo()", "expected an indented block", + subclass=IndentationError) def test_bad_outdent(self): self._check_error("if 1:\n foo()\n bar()", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-14 17:51:37
|
Revision: 5176 http://jython.svn.sourceforge.net/jython/?rev=5176&view=rev Author: fwierzbicki Date: 2008-08-14 17:51:34 +0000 (Thu, 14 Aug 2008) Log Message: ----------- Updated comment. Modified Paths: -------------- branches/asm/grammar/Python.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-14 02:00:01 UTC (rev 5175) +++ branches/asm/grammar/Python.g 2008-08-14 17:51:34 UTC (rev 5176) @@ -56,16 +56,13 @@ * REQUIRES ANTLR v3 * * - * Baby step towards an antlr based Jython parser. - * Terence's Lexer is intact pretty much unchanged, the parser has - * been altered to produce an AST - the AST work started from tne newcompiler - * grammar from Jim Baker minus post-2.3 features. The current parsing - * and compiling strategy looks like this: + * Updated the original parser for Python 2.5 features. The parser has been + * altered to produce an AST - the AST work started from tne newcompiler + * grammar from Jim Baker. The current parsing and compiling strategy looks + * like this: * * Python source->Python.g->simple antlr AST->PythonWalker.g-> * decorated AST (org/python/parser/ast/*)->CodeCompiler(ASM)->.class - * - * for a very limited set of functionality. */ grammar Python; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-14 02:00:03
|
Revision: 5175 http://jython.svn.sourceforge.net/jython/?rev=5175&view=rev Author: fwierzbicki Date: 2008-08-14 02:00:01 +0000 (Thu, 14 Aug 2008) Log Message: ----------- Add EOF to single_input. Modified Paths: -------------- branches/asm/grammar/Python.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-14 00:35:01 UTC (rev 5174) +++ branches/asm/grammar/Python.g 2008-08-14 02:00:01 UTC (rev 5175) @@ -287,9 +287,9 @@ } //single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE -single_input : NEWLINE? -> ^(Interactive) - | simple_stmt -> ^(Interactive simple_stmt) - | compound_stmt NEWLINE -> ^(Interactive compound_stmt) +single_input : NEWLINE* EOF -> ^(Interactive) + | simple_stmt NEWLINE* EOF -> ^(Interactive simple_stmt) + | compound_stmt NEWLINE+ EOF -> ^(Interactive compound_stmt) ; //file_input: (NEWLINE | stmt)* ENDMARKER This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-14 00:35:04
|
Revision: 5174 http://jython.svn.sourceforge.net/jython/?rev=5174&view=rev Author: fwierzbicki Date: 2008-08-14 00:35:01 +0000 (Thu, 14 Aug 2008) Log Message: ----------- antlr 3.1 final. Modified Paths: -------------- branches/asm/build.xml Added Paths: ----------- branches/asm/extlibs/antlr-3.1.jar branches/asm/extlibs/antlr-runtime-3.1.jar Removed Paths: ------------- branches/asm/extlibs/antlr-3.1b2.jar branches/asm/extlibs/antlr-runtime-3.1b2.jar Modified: branches/asm/build.xml =================================================================== --- branches/asm/build.xml 2008-08-14 00:07:31 UTC (rev 5173) +++ branches/asm/build.xml 2008-08-14 00:35:01 UTC (rev 5174) @@ -156,7 +156,7 @@ <pathelement path="${extlibs.dir}/mysql-connector-java-5.1.6.jar" /> <pathelement path="${extlibs.dir}/postgresql-8.3-603.jdbc4.jar" /> <pathelement path="${extlibs.dir}/antlr-2.7.7.jar" /> - <pathelement path="${extlibs.dir}/antlr-3.1b2.jar" /> + <pathelement path="${extlibs.dir}/antlr-3.1.jar" /> <pathelement path="${extlibs.dir}/stringtemplate-3.2.jar" /> </path> @@ -516,7 +516,7 @@ <target name="jarjar" depends="init,needed-check"> <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="extlibs/jarjar-0.7.jar"/> <jarjar destfile="${output.dir}/jarjar.jar"> - <zipfileset src="extlibs/antlr-runtime-3.1b2.jar"/> + <zipfileset src="extlibs/antlr-runtime-3.1.jar"/> <zipfileset src="extlibs/asm-3.1.jar"/> <zipfileset src="extlibs/asm-commons-3.1.jar"/> <zipfileset src="extlibs/asm-util-3.1.jar"/> Property changes on: branches/asm/extlibs/antlr-3.1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Property changes on: branches/asm/extlibs/antlr-runtime-3.1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-14 00:07:35
|
Revision: 5173 http://jython.svn.sourceforge.net/jython/?rev=5173&view=rev Author: fwierzbicki Date: 2008-08-14 00:07:31 +0000 (Thu, 14 Aug 2008) Log Message: ----------- Add EOF check for file_input. Modified Paths: -------------- branches/asm/grammar/Python.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-13 23:35:12 UTC (rev 5172) +++ branches/asm/grammar/Python.g 2008-08-14 00:07:31 UTC (rev 5173) @@ -293,7 +293,7 @@ ; //file_input: (NEWLINE | stmt)* ENDMARKER -file_input : (NEWLINE | stmt)* {debug("parsed file_input");} +file_input : (NEWLINE | stmt)* EOF -> ^(Module stmt*) ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-13 23:35:14
|
Revision: 5172 http://jython.svn.sourceforge.net/jython/?rev=5172&view=rev Author: pjenvey Date: 2008-08-13 23:35:12 +0000 (Wed, 13 Aug 2008) Log Message: ----------- fix alignment of little and big endian long longs. caused extra padding which broke test_zipfile zip64 tests Modified Paths: -------------- branches/asm/src/org/python/modules/struct.java Modified: branches/asm/src/org/python/modules/struct.java =================================================================== --- branches/asm/src/org/python/modules/struct.java 2008-08-13 19:48:08 UTC (rev 5171) +++ branches/asm/src/org/python/modules/struct.java 2008-08-13 23:35:12 UTC (rev 5172) @@ -828,8 +828,8 @@ new LEUnsignedIntFormatDef() .init('I', 4, 0), new LEIntFormatDef() .init('l', 4, 0), new LEUnsignedIntFormatDef() .init('L', 4, 0), - new LELongFormatDef() .init('q', 8, 8), - new LEUnsignedLongFormatDef() .init('Q', 8, 8), + new LELongFormatDef() .init('q', 8, 0), + new LEUnsignedLongFormatDef() .init('Q', 8, 0), new LEFloatFormatDef() .init('f', 4, 0), new LEDoubleFormatDef() .init('d', 8, 0), }; @@ -847,8 +847,8 @@ new BEUnsignedIntFormatDef() .init('I', 4, 0), new BEIntFormatDef() .init('l', 4, 0), new BEUnsignedIntFormatDef() .init('L', 4, 0), - new BELongFormatDef() .init('q', 8, 8), - new BEUnsignedLongFormatDef() .init('Q', 8, 8), + new BELongFormatDef() .init('q', 8, 0), + new BEUnsignedLongFormatDef() .init('Q', 8, 0), new BEFloatFormatDef() .init('f', 4, 0), new BEDoubleFormatDef() .init('d', 8, 0), }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |