protected override IParseTree GetParseTree(CommonTokenStream tokens, BaseErrorListener errorListener) { var parser = new AendringDefinitionGrammarParser(tokens); parser.AddErrorListener(errorListener); return(parser.aendringDefinition()); }
protected override IParseTree GetParseTree(CommonTokenStream tokens, BaseErrorListener errorListener) { var parser = new Dk.Itu.Rlh.MasterProject.Grammar.ParagrafIndledningParser(tokens); parser.AddErrorListener(errorListener); var result = parser.paragrafIndledning(); return(result); }
private T Parse <T>(string sourceCode, BaseErrorListener errorListener, Func <injectionParser, T> parseFunc) { var inputStream = new AntlrInputStream(sourceCode); var lexer = new injectionLexer(inputStream); var tokenStream = new CommonTokenStream(lexer); var parser = new injectionParser(tokenStream); if (errorListener != null) { parser.AddErrorListener(errorListener); } return(parseFunc(parser)); }
private static Map ReadStream(ICharStream charStream, BaseErrorListener errorListener) { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); MapLexer lexer = new MapLexer(charStream); MapParser parser = new MapParser(new CommonTokenStream(lexer)); parser.RemoveErrorListeners(); if (errorListener != null) { parser.AddErrorListener(errorListener); } return(parser.map().value); }
public static List <Shader> Read(string filepath, BaseErrorListener errorListener = null) { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); ICharStream charStream = new AntlrFileStream(filepath); ShaderLexer lexer = new ShaderLexer(charStream); ShaderParser parser = new ShaderParser(new CommonTokenStream(lexer)); parser.RemoveErrorListeners(); if (errorListener != null) { parser.AddErrorListener(errorListener); } return(parser.shaderList().value); }
public static string Compile(string input, BaseErrorListener errorListener) { AntlrInputStream stream = new AntlrInputStream(input); HorseshoeLexer lexer = new HorseshoeLexer(stream); CommonTokenStream tokenStream = new CommonTokenStream(lexer); HorseshoeParser parser = new HorseshoeParser(tokenStream); if (errorListener != null) { parser.RemoveErrorListeners(); parser.AddErrorListener(errorListener); } var context = parser.document(); HorseshoeTranslationListener listener = new HorseshoeTranslationListener(); ParseTreeWalker walker = new ParseTreeWalker(); walker.Walk(listener, context); return(listener.Result); }
public IParseTree Parse(string moduleName, CommonTokenStream moduleTokens, IParseTreeListener[] listeners, BaseErrorListener errorListener, out ITokenStream outStream) { moduleTokens.Reset(); var parser = new VBAParser(moduleTokens); parser.AddErrorListener(errorListener); ParserRuleContext tree; try { parser.Interpreter.PredictionMode = PredictionMode.Sll; tree = parser.startRule(); } catch (Exception ex) { Logger.Warn(ex, "SLL mode failed in module {0}. Retrying using LL.", moduleName); moduleTokens.Reset(); parser.Reset(); parser.Interpreter.PredictionMode = PredictionMode.Ll; tree = parser.startRule(); } foreach (var listener in listeners) { ParseTreeWalker.Default.Walk(listener, tree); } outStream = moduleTokens; return(tree); }
public VBAConditionalCompilationParser.CompilationUnitContext Parse(string moduleName, CommonTokenStream unprocessedTokenStream, BaseErrorListener errorListener) { unprocessedTokenStream.Reset(); var parser = new VBAConditionalCompilationParser(unprocessedTokenStream); parser.AddErrorListener(errorListener); VBAConditionalCompilationParser.CompilationUnitContext tree; try { parser.Interpreter.PredictionMode = PredictionMode.Sll; tree = parser.compilationUnit(); } catch (ParsePassSyntaxErrorException syntaxErrorException) { var parsePassText = syntaxErrorException.ParsePass == ParsePass.CodePanePass ? "code pane" : "exported"; Logger.Warn($"SLL mode failed while preprocessing the {parsePassText} version of module {moduleName} at symbol {syntaxErrorException.OffendingSymbol.Text} at L{syntaxErrorException.LineNumber}C{syntaxErrorException.Position}. Retrying using LL."); Logger.Debug(syntaxErrorException, "SLL mode exception"); unprocessedTokenStream.Reset(); parser.Reset(); parser.Interpreter.PredictionMode = PredictionMode.Ll; tree = parser.compilationUnit(); } catch (Exception exception) { Logger.Warn($"SLL mode failed while prprocessing module {moduleName}. Retrying using LL."); Logger.Debug(exception, "SLL mode exception"); unprocessedTokenStream.Reset(); parser.Reset(); parser.Interpreter.PredictionMode = PredictionMode.Ll; tree = parser.compilationUnit(); } return(tree); }
public (IParseTree tree, ITokenStream tokenStream) Parse(string moduleName, CommonTokenStream moduleTokens, IParseTreeListener[] listeners, BaseErrorListener errorListener) { moduleTokens.Reset(); var parser = new VBAParser(moduleTokens); parser.AddErrorListener(errorListener); ParserRuleContext tree; try { parser.Interpreter.PredictionMode = PredictionMode.Sll; tree = parser.startRule(); } catch (ParsePassSyntaxErrorException syntaxErrorException) { var parsePassText = syntaxErrorException.ParsePass == ParsePass.CodePanePass ? "code pane" : "exported"; Logger.Warn($"SLL mode failed while parsing the {parsePassText} version of module {moduleName} at symbol {syntaxErrorException.OffendingSymbol.Text} at L{syntaxErrorException.LineNumber}C{syntaxErrorException.Position}. Retrying using LL."); Logger.Debug(syntaxErrorException, "SLL mode exception"); moduleTokens.Reset(); parser.Reset(); parser.Interpreter.PredictionMode = PredictionMode.Ll; tree = parser.startRule(); } catch (Exception exception) { Logger.Warn($"SLL mode failed while parsing module {moduleName}. Retrying using LL."); Logger.Debug(exception, "SLL mode exception"); moduleTokens.Reset(); parser.Reset(); parser.Interpreter.PredictionMode = PredictionMode.Ll; tree = parser.startRule(); } foreach (var listener in listeners) { ParseTreeWalker.Default.Walk(listener, tree); } return(tree, moduleTokens); }
public static Map ReadText(string text, BaseErrorListener errorListener = null) { return(ReadStream(new AntlrInputStream(text), errorListener)); }
public static Map ReadFile(string filepath, BaseErrorListener errorListener = null) { return(ReadStream(new AntlrFileStream(filepath), errorListener)); }
protected abstract IParseTree GetParseTree(CommonTokenStream tokens, BaseErrorListener errorListener);
public injectionParser.StatementContext ParseStatement(string sourceCode, BaseErrorListener errorListener = null) => Parse(sourceCode, errorListener, (parser) => parser.statement());
public injectionParser.ExpressionContext ParseExpression(string sourceCode, BaseErrorListener errorListener = null) => Parse(sourceCode, errorListener, (parser) => parser.expression());
public injectionParser.FileContext ParseFile(string sourceCode, BaseErrorListener errorListener = null) => Parse(sourceCode, errorListener, (parser) => parser.file());
public void PreprocessTokenStream(string moduleName, CommonTokenStream tokenStream, BaseErrorListener errorListener, CancellationToken token) { token.ThrowIfCancellationRequested(); var symbolTable = new SymbolTable <string, IValue>(); var tree = _parser.Parse(moduleName, tokenStream, errorListener); token.ThrowIfCancellationRequested(); var stream = tokenStream.TokenSource.InputStream; var evaluator = new VBAPreprocessorVisitor(symbolTable, new VBAPredefinedCompilationConstants(_vbaVersion), stream, tokenStream); var expr = evaluator.Visit(tree); var processedTokens = expr.Evaluate(); //This does the actual preprocessing of the token stream as a side effect. tokenStream.Reset(); }