예제 #1
0
 public override void Execute(ParserContext context)
 {
     context.SendLogMessage(MessageSeverity.Message, ToString());
     CustomAction?.Invoke(context);
     context.ParserStack.Push(context.CurrentNode);
     context.CurrentState = context.CurrentNode.State = NextState;
     context.CurrentNode = null;
 }
예제 #2
0
        public override void Execute(ParserContext context)
        {
            context.SendLogMessage(MessageSeverity.Message, ToString());
            context.Root = context.ParserStack.Pop();
            context.CurrentNode = null;

            context.CurrentState = context.ParserStack.Peek().State;
        }
예제 #3
0
        public override void Execute(ParserContext context)
        {
            ReportSyntaxError(context);

            if (!TryRecover(context))
            {
                context.SendLogMessage(MessageSeverity.Error, "Failed to recover from syntax error.");
                context.CurrentState = null;
            }
        }
예제 #4
0
        private static void ReportSyntaxError(ParserContext context)
        {
            var expectedTokens = context.CurrentState.Actions.Keys.OfType<TokenGrammarElement>().ToArray();

            var node = context.CurrentNode;
            var message = string.Format("Unexpected {0} token. Expected {1}.",
                node.GrammarElement.Name,
                string.Join(" or ", expectedTokens.Select(x => x.Name)));

            context.SyntaxErrors.Add(new SyntaxError(node.Result.Range.Start, message, MessageSeverity.Error));
            context.SendLogMessage(MessageSeverity.Error, message);
        }
예제 #5
0
        public override void Execute(ParserContext context)
        {
            context.SendLogMessage(MessageSeverity.Message, ToString());
            var temp = context.CurrentNode;

            var node = context.CurrentNode = CreateNode(context);
            context.CurrentState = context.ParserStack.Peek().State;

            var action = context.CurrentState.Actions[node.GrammarElement];
            action.Execute(context);

            context.CurrentNode = temp;
        }
예제 #6
0
        private static ShiftParserAction PopToErrorShifter(ParserContext context)
        {
            ParserAction action = null;
            while (context.ParserStack.Any())
            {
                var state = context.ParserStack.Peek().State;
                context.SendLogMessage(MessageSeverity.Message, "Going back to state " + state.Id + ".");
                state.Actions.TryGetValue(Grammar.Error, out action);

                if (action is ShiftParserAction)
                    break;
                context.ParserStack.Pop();
            }

            return action as ShiftParserAction;
        }
예제 #7
0
 public void ReadNextToken(ParserContext context)
 {
     context.SendLogMessage(MessageSeverity.Message, "Read next token.");
     var lexer = context.Lexer;
     lexer.Advance();
     context.CurrentNode = new ParserNode(context, Automaton.Grammar.ToElement(lexer.Current.GetTokenCode()), lexer.Current);
 }