protected List <object> performSyntaxAnalysis( TextReader inR, string sourceName, StreamWriter err, Type nodeClass, HashSet <Exception> pErrors) { OCLWorkbenchLexer lexer = new OCLWorkbenchLexer(inR, sourceName, err, pErrors); OCLWorkbenchParser parser = new OCLWorkbenchParser(sourceName, lexer, err, pErrors); List <object> result = null; OCLCompilerException compilerException = null; try { result = parseNode(parser, nodeClass); } catch (antlr.RecognitionException e) { compilerException = new OCLSyntaticException(e.Message, new SourceLocation(parser.getFilename(), e.getLine(), e.getColumn())); } catch (antlr.TokenStreamRecognitionException e) { compilerException = new OCLSyntaticException(e.Message, new SourceLocation(parser.getFilename(), e.recog.getLine(), e.recog.getColumn())); } catch (antlr.TokenStreamException e) { compilerException = new OCLSyntaticException(e.Message, new SourceLocation(parser.getFilename(), -1, -1)); } catch (Exception e) { if (e.Message != null) { compilerException = new OCLCompilerException(e.Message, new SourceLocation(parser.getFilename(), -1, -1)); } } finally { if ((err != null) && (compilerException != null)) { errors.Add(compilerException); syntaticErrorsCount++; err.WriteLine(compilerException); err.Flush(); } } syntaticErrorsCount += parser.getErrorCount(); if ((err != null) && ((syntaticErrorsCount != 0) || (compilerException != null))) { err.Flush(); } return(result); }
/* Overridden methods. */ public override void reportError(RecognitionException ex) { OCLSyntaticException error = new OCLSyntaticException(ex.Message, new SourceLocation(getFilename(), ex.getLine(), ex.getColumn())); errors.Add(error); if (this.err != null) { this.err.WriteLine(error); } incErrorCount(); }
/** * Overrides default error-reporting function. */ public override void reportError(antlr.RecognitionException ex) { // if this is a NoViableAltForCharException there // is still no column information in antlr, so we // use the current column OCLSyntaticException error = new OCLSyntaticException(ex.Message, new SourceLocation(getFilename(), ex.getLine(), getColumn())); if (this.err != null) { this.err.WriteLine(error); } // continue but remember that we had errors this.parser.incErrorCount(); }