From: <fwi...@us...> - 2008-09-24 21:05:45
|
Revision: 5345 http://jython.svn.sourceforge.net/jython/?rev=5345&view=rev Author: fwierzbicki Date: 2008-09-24 21:05:39 +0000 (Wed, 24 Sep 2008) Log Message: ----------- Switched PythonPartial.g from being a "grammar" to being a "parser grammar", plus some additional related cleanup. This fixes all of the missing Token warnings. Thanks to Terrance Parr for suggesting this fix. Modified Paths: -------------- trunk/jython/grammar/PythonPartial.g trunk/jython/src/org/python/core/ParserFacade.java trunk/jython/tests/java/org/python/antlr/PythonPartialTester.java Modified: trunk/jython/grammar/PythonPartial.g =================================================================== --- trunk/jython/grammar/PythonPartial.g 2008-09-24 19:56:28 UTC (rev 5344) +++ trunk/jython/grammar/PythonPartial.g 2008-09-24 21:05:39 UTC (rev 5345) @@ -62,7 +62,7 @@ * an indent but no dedent. */ -grammar PythonPartial; +parser grammar PythonPartial; options { tokenVocab=Python; @@ -124,67 +124,6 @@ } } - -@lexer::header { -package org.python.antlr; -} - -@lexer::members { -/** Handles context-sensitive lexing of implicit line joining such as - * the case where newline is ignored in cases like this: - * a = [3, - * 4] - */ -int implicitLineJoiningLevel = 0; -int startPos=-1; -public boolean eofWhileNested = false; - public Token nextToken() { - while (true) { - state.token = null; - state.channel = Token.DEFAULT_CHANNEL; - state.tokenStartCharIndex = input.index(); - state.tokenStartCharPositionInLine = input.getCharPositionInLine(); - state.tokenStartLine = input.getLine(); - state.text = null; - if ( input.LA(1)==CharStream.EOF ) { - if (implicitLineJoiningLevel > 0) { - eofWhileNested = true; - } - return Token.EOF_TOKEN; - } - try { - mTokens(); - if ( state.token==null ) { - emit(); - } - else if ( state.token==Token.SKIP_TOKEN ) { - continue; - } - return state.token; - } - catch (RecognitionException re) { - throw new ParseException("failed partial", re); - } - } - } - - public void reportError(RecognitionException e) { - System.err.print("[LEXER REPORTING] "); - // if we've already reported an error and have not matched a token - // yet successfully, don't report any errors. - if ( state.errorRecovery ) { - System.err.print("[SPURIOUS] "); - return; - } - state.syntaxErrors++; // don't count spurious - state.errorRecovery = true; - - displayRecognitionError(this.getTokenNames(), e); - } - - -} - single_input : NEWLINE | simple_stmt | compound_stmt NEWLINE? Modified: trunk/jython/src/org/python/core/ParserFacade.java =================================================================== --- trunk/jython/src/org/python/core/ParserFacade.java 2008-09-24 19:56:28 UTC (rev 5344) +++ trunk/jython/src/org/python/core/ParserFacade.java 2008-09-24 21:05:39 UTC (rev 5345) @@ -26,7 +26,7 @@ import org.python.antlr.PythonTree; import org.python.antlr.PythonTree; import org.python.antlr.PythonLexer; -import org.python.antlr.PythonPartialParser; +import org.python.antlr.PythonPartial; import org.python.antlr.PythonTokenSource; import org.python.antlr.ast.modType; import org.python.core.io.StreamIO; @@ -172,7 +172,7 @@ CommonTokenStream tokens = new CommonTokenStream(lexer); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); tokens = new CommonTokenStream(indentedSource); - PythonPartialParser parser = new PythonPartialParser(tokens); + PythonPartial parser = new PythonPartial(tokens); if (kind.equals("single")) { parser.single_input(); } else if (kind.equals("eval")) { Modified: trunk/jython/tests/java/org/python/antlr/PythonPartialTester.java =================================================================== --- trunk/jython/tests/java/org/python/antlr/PythonPartialTester.java 2008-09-24 19:56:28 UTC (rev 5344) +++ trunk/jython/tests/java/org/python/antlr/PythonPartialTester.java 2008-09-24 21:05:39 UTC (rev 5345) @@ -19,7 +19,7 @@ //PythonTokenSource indentedSource = new PythonTokenSource(tokens); PythonTokenSource indentedSource = new PythonTokenSource(tokens, "<test>"); tokens = new CommonTokenStream(indentedSource); - PythonPartialParser parser = new PythonPartialParser(tokens); + PythonPartial parser = new PythonPartial(tokens); parser.single_input(); System.out.println("SUCCEED"); } catch (ParseException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |