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