Antlr4.Runtime.DefaultErrorStrategy.ReportUnwantedToken C# (CSharp) Method

ReportUnwantedToken() protected method

This method is called to report a syntax error which requires the removal of a token from the input stream.
This method is called to report a syntax error which requires the removal of a token from the input stream. At the time this method is called, the erroneous symbol is current LT(1) symbol and has not yet been removed from the input stream. When this method returns, recognizer is in error recovery mode.

This method is called when SingleTokenDeletion(Parser) identifies single-token deletion as a viable recovery strategy for a mismatched input error.

The default implementation simply returns if the handler is already in error recovery mode. Otherwise, it calls BeginErrorCondition(Parser) to enter error recovery mode, followed by calling Parser.NotifyErrorListeners(string) .

protected ReportUnwantedToken ( Parser recognizer ) : void
recognizer Parser the parser instance
return void
        protected internal virtual void ReportUnwantedToken(Parser recognizer)
        {
            if (InErrorRecoveryMode(recognizer))
            {
                return;
            }
            BeginErrorCondition(recognizer);
            IToken t = recognizer.CurrentToken;
            string tokenName = GetTokenErrorDisplay(t);
            IntervalSet expecting = GetExpectedTokens(recognizer);
            string msg = "extraneous input " + tokenName + " expecting " + expecting.ToString(recognizer.Vocabulary);
            recognizer.NotifyErrorListeners(t, msg, null);
        }