From: <fwi...@us...> - 2008-08-08 23:54:10
|
Revision: 5112 http://jython.svn.sourceforge.net/jython/?rev=5112&view=rev Author: fwierzbicki Date: 2008-08-08 23:54:06 +0000 (Fri, 08 Aug 2008) Log Message: ----------- New error nodes for tool ASTs. Added errorhandling methods to ErrorHandler. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g branches/asm/src/org/python/antlr/ErrorHandler.java branches/asm/src/org/python/antlr/FailFastHandler.java branches/asm/src/org/python/antlr/GrammarActions.java branches/asm/src/org/python/antlr/ListErrorHandler.java Added Paths: ----------- branches/asm/src/org/python/antlr/ast/ErrorExpr.java branches/asm/src/org/python/antlr/ast/ErrorMod.java branches/asm/src/org/python/antlr/ast/ErrorSlice.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-08 22:07:24 UTC (rev 5111) +++ branches/asm/grammar/Python.g 2008-08-08 23:54:06 UTC (rev 5112) @@ -192,6 +192,7 @@ public void setErrorHandler(ErrorHandler eh) { this.errorHandler = eh; + actions.setErrorHandler(eh); } private void debug(String message) { Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-08 22:07:24 UTC (rev 5111) +++ branches/asm/grammar/PythonWalker.g 2008-08-08 23:54:06 UTC (rev 5112) @@ -95,6 +95,7 @@ public void setErrorHandler(ErrorHandler eh) { this.errorHandler = eh; + actions.setErrorHandler(eh); } public void debug(String message) { @@ -225,7 +226,7 @@ if ($Call == null) { decs.add($dotted_attr.etype); } else { - Call c; + exprType c; if ($Args == null) { c = actions.makeCall($Call, $dotted_attr.etype); } else { @@ -344,7 +345,7 @@ call_expr returns [exprType etype, PythonTree marker] : ^(Call (^(Args arglist))? test[expr_contextType.Load]) { - Call c; + exprType c; if ($Args == null) { c = actions.makeCall($test.marker, $test.etype); } else { @@ -676,7 +677,7 @@ if ($ORELSE != null) { o = $orelse.stypes; } - While w = actions.makeWhile($WHILE, $test.etype, $body.stypes, o); + stmtType w = actions.makeWhile($WHILE, $test.etype, $body.stypes, o); $stmts::statements.add(w); } ; @@ -687,7 +688,7 @@ if ($ORELSE != null) { o = $orelse.stypes; } - For f = actions.makeFor($FOR, $targ.etype, $iter.etype, $body.stypes, o); + stmtType f = actions.makeFor($FOR, $targ.etype, $iter.etype, $body.stypes, o); $stmts::statements.add(f); } ; Modified: branches/asm/src/org/python/antlr/ErrorHandler.java =================================================================== --- branches/asm/src/org/python/antlr/ErrorHandler.java 2008-08-08 22:07:24 UTC (rev 5111) +++ branches/asm/src/org/python/antlr/ErrorHandler.java 2008-08-08 23:54:06 UTC (rev 5112) @@ -4,10 +4,20 @@ import org.antlr.runtime.IntStream; import org.antlr.runtime.Lexer; import org.antlr.runtime.RecognitionException; +import org.python.antlr.ast.exprType; +import org.python.antlr.ast.modType; +import org.python.antlr.ast.sliceType; +import org.python.antlr.ast.stmtType; interface ErrorHandler { void reportError(BaseRecognizer br, RecognitionException re); void recover(BaseRecognizer br, IntStream input, RecognitionException re); void recover(Lexer lex, RecognitionException re); boolean isRecoverable(); + //exprType, modType, sliceType, stmtType + exprType errorExpr(PythonTree t); + modType errorMod(PythonTree t); + sliceType errorSlice(PythonTree t); + stmtType errorStmt(PythonTree t); + } Modified: branches/asm/src/org/python/antlr/FailFastHandler.java =================================================================== --- branches/asm/src/org/python/antlr/FailFastHandler.java 2008-08-08 22:07:24 UTC (rev 5111) +++ branches/asm/src/org/python/antlr/FailFastHandler.java 2008-08-08 23:54:06 UTC (rev 5112) @@ -4,6 +4,14 @@ import org.antlr.runtime.IntStream; import org.antlr.runtime.Lexer; import org.antlr.runtime.RecognitionException; +import org.python.antlr.ast.ErrorMod; +import org.python.antlr.ast.exprType; +import org.python.antlr.ast.ErrorExpr; +import org.python.antlr.ast.ErrorSlice; +import org.python.antlr.ast.ErrorStmt; +import org.python.antlr.ast.modType; +import org.python.antlr.ast.sliceType; +import org.python.antlr.ast.stmtType; public class FailFastHandler implements ErrorHandler { @@ -23,9 +31,26 @@ return false; } + public exprType errorExpr(PythonTree t) { + throw new ParseException("Bad Expr Node", t); + } + + public modType errorMod(PythonTree t) { + throw new ParseException("Bad Mod Node", t); + } + + public sliceType errorSlice(PythonTree t) { + throw new ParseException("Bad Slice Node", t); + } + + public stmtType errorStmt(PythonTree t) { + throw new ParseException("Bad Stmt Node", t); + } + private String message(BaseRecognizer br, RecognitionException re) { String hdr = br.getErrorHeader(re); String msg = br.getErrorMessage(re, br.getTokenNames()); return hdr+" "+msg; } + } Modified: branches/asm/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-08 22:07:24 UTC (rev 5111) +++ branches/asm/src/org/python/antlr/GrammarActions.java 2008-08-08 23:54:06 UTC (rev 5112) @@ -84,9 +84,14 @@ import java.util.Set; public class GrammarActions { + private ErrorHandler errorHandler = null; + public GrammarActions() { } + public void setErrorHandler(ErrorHandler eh) { + this.errorHandler = eh; + } void debug(String x) { if (false) { System.out.println(x); @@ -135,11 +140,9 @@ } stmtType makeFunctionDef(PythonTree t, PythonTree nameToken, argumentsType args, List funcStatements, List decorators) { - /* - if (nameToken == null || funcStatements == null || decorators == null) { - return new ErrorStmt(t); + if (nameToken == null) { + return errorHandler.errorStmt(t); } - */ argumentsType a; debug("Matched FunctionDef"); if (args != null) { @@ -322,11 +325,9 @@ } stmtType makeClassDef(PythonTree t, PythonTree nameToken, List bases, List body) { - /* - if (nameToken == null || bases == null || body == null) { - return new ErrorStmt(t); + if (nameToken == null) { + return errorHandler.errorStmt(t); } - */ exprType[] b = (exprType[])bases.toArray(new exprType[bases.size()]); stmtType[] s = (stmtType[])body.toArray(new stmtType[body.size()]); return new ClassDef(t, nameToken.getText(), b, s); @@ -378,7 +379,10 @@ return new TryFinally(t, b, f); } - If makeIf(PythonTree t, exprType test, List body, List orelse) { + stmtType makeIf(PythonTree t, exprType test, List body, List orelse) { + if (test == null) { + return errorHandler.errorStmt(t); + } stmtType[] o; if (orelse != null) { o = (stmtType[])orelse.toArray(new stmtType[orelse.size()]); @@ -395,7 +399,10 @@ } - While makeWhile(PythonTree t, exprType test, List body, List orelse) { + stmtType makeWhile(PythonTree t, exprType test, List body, List orelse) { + if (test == null) { + return errorHandler.errorStmt(t); + } stmtType[] o; if (orelse != null) { o = (stmtType[])orelse.toArray(new stmtType[orelse.size()]); @@ -406,7 +413,10 @@ return new While(t, test, b, o); } - For makeFor(PythonTree t, exprType target, exprType iter, List body, List orelse) { + stmtType makeFor(PythonTree t, exprType target, exprType iter, List body, List orelse) { + if (target == null || iter == null) { + return errorHandler.errorStmt(t); + } stmtType[] o; if (orelse != null) { o = (stmtType[])orelse.toArray(new stmtType[orelse.size()]); @@ -417,11 +427,14 @@ return new For(t, target, iter, b, o); } - Call makeCall(PythonTree t, exprType func) { + exprType makeCall(PythonTree t, exprType func) { return makeCall(t, func, null, null, null, null); } - Call makeCall(PythonTree t, exprType func, List args, List keywords, exprType starargs, exprType kwargs) { + exprType makeCall(PythonTree t, exprType func, List args, List keywords, exprType starargs, exprType kwargs) { + if (func == null) { + return errorHandler.errorExpr(t); + } exprType[] a; keywordType[] k; if (args == null) { Modified: branches/asm/src/org/python/antlr/ListErrorHandler.java =================================================================== --- branches/asm/src/org/python/antlr/ListErrorHandler.java 2008-08-08 22:07:24 UTC (rev 5111) +++ branches/asm/src/org/python/antlr/ListErrorHandler.java 2008-08-08 23:54:06 UTC (rev 5112) @@ -4,6 +4,14 @@ import org.antlr.runtime.IntStream; import org.antlr.runtime.Lexer; import org.antlr.runtime.RecognitionException; +import org.python.antlr.ast.ErrorMod; +import org.python.antlr.ast.exprType; +import org.python.antlr.ast.ErrorExpr; +import org.python.antlr.ast.ErrorSlice; +import org.python.antlr.ast.ErrorStmt; +import org.python.antlr.ast.modType; +import org.python.antlr.ast.sliceType; +import org.python.antlr.ast.stmtType; public class ListErrorHandler implements ErrorHandler { @@ -23,4 +31,20 @@ return true; } + public exprType errorExpr(PythonTree t) { + return new ErrorExpr(t); + } + + public modType errorMod(PythonTree t) { + return new ErrorMod(t); + } + + public sliceType errorSlice(PythonTree t) { + return new ErrorSlice(t); + } + + public stmtType errorStmt(PythonTree t) { + return new ErrorStmt(t); + } + } Added: branches/asm/src/org/python/antlr/ast/ErrorExpr.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ErrorExpr.java (rev 0) +++ branches/asm/src/org/python/antlr/ast/ErrorExpr.java 2008-08-08 23:54:06 UTC (rev 5112) @@ -0,0 +1,28 @@ +package org.python.antlr.ast; +import org.python.antlr.PythonTree; + +public class ErrorExpr extends exprType { + + public static final String[] _fields = new String[] {}; + + public ErrorExpr(PythonTree tree) { + super(tree); + } + + public String toString() { + return "ErrorExpr"; + } + + public String toStringTree() { + return "ErrorExpr"; + } + + public int getLineno() { + return getLine(); + } + + public int getCol_offset() { + return getCharPositionInLine(); + } + +} Added: branches/asm/src/org/python/antlr/ast/ErrorMod.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ErrorMod.java (rev 0) +++ branches/asm/src/org/python/antlr/ast/ErrorMod.java 2008-08-08 23:54:06 UTC (rev 5112) @@ -0,0 +1,28 @@ +package org.python.antlr.ast; +import org.python.antlr.PythonTree; + +public class ErrorMod extends modType { + + public static final String[] _fields = new String[] {}; + + public ErrorMod(PythonTree tree) { + super(tree); + } + + public String toString() { + return "ErrorMod"; + } + + public String toStringTree() { + return "ErrorMod"; + } + + public int getLineno() { + return getLine(); + } + + public int getCol_offset() { + return getCharPositionInLine(); + } + +} Added: branches/asm/src/org/python/antlr/ast/ErrorSlice.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ErrorSlice.java (rev 0) +++ branches/asm/src/org/python/antlr/ast/ErrorSlice.java 2008-08-08 23:54:06 UTC (rev 5112) @@ -0,0 +1,32 @@ +package org.python.antlr.ast; +import org.python.antlr.PythonTree; +import org.antlr.runtime.CommonToken; +import org.antlr.runtime.Token; +import java.io.DataOutputStream; +import java.io.IOException; + +public class ErrorSlice extends sliceType { + + public static final String[] _fields = new String[] {}; + + public ErrorSlice(PythonTree tree) { + super(tree); + } + + public String toString() { + return "ErrorSlice"; + } + + public String toStringTree() { + return "ErrorSlice"; + } + + public int getLineno() { + return getLine(); + } + + public int getCol_offset() { + return getCharPositionInLine(); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |