From: <fwi...@us...> - 2008-08-01 20:37:49
|
Revision: 5044 http://jython.svn.sourceforge.net/jython/?rev=5044&view=rev Author: fwierzbicki Date: 2008-08-01 20:37:46 +0000 (Fri, 01 Aug 2008) Log Message: ----------- Better handling of bad dedent. Not perfect since it throws the wrong exception. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/src/org/python/antlr/PythonTokenSource.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-01 20:22:22 UTC (rev 5043) +++ branches/asm/grammar/Python.g 2008-08-01 20:37:46 UTC (rev 5044) @@ -1385,8 +1385,10 @@ for (int i=0; i<spaces; i++) { indentation[i] = ' '; } - String s = new String(indentation); - emit(new ClassicToken(LEADING_WS,new String(indentation))); + ClassicToken c = new ClassicToken(LEADING_WS,new String(indentation)); + c.setLine(input.getLine()); + c.setCharPositionInLine(input.getCharPositionInLine()); + emit(c); } // kill trailing newline if present and then ignore ( ('\r')? '\n' {if (state.token!=null) state.token.setChannel(HIDDEN); else $channel=HIDDEN;})* Modified: branches/asm/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-01 20:22:22 UTC (rev 5043) +++ branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-01 20:37:46 UTC (rev 5044) @@ -202,7 +202,7 @@ } else if (cpos < lastIndent) { // they dedented // how far back did we dedent? - int prevIndex = findPreviousIndent(cpos); + int prevIndex = findPreviousIndent(cpos, t); //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--) { @@ -255,13 +255,20 @@ } /** Return the index on stack of previous indent level == i else -1 */ - protected int findPreviousIndent(int i) { + protected int findPreviousIndent(int i, Token t) { for (int j = sp - 1; j >= 0; j--) { if (indentStack[j] == i) { return j; } } - return FIRST_CHAR_POSITION; + //The -2 is for the special case of getCharPositionInLine in multiline str nodes. + if (i == -1 || i == -2) { + return FIRST_CHAR_POSITION; + } + ParseException p = new ParseException("unindent does not match any outer indentation level"); + p.line = t.getLine(); + p.charPositionInLine = t.getCharPositionInLine(); + throw p; } public String stackString() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |