Antlr4OboParserTestBase.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:ontolib 作者:
/**
 * Build and return {@link Antlr4OboParser} for a given <code>text</code>.
 *
 * @param text String with the text to parse.
 * @param mode Name of the mode to use.
 * @return {@link Antlr4OboParser}, readily setup for parsing the OBO file.
 */
protected Antlr4OboParser buildParser(String text, String mode) {
  final CodePointCharStream inputStream = CharStreams.fromString(text);
  final OboLexer l = new OboLexer(inputStream);

  for (int i = 0; i < l.getModeNames().length; ++i) {
    if (mode.equals(l.getModeNames()[i])) {
      l.mode(i);
    }
  }

  Antlr4OboParser p = new Antlr4OboParser(new CommonTokenStream(l));

  p.addErrorListener(new BaseErrorListener() {
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
        int charPositionInLine, String msg, RecognitionException e) {
      throw new IllegalStateException("failed to parse at line " + line + " due to " + msg, e);
    }
  });

  p.addErrorListener(new DiagnosticErrorListener());

  p.addParseListener(outerListener);

  return p;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号