Java 类org.antlr.v4.runtime.ConsoleErrorListener 实例源码

项目:DataFrame    文件:PredicateCompiler.java   
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());
}
项目:TSS    文件:Simulator.java   
private static CommandResult executeCommand(String command, Transputer[] transputers, PrintWriter output, PrintWriter errOutput) {
    DebuggerCommandLexer commandLexer = new DebuggerCommandLexer(new ANTLRInputStream(command));
    commandLexer.removeErrorListener(ConsoleErrorListener.INSTANCE);

    CommonTokenStream tokenStream = new CommonTokenStream(commandLexer);
    ErrorListener errorListener = new ErrorListener();
    DebuggerCommandParser commandParser = new DebuggerCommandParser(tokenStream);
    commandParser.addErrorListener(errorListener);
    commandParser.removeErrorListener(ConsoleErrorListener.INSTANCE);

    ParseTree commandTree = commandParser.command();

    if (errorListener.errors != 0) {
        output.println("Command not recognised.");
        output.flush();
        return CommandResult.NOT_RECOGNISED;
    }

    CommandExecutor executor = new CommandExecutor(transputers, output, errOutput);
    return executor.visit(commandTree);
}
项目:org.ops4j.ramler    文件:AbstractGeneratorTest.java   
private TypescriptParser buildParser(File source) throws IOException {
    CharStream inputCharStream = CharStreams.fromPath(source.toPath());
    TokenSource tokenSource = new TypescriptLexer(inputCharStream);
    TokenStream inputTokenStream = new CommonTokenStream(tokenSource);
    TypescriptParser parser = new TypescriptParser(inputTokenStream);

    // make parser throw exception on first error
    parser.setErrorHandler(new BailErrorStrategy());

    // print detailed error messages to System.err
    parser.addErrorListener(new ConsoleErrorListener());

    return parser;
}
项目:jmespath-java    文件:AntlrHelper.java   
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;
}
项目:cd2t-100    文件:CodeFactory.java   
/**
 * Orchestrates the lexing and parsing of the {@code programText} with respect
 * to the specified configuration (parameters). The data extracted from
 * the process is returned afterwards. The returned object also includes
 * the perceived input errors.
 *
 * @param registerNameSet A set containing the usable register names.
 * @param portNameSet A set containing the usable existing port names.
 * @param programText The source code to be processed.
 *
 * @return the instructions, labels, rules and exceptions extracted from
 *         the {@code programText} bundled up
 */
public static CodeElementSet createCodeElementSet(Set<String> registerNameSet,
                                                  Set<String> portNameSet,
                                                  String programText) {
  String sanitized = sanitizeText(programText);

  AsmLexer asmLexer = new AsmLexer(new ANTLRInputStream(sanitized));

  AsmParser asmParser = new AsmParser(new CommonTokenStream(asmLexer));

  AsmListenerImpl asmListener =
    new AsmListenerImpl(registerNameSet, portNameSet);

  AsmErrorListener asmErrorListener =
    new AsmErrorListener();

  /*
   *  Remove the default error listener which prints messages to STDERR.
   */
  asmLexer.removeErrorListener(ConsoleErrorListener.INSTANCE);
  asmParser.removeErrorListener(ConsoleErrorListener.INSTANCE);

  asmLexer.addErrorListener(asmErrorListener);
  asmParser.addErrorListener(asmErrorListener);

  asmParser.addParseListener(asmListener);

  logger.debug("Creating code element set...");

  asmParser.program();

  return CodeElementSet.fromListeners(asmListener, asmErrorListener);
}
项目:teavm-flavour    文件:Parser.java   
public ObjectExpr parseObject(String text) {
    diagnostics.clear();
    try (Reader reader = new StringReader(text)) {
        ExprLexer lexer = new ExprLexer(new ANTLRInputStream(reader));
        lexer.removeErrorListener(ConsoleErrorListener.INSTANCE);
        lexer.addErrorListener(errorListener);
        ExprParser exprParser = new ExprParser(new CommonTokenStream(lexer));
        exprParser.removeErrorListener(ConsoleErrorListener.INSTANCE);
        exprParser.addErrorListener(errorListener);
        return exprParser.object().accept(objectVisitor);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:teavm-flavour    文件:Parser.java   
public Expr parse(String text) {
    diagnostics.clear();
    try (Reader reader = new StringReader(text)) {
        ExprLexer lexer = new ExprLexer(new ANTLRInputStream(reader));
        lexer.removeErrorListener(ConsoleErrorListener.INSTANCE);
        lexer.addErrorListener(errorListener);
        ExprParser exprParser = new ExprParser(new CommonTokenStream(lexer));
        exprParser.removeErrorListener(ConsoleErrorListener.INSTANCE);
        exprParser.addErrorListener(errorListener);
        return exprParser.lambda().accept(exprVisitor);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:hands-on-neo4j-devoxx-fr-2017    文件:CypherStatementValidator.java   
private void listenToParserErrors(CypherErrorStatefulListener listener, CypherParser parser) {
    parser.removeErrorListener(ConsoleErrorListener.INSTANCE);
    parser.addErrorListener(listener);
}
项目:jmespath-java    文件:AntlrHelper.java   
private static JmesPathLexer createLexer(String input, ANTLRErrorListener errorListener) {
  JmesPathLexer lexer = new JmesPathLexer(new ANTLRInputStream(input));
  lexer.removeErrorListener(ConsoleErrorListener.INSTANCE);
  lexer.addErrorListener(errorListener);
  return lexer;
}