InmemantlrGrammar.java 文件源码

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

项目:inmemantlr 作者:
/**
 * We want to touch as little ANTR code as possible. We overload this
 * function to pretend the existence of the token vocab parser
 */
@Override
public void importTokensFromTokensFile() {
    if (!tokenVocab.isEmpty()) {
        MemoryTokenVocabParser vparser = new MemoryTokenVocabParser(this, tokenVocab);
        Map<String, Integer> tokens = vparser.load();

        int ret;
        for (String t : tokens.keySet()) {
            if (t.charAt(0) == '\'') {
                ret = defineStringLiteral(t, tokens.get(t));
                if (ret == Token.INVALID_TYPE)
                    throw new IllegalArgumentException("Token must not be INVAlID_TYPE");
            } else {
                ret = defineTokenName(t, tokens.get(t));
                if (ret == Token.INVALID_TYPE)
                    throw new IllegalArgumentException("Token must not be INVAlID_TYPE");
            }
            LOGGER.debug("token {} {}", t, tokens.get(t));
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号