org.antlr.v4.runtime.ConsoleErrorListener Java Examples
The following examples show how to use
org.antlr.v4.runtime.ConsoleErrorListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tool.java From bookish with MIT License | 6 votes |
public String translateString(Translator trans, String markdown, String startRule) throws Exception { CharStream input = CharStreams.fromString(markdown); BookishLexer lexer = new BookishLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); BookishParser parser = new BookishParser(tokens,null, 0); parser.removeErrorListeners(); parser.addErrorListener(new ConsoleErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { msg = "Parsing author string: "+msg; super.syntaxError(recognizer, offendingSymbol, line, charPositionInLine, msg, e); } }); Method startMethod = BookishParser.class.getMethod(startRule, (Class[])null); ParseTree doctree = (ParseTree)startMethod.invoke(parser, (Object[])null); OutputModelObject omo = trans.visit(doctree); // get single chapter ModelConverter converter = new ModelConverter(trans.templates); ST outputST = converter.walk(omo); return outputST.render(); }
Example #2
Source File: PredicateCompiler.java From DataFrame with MIT License | 6 votes |
public static FilterPredicate compile(String predicateString){ predicateString = predicateString.trim(); if(predicateString.isEmpty()){ return FilterPredicate.empty(); } PredicateCompileErrorListener errorListener = new PredicateCompileErrorListener(predicateString); CharStream stream = CharStreams.fromString(predicateString); PredicateLexer lexer = new PredicateLexer(stream); lexer.removeErrorListener(ConsoleErrorListener.INSTANCE); lexer.addErrorListener(errorListener); CommonTokenStream tokens = new CommonTokenStream(lexer); PredicateParser parser = new PredicateParser(tokens); parser.removeErrorListener(ConsoleErrorListener.INSTANCE); parser.addErrorListener(errorListener); FilterPredicateVisitor filterPredicateVisitor = new FilterPredicateVisitor(); return filterPredicateVisitor.visit(parser.compilationUnit()); }
Example #3
Source File: GrammarService.java From Refactoring-Bot with MIT License | 5 votes |
/** * This method checks if a comment has a valid bot grammar and returns if the * comment is valid or not. * * @param comment * @return valid */ public Boolean checkComment(String comment, GitConfiguration gitConfig) { try { // Check if USERNAME-Keyword equals tagged Botname if (comment.split(" ").length > 1 && !isBotMentionedInComment(comment.split(" ")[0], gitConfig)) { return false; } // Create lexer and disable console logs BotOperationsLexer lexer = new BotOperationsLexer(CharStreams.fromString(comment)); lexer.removeErrorListener(ConsoleErrorListener.INSTANCE); // Create parser and disable console logs CommonTokenStream token = new CommonTokenStream(lexer); BotOperationsParser parser = new BotOperationsParser(token); parser.setBuildParseTree(true); parser.removeErrorListener(ConsoleErrorListener.INSTANCE); // Create parse tree ParseTree tree = parser.botCommand(); ParseTreeWalker walker = new ParseTreeWalker(); // Walk path tree BotOperationsBaseListener listener = new BotOperationsBaseListener(); walker.walk(listener, tree); return true; } catch (Exception e) { return false; } }
Example #4
Source File: AntlrHelper.java From jmespath-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static JmesPathParser createParser(String input, ANTLRErrorListener errorListener) { JmesPathLexer lexer = createLexer(input, errorListener); CommonTokenStream tokens = new CommonTokenStream(lexer); JmesPathParser parser = new JmesPathParser(tokens); parser.removeErrorListener(ConsoleErrorListener.INSTANCE); parser.addErrorListener(errorListener); parser.setBuildParseTree(true); return parser; }
Example #5
Source File: SmartDocumentFilter.java From groovy with Apache License 2.0 | 5 votes |
private GroovyLangLexer createLexer(String text) throws IOException { CharStream charStream = CharStreams.fromReader(new StringReader(text)); GroovyLangLexer lexer = new GroovyLangLexer(charStream); lexer.removeErrorListener(ConsoleErrorListener.INSTANCE); return lexer; }
Example #6
Source File: ParseTreeBasicSolidity.java From smartcheck with GNU General Public License v3.0 | 4 votes |
private Lexer lexerSetup(Lexer lexer) { lexer.removeErrorListener(ConsoleErrorListener.INSTANCE); return lexer; }
Example #7
Source File: ParseTreeBasicSolidity.java From smartcheck with GNU General Public License v3.0 | 4 votes |
private SolidityParser parserSetup(SolidityParser parser) { parser.removeErrorListener(ConsoleErrorListener.INSTANCE); return parser; }
Example #8
Source File: ParseTreeBasicVyper.java From smartcheck with GNU General Public License v3.0 | 4 votes |
private Lexer lexerSetup(Lexer lexer) { lexer.removeErrorListener(ConsoleErrorListener.INSTANCE); return lexer; }
Example #9
Source File: ParseTreeBasicVyper.java From smartcheck with GNU General Public License v3.0 | 4 votes |
private VyperParser parserSetup(VyperParser parser) { parser.removeErrorListener(ConsoleErrorListener.INSTANCE); return parser; }
Example #10
Source File: AntlrHelper.java From jmespath-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static JmesPathLexer createLexer(String input, ANTLRErrorListener errorListener) { JmesPathLexer lexer = new JmesPathLexer(CharStreams.fromString(input)); lexer.removeErrorListener(ConsoleErrorListener.INSTANCE); lexer.addErrorListener(errorListener); return lexer; }