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; }
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; }
public override void Execute(ParserContext context) { ReportSyntaxError(context); if (!TryRecover(context)) { context.SendLogMessage(MessageSeverity.Error, "Failed to recover from syntax error."); context.CurrentState = null; } }
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); }
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; }
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; }
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); }