Esempio n. 1
0
        public override void ReportError(Antlr4.Runtime.Parser recognizer, RecognitionException e)
        {
            IntervalSet x = recognizer.GetExpectedTokens();

            LASet[e] = Filter(x);
            base.ReportError(recognizer, e);
        }
Esempio n. 2
0
        protected virtual string ErrorMessageForMissingToken(Antlr4.Runtime.Parser recognizer, IToken t)
        {
            IntervalSet expecting = GetExpectedTokens(recognizer);
            string      msg       = "missing " + GetListOfExpectedTokens(expecting, recognizer.Vocabulary) + " at " + GetTokenErrorDisplay(t);

            return(msg);
        }
 public override void ReportAmbiguity(Antlr4.Runtime.Parser recognizer, DFA dfa, int startIndex, int stopIndex,
                                      bool exact, BitSet ambigAlts,
                                      ATNConfigSet configs)
 {
     //TODO : make sure that 'dfa.ToLexerString()' has meaningful and expected output. Not sure about that...
     Errors?.Add(new SyntaxErrorException(
                     $"Ambiguity error while parsing '{dfa.ToLexerString()}'. (start index: {startIndex}, stop index: {stopIndex})"));
 }
Esempio n. 4
0
 public override void ReportAttemptingFullContext(Antlr4.Runtime.Parser recognizer,
                                                  DFA dfa,
                                                  int startIndex,
                                                  int stopIndex,
                                                  BitSet conflictingAlts,
                                                  SimulatorState conflictState)
 {
 }
Esempio n. 5
0
 public override void ReportContextSensitivity(Antlr4.Runtime.Parser recognizer,
                                               DFA dfa,
                                               int startIndex,
                                               int stopIndex,
                                               int prediction,
                                               SimulatorState acceptState)
 {
 }
Esempio n. 6
0
        // --- Override the five methods below to customize Antlr error messages ---

        protected virtual string ErrorMessageForUnexpectedToken(Antlr4.Runtime.Parser recognizer, IToken t)
        {
            string      tokenName = GetTokenErrorDisplay(t);
            IntervalSet expecting = GetExpectedTokens(recognizer);
            string      msg       = "extraneous input " + tokenName + " expecting " + GetListOfExpectedTokens(expecting, recognizer.Vocabulary);

            return(msg);
        }
Esempio n. 7
0
 public override void ReportAmbiguity(Antlr4.Runtime.Parser recognizer,
                                      DFA dfa,
                                      int startIndex,
                                      int stopIndex,
                                      bool exact,
                                      BitSet ambigAlts,
                                      ATNConfigSet configs)
 {
 }
Esempio n. 8
0
        public AntlrPerformanceProfiler(Antlr4.Runtime.Parser parser)
        {
            parserRulesCount     = parser.RuleNames.Length;
            parserRuleNames      = parser.RuleNames;
            parserDecisionsCount = parser.Atn.DecisionToDfa.Length;

            ParsedFilesInfos   = new List <ParsedFileInfo>();
            AggregatedPerfInfo = new ParsedFileInfo("TOTAL", parserRulesCount, parserDecisionsCount);
            RuleStacksCount    = new Dictionary <string, int>();
        }
Esempio n. 9
0
 /// <summary>
 /// A compiler directive can be embedded anywhere in the Cobol syntax
 /// so we can consider that EOF is always present in the following set
 /// </summary>
 public override void Sync(Antlr4.Runtime.Parser recognizer)
 {
     if (GetExpectedTokens(recognizer).Contains(TokenConstants.Eof))
     {
         return;
     }
     else
     {
         base.Sync(recognizer);
     }
 }
 public override void ReportAttemptingFullContext(
     [NotNull] Antlr4.Runtime.Parser recognizer,
     [NotNull] DFA dfa,
     int startIndex,
     int stopIndex,
     [Nullable] BitSet conflictingAlts,
     [NotNull] SimulatorState conflictState)
 {
     Errors.Add(
         new AttemptingFullContextParseError(recognizer, dfa, startIndex, stopIndex, conflictingAlts, conflictState)
         );
 }
 public override void ReportContextSensitivity(
     [NotNull] Antlr4.Runtime.Parser recognizer,
     [NotNull] DFA dfa,
     int startIndex,
     int stopIndex,
     int prediction,
     [NotNull] SimulatorState acceptState)
 {
     Errors.Add(
         new ContextSensivityParseError(recognizer, dfa, startIndex, stopIndex, prediction, acceptState)
         );
 }
Esempio n. 12
0
        /// <summary>
        /// This method is called to report a syntax error which requires the
        /// insertion of a missing token into the input stream.
        /// </summary>
        protected override void ReportMissingToken(Antlr4.Runtime.Parser recognizer)
        {
            if (InErrorRecoveryMode(recognizer))
            {
                return;
            }
            BeginErrorCondition(recognizer);
            IToken t   = recognizer.CurrentToken;
            string msg = ErrorMessageForMissingToken(recognizer, t);

            recognizer.NotifyErrorListeners(t, msg, null);
        }
 public override void ReportAmbiguity(
     [NotNull] Antlr4.Runtime.Parser recognizer,
     [NotNull] DFA dfa,
     int startIndex,
     int stopIndex,
     bool exact,
     [Nullable] BitSet ambigAlts,
     [NotNull] ATNConfigSet configs)
 {
     Errors.Add(
         new AmbiguityParseError(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs)
         );
 }
Esempio n. 14
0
        // --- Please do not touch the methods below which reproduce exactly the default Antlr runtime behaviour --

        /// <summary>
        /// Single token deletion recovery strategy
        /// </summary>
        protected override IToken SingleTokenDeletion(Antlr4.Runtime.Parser recognizer)
        {
            Token lastConsumedToken = (Token)((ITokenStream)recognizer.InputStream).Lt(-1);
            Token nextToken         = (Token)((ITokenStream)recognizer.InputStream).Lt(1);

            if (ErrorStrategyShouldNotConsumeThisToken(lastConsumedToken, nextToken))
            {
                return(null);
            }
            else
            {
                return(base.SingleTokenDeletion(recognizer));
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Multiple token deletion resynchronization strategy
        /// </summary>
        protected override void ConsumeUntil(Antlr4.Runtime.Parser recognizer, IntervalSet set)
        {
            Token lastConsumedToken = (Token)((ITokenStream)recognizer.InputStream).Lt(-1);
            Token nextToken         = (Token)((ITokenStream)recognizer.InputStream).Lt(1);
            int   ttype             = nextToken.Type;

            while (ttype != TokenConstants.Eof && !set.Contains(ttype) &&
                   !ErrorStrategyShouldNotConsumeThisToken(lastConsumedToken, nextToken))
            {
                recognizer.Consume();
                lastConsumedToken = nextToken;
                nextToken         = (Token)((ITokenStream)recognizer.InputStream).Lt(1);
                ttype             = nextToken.Type;
            }
        }
Esempio n. 16
0
        protected override void ConsumeUntil(Antlr4.Runtime.Parser recognizer, IntervalSet set)
        {
            int tokenType = ((ITokenStream)recognizer.InputStream).La(1);
            int indents   = 1;

            while (tokenType != TokenConstants.Eof && indents > 0)
            {
                recognizer.Consume();
                tokenType = ((ITokenStream)recognizer.InputStream).La(1);
                if (tokenType == MalinaLexer.INDENT)
                {
                    indents++;
                }
                if (tokenType == MalinaLexer.DEDENT)
                {
                    indents--;
                }
            }
        }
Esempio n. 17
0
        public override void Recover(Antlr4.Runtime.Parser recognizer, RecognitionException e)
        {
            int tokenType = ((ITokenStream)recognizer.InputStream).La(1);
            int indents   = 1;

            while (tokenType != TokenConstants.Eof && indents > 0)
            {
                recognizer.Consume();
                tokenType = ((ITokenStream)recognizer.InputStream).La(1);
                if (tokenType == MalinaLexer.INDENT)
                {
                    indents++;
                }
                if (tokenType == MalinaLexer.DEDENT)
                {
                    indents--;
                }
            }
        }
        protected override void ReportFailedPredicate(Antlr4.Runtime.Parser recognizer, FailedPredicateException e)
        {
            switch (e.Predicate)
            {
            case "FeatureControlFlow":
                NotifyErrorListeners(recognizer, "Control flow expressions not supported in this version of the language", e);
                break;

            case "FeatureConditionalExpr":
                NotifyErrorListeners(recognizer, "Conditional expressions not supported in this version of the language", e);
                break;

            case "FeatureMutableVars":
                NotifyErrorListeners(recognizer, "Mutable variables not supported in this version of the language", e);
                break;

            default:
                base.ReportFailedPredicate(recognizer, e);
                break;
            }
        }
 public void Sync(Antlr4.Runtime.Parser recognizer)
 {
     throw new NotImplementedException();
 }
Esempio n. 20
0
 protected override ParserRuleContext Parse(Antlr4.Runtime.Parser parser)
 {
     return(((ECMAScriptParser)parser).program());
 }
Esempio n. 21
0
        protected virtual string ErrorMessageForFailedPredicate(FailedPredicateException e, Antlr4.Runtime.Parser recognizer)
        {
            string ruleName = recognizer.RuleNames[recognizer.RuleContext.RuleIndex];
            string msg      = "rule " + ruleName + " " + e.Message;

            return(msg);
        }
Esempio n. 22
0
 protected override ParserRuleContext Parse(Antlr4.Runtime.Parser parser) => ((TSqlParser)parser).tsql_file();
Esempio n. 23
0
 public override void Sync(Antlr4.Runtime.Parser recognizer)
 {
 }
 public IToken RecoverInline(Antlr4.Runtime.Parser recognizer)
 {
     throw new NotImplementedException();
 }
Esempio n. 25
0
 protected override ParserRuleContext Parse(Antlr4.Runtime.Parser parser) => ((PlSqlParser)parser).sql_script();
Esempio n. 26
0
 protected override ParserRuleContext Parse(Antlr4.Runtime.Parser parser)
 {
     return(((PlSqlParser)parser).compilation_unit());
 }
 public void ReportError(Antlr4.Runtime.Parser recognizer, RecognitionException e)
 {
     throw new NotImplementedException();
 }
 public void ReportMatch(Antlr4.Runtime.Parser recognizer)
 {
     throw new NotImplementedException();
 }
Esempio n. 29
0
 protected override ParserRuleContext Parse(Antlr4.Runtime.Parser parser) =>
 ((JavaParser)parser).compilationUnit();
 public bool InErrorRecoveryMode(Antlr4.Runtime.Parser recognizer)
 {
     throw new NotImplementedException();
 }