public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e) { var outputWindow = OutputWindowService.TryGetPane(PredefinedOutputWindowPanes.TvlIntellisense); if (outputWindow != null) { string header = GetErrorHeader(e); string message = GetErrorMessage(e, tokenNames); Span span = new Span(); if (e.Token != null) span = Span.FromBounds(e.Token.StartIndex, e.Token.StopIndex + 1); if (message.Length > 100) message = message.Substring(0, 100) + " ..."; ITextDocument document; if (TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out document) && document != null) { string fileName = document.FilePath; var line = Snapshot.GetLineFromPosition(span.Start); message = string.Format("{0}({1},{2}): {3}: {4}", fileName, line.LineNumber + 1, span.Start - line.Start.Position + 1, GetType().Name, message); } outputWindow.WriteLine(message); } base.DisplayRecognitionError(tokenNames, e); }
public override string GetErrorMessage(RecognitionException e, string[] tokenNames) { System.Collections.IList stack = GetRuleInvocationStack(e, typeof(BlaiseParser).FullName); string msg = string.Empty; if (e is NoViableAltException) { NoViableAltException nvae = (NoViableAltException)e; msg = "noviablealt;token=" + e.Token.ToString() + "(decision=" + nvae.decisionNumber + "state" + nvae.stateNumber + ")" + "decision=<<" + nvae.grammarDecisionDescription + ">>"; } else { msg = base.GetErrorMessage(e, tokenNames); } string stackStr = string.Empty; foreach (object obj in stack) { stackStr += obj.ToString(); } return stackStr + " " + msg; }
public static QuerySyntaxException Convert(RecognitionException e, string hql) { string positionInfo = e.Line > 0 && e.CharPositionInLine > 0 ? " near line " + e.Line + ", column " + e.CharPositionInLine : ""; return new QuerySyntaxException(e.Message + positionInfo, hql); }
public IASTNode HandleIdentifierError(IToken token, RecognitionException ex) { if (token is HqlToken) { HqlToken hqlToken = (HqlToken)token; // ... and the token could be an identifer and the error is // a mismatched token error ... if (hqlToken.PossibleId && (ex is MismatchedTokenException)) { MismatchedTokenException mte = (MismatchedTokenException)ex; // ... and the expected token type was an identifier, then: if (mte.Expecting == IDENT) { // Use the token as an identifier. _parseErrorHandler.ReportWarning("Keyword '" + token.Text + "' is being interpreted as an identifier due to: " + mte.Message); // Add the token to the AST. token.Type = WEIRD_IDENT; input.Consume(); return((IASTNode)adaptor.Create(token)); } } } // Otherwise, handle the error normally. ReflectHelper.PreserveStackTrace(ex); throw ex; }
public override string GetErrorMessage(RecognitionException e, string[] tokenNames) { if (e is MismatchedTokenException) { MismatchedTokenException exception = (MismatchedTokenException) e; return ("mismatched character " + this.GetCharErrorDisplay(e.Character) + " expecting " + this.GetCharErrorDisplay(exception.Expecting)); } if (e is NoViableAltException) { NoViableAltException exception1 = (NoViableAltException) e; return ("no viable alternative at character " + this.GetCharErrorDisplay(e.Character)); } if (e is EarlyExitException) { EarlyExitException exception5 = (EarlyExitException) e; return ("required (...)+ loop did not match anything at character " + this.GetCharErrorDisplay(e.Character)); } if (e is MismatchedNotSetException) { MismatchedNotSetException exception2 = (MismatchedNotSetException) e; return string.Concat(new object[] { "mismatched character ", this.GetCharErrorDisplay(e.Character), " expecting set ", exception2.Expecting }); } if (e is MismatchedSetException) { MismatchedSetException exception3 = (MismatchedSetException) e; return string.Concat(new object[] { "mismatched character ", this.GetCharErrorDisplay(e.Character), " expecting set ", exception3.Expecting }); } if (e is MismatchedRangeException) { MismatchedRangeException exception4 = (MismatchedRangeException) e; return ("mismatched character " + this.GetCharErrorDisplay(e.Character) + " expecting set " + this.GetCharErrorDisplay(exception4.A) + ".." + this.GetCharErrorDisplay(exception4.B)); } return base.GetErrorMessage(e, tokenNames); }
public void ReportError(RecognitionException e) { ReportError( e.ToString() ); _recognitionExceptions.Add( e ); if ( log.IsDebugEnabled ) { log.Debug( e.ToString(), e ); } }
public AutomationErrorNode(ITokenStream input, IToken start, IToken stop, RecognitionException ex) { var handler = new CommonErrorNode(input, start, stop, ex); this.isNil = handler.IsNil; this.type = handler.Type; this.text = handler.Text; this.toString = handler.ToString(); }
protected virtual void DebugRecognitionException(RecognitionException ex) { IDebugEventListener debugListener = this.recognizer.DebugListener; if (debugListener != null) { debugListener.RecognitionException(ex); } }
public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e) { string headerError = GetErrorHeader(e); string error = GetErrorMessage(e, tokenNames); Errors.Add(new ParseException(new LineInfo(e.Line, e.CharPositionInLine), error)); base.DisplayRecognitionError(tokenNames, e); }
private static string FormatRecognitionException(RecognitionException e, string source) { var res = "Message: " + e.Message + "\n"; res += "Token: " + e.Token.Text + "\n"; res += "Source: " + source + "\n"; res += "Line: " + e.Line + "\n"; res += "Char position in line: " + e.CharPositionInLine + "\n"; return res; }
/** * Constructor. * * @param pInput Will be passed to the constructor of the wrapped object. * @param pStart Will be passed to the constructor of the wrapped object. * @param pStop Will be passed to the constructor of the wrapped object. * @param pException Will be passed to the constructor of the wrapped * object. * * __TEST__ */ public AST2JSOMCommonErrorNode( ITokenStream pInput, IToken pStart, IToken pStop, RecognitionException pException) : base() { //base(); mCommonErrorNode = new CommonErrorNode(pInput, pStart, pStop, pException); }
public override void ReportError(RecognitionException e) { if ( state.errorRecovery ) { return; } state.syntaxErrors++; // don't count spurious state.errorRecovery = true; throw e; }
public static SyntaxErrorException Report(BaseRecognizer source, RecognitionException e) { var input = source.Input.ToString(); if (source.Input is ANTLRStringStream) input = new String((Char[])typeof(ANTLRStringStream).GetField("data", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(source.Input)); var antlrMessage = source.GetErrorHeader(e) + " " + source.GetErrorMessage(e, source.TokenNames); throw new SyntaxErrorException(input, antlrMessage, e); }
/// <summary> /// Logs the given error to the <see cref="ErrorTracker"/>. /// </summary> /// <param name="tokenNames">The names of the tokens in the current language.</param> /// <param name="e">The error.</param> public override void DisplayRecognitionError(String[] tokenNames, RecognitionException e) { LanguageError lerError = new LanguageError(); lerError.Line = e.Line - 1; lerError.Column = e.CharPositionInLine; lerError.Position = e.Token.StartIndex; lerError.End = e.Token.StopIndex; lerError.Message = GetErrorMessage(e, tokenNames); ErrorTracker.ParserErrors.Add(lerError); }
public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e) { var handler = Error; if (handler != null) { handler(string.Format("{0} {1}", GetErrorHeader(e), GetErrorMessage(e, tokenNames))); } base.DisplayRecognitionError(tokenNames, e); }
public SyntaxErrorException(string input, String antlrMessage, RecognitionException exception) : base(JSToCSharpExceptionType.SyntaxError, exception) { AntlrMessage = antlrMessage; Input = input; var span = AntlrException.Token == null ? -1 : AntlrException.Token.Text.Length; var prettyInput = input.InjectErrorMarker(LineNumber, CharPositionInLine, span).InjectLineNumbers1(); SourceCode = prettyInput; }
public CommonErrorNode(ITokenStream input, IToken start, IToken stop, RecognitionException e) { if ((stop == null) || ((stop.TokenIndex < start.TokenIndex) && (stop.Type != -1))) { stop = start; } this.input = input; this.start = start; this.stop = stop; this.trappedException = e; }
public override void DisplayRecognitionError(String[] tokenNames, RecognitionException e) { base.DisplayRecognitionError(tokenNames, e); if (Errors == null) Errors = new List<string>(); var hdr = GetErrorHeader(e); var msg = GetErrorMessage(e, tokenNames); Errors.Add(msg + " at " + hdr); }
public override void ReportError( RecognitionException e ) { StringTemplateGroup group = self.Group; if ( group == StringTemplate.defaultGroup ) { self.Error( "action parse error; template context is " + self.GetEnclosingInstanceStackString(), e ); } else { self.Error( "action parse error in group " + self.Group.Name + " line " + self.GroupFileLine + "; template context is " + self.GetEnclosingInstanceStackString(), e ); } }
/// <summary> /// Creates a <see cref="CompilerError"/> instance with a specific <see cref="Exception"/>. /// </summary> /// <param name="exception">Compiler exception.</param> public CompilerError(RecognitionException exception) { Token = exception.Token; var result = new StringBuilder(); if (!string.IsNullOrEmpty(FileName)) { result.AppendFormat("{0} ({1},{2}) : ", FileName, Token.Line, Token.CharPositionInLine + 1); } result.AppendFormat("error S0001 : invalid token {0}", Token.Text); Details = result.ToString(); }
public override void ReportError(RecognitionException e) { if (e is MissingTokenException) { errors.Add(string.Format("{0}:{1} - Unexpected {2}\n {3}", e.Line, e.CharPositionInLine, e.Token.Text, e)); } else { errors.Add(string.Format("{0}:{1} - Error with token {2}\n {3}", e.Line, e.CharPositionInLine, e.Token.Text, e.ToString())); } base.ReportError(e); }
public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e) { string header = GetErrorHeader(e); string message = GetErrorMessage(e, tokenNames); Span span = new Span(); if (e.Token != null) span = Span.FromBounds(e.Token.StartIndex, e.Token.StopIndex + 1); ParseErrorEventArgs args = new ParseErrorEventArgs(message, span); OnParseError(args); base.DisplayRecognitionError(tokenNames, e); }
public override string GetErrorMessage(RecognitionException e, string[] tokenNames) { if (this != null) { ITreeAdaptor treeAdaptor = ((ITreeNodeStream) e.Input).TreeAdaptor; e.Token = treeAdaptor.GetToken(e.Node); if (e.Token == null) { e.Token = new CommonToken(treeAdaptor.GetType(e.Node), treeAdaptor.GetText(e.Node)); } } return base.GetErrorMessage(e, tokenNames); }
public override void DisplayRecognitionError( string[] tokenNames, RecognitionException e) { var sb = new StringBuilder(); sb.AppendLine("There was a problem with the json input during syntactical analysis and it cannot be parsed. Here is some more info:"); sb.AppendLine("----"); sb.AppendLine(e.Message); sb.AppendLine("region: " + e.Input.ToString()); sb.AppendLine("line: " + e.Line); sb.AppendLine("col: " + e.CharPositionInLine); throw new JsonException(sb.ToString(), e); }
public override void DisplayRecognitionError(string[] tokenNames, RecognitionException e) { if (OnDisplayRecognitionError != null) { csParserException ce = new csParserException(); ce._tokenNames = tokenNames; ce._source = this; ce._exception = e; ce._errorStr = GetErrorHeader(e) + " " + GetErrorMessage(e, tokenNames); OnDisplayRecognitionError(ce); } //base.DisplayRecognitionError(tokenNames, e); string hdr = GetErrorHeader(e); string msg = GetErrorMessage(e, tokenNames); _SyntaxErrors.Add(hdr + " " + msg); EmitErrorMessage(hdr + " " + msg); }
public CommonErrorNode(ITokenStream input, IToken start, IToken stop, RecognitionException e) { if (stop == null || (stop.TokenIndex < start.TokenIndex && stop.Type != Runtime.Token.EOF) ) { // sometimes resync does not consume a token (when LT(1) is // in follow set). So, stop will be 1 to left to start. adjust. // Also handle case where start is the first token and no token // is consumed during recovery; LT(-1) will return null. stop = start; } this.input = input; this.start = start; this.stop = stop; this.trappedException = e; }
public override void ReportError(RecognitionException e) { string msg = null; if (e is NoViableAltException) { msg = "invalid character '" + (char)input.LA(1) + "'"; } else if (e is MismatchedTokenException && ((MismatchedTokenException)e).expecting == '"') { msg = "unterminated string"; } else { msg = GetErrorMessage(e, TokenNames); } ErrorManager.SyntaxError(ErrorType.SyntaxError, e, msg, SourceName); }
protected override object GetMissingSymbol(IIntStream input, RecognitionException e, int expectedTokenType, BitSet follow) { String tokenText = null; if ( expectedTokenType==Token.EOF ) tokenText = "<missing EOF>"; else tokenText = "<missing " + TokenNames[expectedTokenType] + ">"; CommonToken t = new CommonToken(expectedTokenType, tokenText); IToken current = ((ITokenStream)input).LT(1); if (current.Type == Token.EOF) { current = ((ITokenStream)input).LT(-1); } t.line = current.Line; t.CharPositionInLine = current.CharPositionInLine; t.Channel = DEFAULT_TOKEN_CHANNEL; return t; }
public override void ReportError(RecognitionException ex) { IToken token = null; if (ex is MismatchedTokenException) { token = ((MismatchedTokenException)ex).Token; } else if (ex is NoViableAltException) { token = ((NoViableAltException)ex).Token; } ErrorManager.SyntaxError( ErrorManager.MSG_SYNTAX_ERROR, grammar, token, "assign.types: " + ex.ToString(), ex); }
public GrammarASTErrorNode(ITokenStream input, IToken start, IToken stop, RecognitionException e) { //Console.Out.WriteLine( "start: " + start + ", stop: " + stop ); if (stop == null || (stop.TokenIndex < start.TokenIndex && stop.Type != TokenTypes.EndOfFile)) { // sometimes resync does not consume a token (when LT(1) is // in follow set. So, stop will be 1 to left to start. adjust. // Also handle case where start is the first token and no token // is consumed during recovery; LT(-1) will return null. stop = start; } this.input = input; this.start = start; this.stop = stop; this.trappedException = e; }
public override void ReportError(RecognitionException ex) { IToken token = null; if (ex is MismatchedTokenException) { token = ((MismatchedTokenException)ex).Token; } else if (ex is NoViableAltException) { token = ((NoViableAltException)ex).Token; } ErrorManager.SyntaxError( ErrorManager.MSG_SYNTAX_ERROR, grammar, token, "antlr.print: " + ex.ToString(), ex); }
public override void ReportError(RecognitionException ex) { //Token token = null; //try //{ // token = LT( 1 ); //} //catch ( TokenStreamException tse ) //{ // ErrorManager.internalError( "can't get token???", tse ); //} IToken token = ex.Token; ErrorManager.SyntaxError( ErrorManager.MSG_SYNTAX_ERROR, Grammar, token, "antlr: " + ex.ToString(), ex); }
public override void ReportError(RecognitionException exception) { // Add error report here base.ReportError(exception); if (exception is NoViableAltException) { // Throw an error that we can't continue the execution/parsing of this input throw new ParseException("No Viable Alternate", false, exception); } else if (exception is UnwantedTokenException) { UnwantedTokenException ex = (UnwantedTokenException)exception; // check if we can continue bool canContinue = (ex.Token.Text == "{"); // TODO: change this a constant // Throw an error that we can't continue the execution/parsing of this input throw new ParseException("Unwanted token found:" + ex.Token.Text, canContinue, ex); } // Throw an error, maybe we can continue the execution? throw new ParseException(exception.Message, true, exception); }
public override void ReportError(Antlr.Runtime.RecognitionException e) { throw new UnexpectedTokenSaqaException(e); }
public virtual void DisplayRecognitionError(string[] tokenNames, RecognitionException e) { this.EmitErrorMessage(this.GetErrorHeader(e) + " " + this.GetErrorMessage(e, tokenNames)); }
protected virtual void DebugRecognitionException(RecognitionException ex) { this.DebugListener?.RecognitionException(ex); }
public override void ReportError(RecognitionException e) { _parseErrorHandler.ReportError(e); }
public override object ErrorNode(ITokenStream input, IToken start, IToken stop, RecognitionException e) { GrammarAST t = new GrammarASTErrorNode(input, start, stop, e); if (_outer != null) { t.enclosingRuleName = _outer.currentRuleName; } return(t); }
public override void ReportError(Antlr.Runtime.RecognitionException e) { Errors.AddError(new CodeErrorItem(e.ToString(), e.Token, e.Token)); base.ReportError(e); }
/** <summary> * Lexers can normally match any char in it's vocabulary after matching * a token, so do the easy thing and just kill a character and hope * it all works out. You can instead use the rule invocation stack * to do sophisticated error recovery if you are in a fragment rule. * </summary> */ public virtual void Recover(RecognitionException re) { //System.out.println("consuming char "+(char)input.LA(1)+" during recovery"); //re.printStackTrace(); input.Consume(); }
/** <summary>What error message should be generated for the various exception types?</summary> * * <remarks> * Not very object-oriented code, but I like having all error message * generation within one method rather than spread among all of the * exception classes. This also makes it much easier for the exception * handling because the exception classes do not have to have pointers back * to this object to access utility routines and so on. Also, changing * the message for an exception type would be difficult because you * would have to subclassing exception, but then somehow get ANTLR * to make those kinds of exception objects instead of the default. * This looks weird, but trust me--it makes the most sense in terms * of flexibility. * * For grammar debugging, you will want to override this to add * more information such as the stack frame with * getRuleInvocationStack(e, this.getClass().getName()) and, * for no viable alts, the decision description and state etc... * * Override this to change the message generated for one or more * exception types. * </remarks> */ public virtual string GetErrorMessage(RecognitionException e, string[] tokenNames) { string msg = e.Message; if (e is UnwantedTokenException) { UnwantedTokenException ute = (UnwantedTokenException)e; string tokenName = "<unknown>"; if (ute.Expecting == TokenTypes.EndOfFile) { tokenName = "EndOfFile"; } else { tokenName = tokenNames[ute.Expecting]; } msg = "extraneous input " + GetTokenErrorDisplay(ute.UnexpectedToken) + " expecting " + tokenName; } else if (e is MissingTokenException) { MissingTokenException mte = (MissingTokenException)e; string tokenName = "<unknown>"; if (mte.Expecting == TokenTypes.EndOfFile) { tokenName = "EndOfFile"; } else { tokenName = tokenNames[mte.Expecting]; } msg = "missing " + tokenName + " at " + GetTokenErrorDisplay(e.Token); } else if (e is MismatchedTokenException) { MismatchedTokenException mte = (MismatchedTokenException)e; string tokenName = "<unknown>"; if (mte.Expecting == TokenTypes.EndOfFile) { tokenName = "EndOfFile"; } else { tokenName = tokenNames[mte.Expecting]; } msg = "mismatched input " + GetTokenErrorDisplay(e.Token) + " expecting " + tokenName; } else if (e is MismatchedTreeNodeException) { MismatchedTreeNodeException mtne = (MismatchedTreeNodeException)e; string tokenName = "<unknown>"; if (mtne.Expecting == TokenTypes.EndOfFile) { tokenName = "EndOfFile"; } else { tokenName = tokenNames[mtne.Expecting]; } // workaround for a .NET framework bug (NullReferenceException) string nodeText = (mtne.Node != null) ? mtne.Node.ToString() ?? string.Empty : string.Empty; msg = "mismatched tree node: " + nodeText + " expecting " + tokenName; } else if (e is NoViableAltException) { //NoViableAltException nvae = (NoViableAltException)e; // for development, can add "decision=<<"+nvae.grammarDecisionDescription+">>" // and "(decision="+nvae.decisionNumber+") and // "state "+nvae.stateNumber msg = "no viable alternative at input " + GetTokenErrorDisplay(e.Token); } else if (e is EarlyExitException) { //EarlyExitException eee = (EarlyExitException)e; // for development, can add "(decision="+eee.decisionNumber+")" msg = "required (...)+ loop did not match anything at input " + GetTokenErrorDisplay(e.Token); } else if (e is MismatchedSetException) { MismatchedSetException mse = (MismatchedSetException)e; msg = "mismatched input " + GetTokenErrorDisplay(e.Token) + " expecting set " + mse.Expecting; } else if (e is MismatchedNotSetException) { MismatchedNotSetException mse = (MismatchedNotSetException)e; msg = "mismatched input " + GetTokenErrorDisplay(e.Token) + " expecting set " + mse.Expecting; } else if (e is FailedPredicateException) { FailedPredicateException fpe = (FailedPredicateException)e; msg = "rule " + fpe.RuleName + " failed predicate: {" + fpe.PredicateText + "}?"; } return(msg); }
/** <summary>What is the error header, normally line/character position information?</summary> */ public override string GetErrorHeader(RecognitionException e) { string prefix = SourceName ?? string.Empty; if (prefix.Length > 0) prefix += ' '; return string.Format("{0}line {1}:{2}", prefix, e.Line, e.CharPositionInLine + 1); }