[Pydev-cvs] org.python.pydev/src/org/python/pydev/parser PyParser.java,1.9,1.10
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2004-09-22 16:32:50
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8307/src/org/python/pydev/parser Modified Files: PyParser.java Log Message: Changes to PyParser. Now it tries to parse one more time if a parser error occurs, substituting the error line for a pass, so that we have more changes of getting the class and method definition tokens on ModelUtils. Index: PyParser.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/parser/PyParser.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PyParser.java 22 Jul 2004 16:14:53 -0000 1.9 --- PyParser.java 22 Sep 2004 16:32:41 -0000 1.10 *************** *** 26,29 **** --- 26,30 ---- import org.python.parser.TokenMgrError; import org.python.pydev.editor.PyEdit; + import org.python.pydev.editor.codecompletion.PyCodeCompletion; /** *************** *** 53,56 **** --- 54,58 ---- boolean parseNow = false; // synchronized access by ParsingThread + /* * counter how to parse. 0 means do not parse, > 0 means wait this many *************** *** 100,103 **** --- 102,106 ---- final PyParser parser = this; documentListener = new IDocumentListener() { + public void documentChanged(DocumentEvent event) { if (event == null || event.getText() == null || event.getText().indexOf("\n") == -1) { *************** *** 167,174 **** StringReader inString = new StringReader(document.get()); ReaderCharStream in = new ReaderCharStream(inString); IParserHost host = new CompilerAPI(); ! PythonGrammar g1 = new PythonGrammar((CharStream) null, ! (IParserHost) null); PythonGrammar grammar = new PythonGrammar(in, host); --- 170,189 ---- StringReader inString = new StringReader(document.get()); ReaderCharStream in = new ReaderCharStream(inString); + reparseDocument(in, true); + } + + /** + * + * @param in char stream to read + * @param reparseIfErrorFound boolean indicating that another reparse should + * be attempted, changing the current text line for a 'pass', so that we can + * give outline and some feedback. + * (Maybe a good idea would be a fast parser that is error aware and that finds + * the information we need, as class and function definitions). + */ + private void reparseDocument(ReaderCharStream in, boolean reparseIfErrorFound) { IParserHost host = new CompilerAPI(); ! PythonGrammar g1 = new PythonGrammar((CharStream) null, (IParserHost) null); PythonGrammar grammar = new PythonGrammar(in, host); *************** *** 177,192 **** if (input == null) return; ! IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input) ! .getFile() ! : null; try { SimpleNode newRoot = grammar.file_input(); // parses the file ! if (original != null) original.deleteMarkers(IMarker.PROBLEM, false, 1); fireParserChanged(newRoot); } catch (ParseException parseErr) { ! fireParserError(parseErr); } catch (TokenMgrError tokenErr) { ! fireParserError(tokenErr); } catch (Exception e) { System.err.println("Unexpected parse error"); --- 192,211 ---- if (input == null) return; ! IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null; try { SimpleNode newRoot = grammar.file_input(); // parses the file ! ! if (original != null && reparseIfErrorFound) original.deleteMarkers(IMarker.PROBLEM, false, 1); + fireParserChanged(newRoot); } catch (ParseException parseErr) { ! if (reparseIfErrorFound) ! tryReparseAgain(parseErr); ! } catch (TokenMgrError tokenErr) { ! if (reparseIfErrorFound) ! tryReparseAgain(tokenErr); ! } catch (Exception e) { System.err.println("Unexpected parse error"); *************** *** 194,197 **** --- 213,265 ---- } } + + /** + * @param tokenErr + */ + private void tryReparseAgain(TokenMgrError tokenErr) { + int line = tokenErr.errorLine; + + tryReparseChangingLine(line); + + fireParserError(tokenErr); //in this on + } + + /** + * This method tries to reparse the code again, changing the current line to + * a 'pass' + * + * Any new errors are ignored, and the error passed as a parameter is fired + * anyway, so, the utility of this function is trying to make a real model + * without any problems, so that we can update the outline and ModelUtils + * with a good aproximation of the code. + * + * @param tokenErr + */ + private void tryReparseAgain(ParseException tokenErr) { + int line = 0; + if(tokenErr.currentToken.image.equals(".") || tokenErr.currentToken.image.equals("(")){ + line = tokenErr.currentToken.beginLine-1; + }else{ + line = tokenErr.currentToken.beginLine; + } + + + tryReparseChangingLine(line); + + fireParserError(tokenErr); + } + + /** + * @param line + * + */ + private void tryReparseChangingLine(int line) { + String docToParse = PyCodeCompletion.getDocToParseFromLine(document, line); + + // create a stream with document's data + StringReader inString = new StringReader(docToParse); + ReaderCharStream in = new ReaderCharStream(inString); + reparseDocument(in, false); + } } *************** *** 210,214 **** private static ArrayList parsers = new ArrayList(); // synchronized access ! // only private boolean done = false; --- 278,283 ---- private static ArrayList parsers = new ArrayList(); // synchronized access ! ! // only private boolean done = false; |