internal static AntlrParseResultEventArgs ParseSnapshot(ITextSnapshot snapshot) { Stopwatch timer = Stopwatch.StartNew(); ITokenSource tokenSource = new GrammarLexer(new AntlrInputStream(snapshot.GetText())); CommonTokenStream tokenStream = new CommonTokenStream(tokenSource); GrammarParser.GrammarSpecContext parseResult; GrammarParser parser = new GrammarParser(tokenStream); List<ParseErrorEventArgs> errors = new List<ParseErrorEventArgs>(); try { parser.Interpreter.PredictionMode = PredictionMode.Sll; parser.RemoveErrorListeners(); parser.BuildParseTree = true; parser.ErrorHandler = new BailErrorStrategy(); parseResult = parser.grammarSpec(); } catch (ParseCanceledException ex) { if (!(ex.InnerException is RecognitionException)) throw; tokenStream.Reset(); parser.Interpreter.PredictionMode = PredictionMode.Ll; //parser.AddErrorListener(DescriptiveErrorListener.Default); parser.SetInputStream(tokenStream); parser.ErrorHandler = new DefaultErrorStrategy(); parseResult = parser.grammarSpec(); } return new AntlrParseResultEventArgs(snapshot, errors, timer.Elapsed, tokenStream.GetTokens(), parseResult); }
internal static AntlrParseResultEventArgs ParseSnapshot(ITextSnapshot snapshot) { Stopwatch timer = Stopwatch.StartNew(); ITokenSource tokenSource = new GrammarLexer(new AntlrInputStream(snapshot.GetText())); CommonTokenStream tokenStream = new CommonTokenStream(tokenSource); GrammarParser.GrammarSpecContext parseResult; GrammarParser parser = new GrammarParser(tokenStream); List <ParseErrorEventArgs> errors = new List <ParseErrorEventArgs>(); try { parser.Interpreter.PredictionMode = PredictionMode.Sll; parser.RemoveErrorListeners(); parser.BuildParseTree = true; parser.ErrorHandler = new BailErrorStrategy(); parseResult = parser.grammarSpec(); } catch (ParseCanceledException ex) when(ex.InnerException is RecognitionException) { tokenStream.Reset(); parser.Interpreter.PredictionMode = PredictionMode.Ll; //parser.AddErrorListener(DescriptiveErrorListener.Default); parser.SetInputStream(tokenStream); parser.ErrorHandler = new DefaultErrorStrategy(); parseResult = parser.grammarSpec(); } return(new AntlrParseResultEventArgs(snapshot, errors, timer.Elapsed, tokenStream.GetTokens(), parseResult)); }
private IList<IAnchor> CreateReferenceAnchorPoints(ITextSnapshot snapshot, GrammarParser.GrammarSpecContext parseResult) { if (parseResult == null) { AntlrParseResultEventArgs resultEventArgs = Antlr4BackgroundParser.ParseSnapshot(snapshot); parseResult = (GrammarParser.GrammarSpecContext)resultEventArgs.Result; } AnchorListener listener = new AnchorListener(snapshot); ParseTreeWalker.Default.Walk(listener, parseResult); return listener.Anchors; }
public override void EnterGrammarType(GrammarParser.GrammarTypeContext context) { EnterAnchor(context); }
public GrammarTypeAnchor(GrammarParser.GrammarTypeContext context, ITrackingSpan span) : base(GrammarParser.RULE_grammarType, span) { if (context.LEXER() != null) { grammarType = GrammarParser.LEXER; } else if (context.PARSER() != null) { grammarType = GrammarParser.PARSER; } else { grammarType = GrammarParser.COMBINED; } }
public override void ExitRuleSpec(GrammarParser.RuleSpecContext context) { ExitAnchor(context, GrammarParser.RULE_ruleSpec); }
public override void EnterRuleSpec(GrammarParser.RuleSpecContext context) { EnterAnchor(context); }
public override void ExitGrammarType(GrammarParser.GrammarTypeContext context) { ExitAnchor(context, GrammarParser.RULE_grammarType); }