From: <fwi...@us...> - 2008-11-14 16:07:45
|
Revision: 5579 http://jython.svn.sourceforge.net/jython/?rev=5579&view=rev Author: fwierzbicki Date: 2008-11-14 16:07:43 +0000 (Fri, 14 Nov 2008) Log Message: ----------- Fix for NPE's and a weird Antlr error that can occur when Antlr is allowed to recover from parser errrors (for example, when ListErrorHandler is used). Modified Paths: -------------- trunk/jython/grammar/Python.g Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2008-11-14 07:35:53 UTC (rev 5578) +++ trunk/jython/grammar/Python.g 2008-11-14 16:07:43 UTC (rev 5579) @@ -307,7 +307,10 @@ $file_input.tree = mtype; } : (NEWLINE - | stmt {stypes.addAll($stmt.stypes);} + | stmt { + if ($stmt.stypes != null) + {stypes.addAll($stmt.stypes);} + } )* EOF { mtype = new Module($file_input.start, actions.castStmts(stypes)); } @@ -937,10 +940,11 @@ $stypes = $simple_stmt.stypes; } | NEWLINE INDENT - (stmt - { + (stmt { + if ($stmt.stypes != null) { $stypes.addAll($stmt.stypes); } + } )+ DEDENT ; @@ -1119,6 +1123,14 @@ -> $left ) ; + // This only happens when Antlr is allowed to do error recovery (for example if ListErrorHandler + // is used. It is at least possible that this is a bug in Antlr itself, so this needs further + // investigation. To reproduce, set errorHandler to ListErrorHandler and try to parse "[". + catch [RewriteCardinalityException rce] { + PythonTree badNode = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), null); + retval.tree = badNode; + errorHandler.error("Internal Parser Error", badNode); + } arith_op returns [operatorType op] : PLUS {$op = operatorType.Add;} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |