Esempio n. 1
0
        override public void SyntaxError(
            TextWriter output,
            IRecognizer recognizer,
            IToken offendingSymbol,
            int line,
            int charPositionInLine,
            string msg,
            RecognitionException e
            )
        {
            StringBuilder sb = new StringBuilder();

            sb.Append($"Syntax error at line {line}:{charPositionInLine}\n");
            var expected = e.GetExpectedTokens()
                           .ToIntegerList()
                           .Select((tok, index) => {
                var str = recognizer.Vocabulary.GetLiteralName(tok);
                if (str == null)
                {
                    return(recognizer.Vocabulary.GetDisplayName(tok));
                }
                return(str);
            }).ToList();

            sb.Append("Expected one of: " + String.Join(", ", expected));
            throw new ParseFailure(sb.ToString());
        }
Esempio n. 2
0
        private static bool CheckForInputMismatchWithNoExpected(RecognitionException e)
        {
            if (!(e is InputMismatchException))
            {
                return false;
            }

            var expectedTokens = e.GetExpectedTokens().ToList();
            if (expectedTokens.Count > 1)
            {
                return false;
            }

            return expectedTokens.Count == 1 && expectedTokens[0] == -1;
        }
Esempio n. 3
0
 public void SyntaxError([NotNull] IRecognizer recognizer, [Nullable] IToken offendingSymbol, int line, int charPositionInLine, [NotNull] string msg, [Nullable] RecognitionException e)
 {
     if (e != null)
     {
         var expected_tokens = e.GetExpectedTokens();
         if ((e.OffendingToken.Type == CloacaLexer.Eof ||
              (expected_tokens.Count > 0 && (expected_tokens.Contains(CloacaParser.INDENT) || expected_tokens.Contains(CloacaParser.NEWLINE)))))
         {
             // Eat the error if it's just complaining that it expected more text in the REPL.
             ExpectedMoreText = true;
             return;
         }
     }
     else if (offendingSymbol.Text == "<EOF>" && charPositionInLine == 0)
     {
         // Eat the error if it's just complaining that it expected more text in the REPL.
         ExpectedMoreText = true;
         return;
     }
     Errors.Add("line " + line + ":" + charPositionInLine + " " + msg);
 }