Grammar.java 文件源码

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

项目:codebuff 作者:
/**
 * Gets the name by which a token can be referenced in the generated code.
 * For tokens defined in a {@code tokens{}} block or via a lexer rule, this
 * is the declared name of the token. For token types generated by the use
 * of a string literal within a parser rule of a combined grammar, this is
 * the automatically generated token type which includes the
 * {@link #AUTO_GENERATED_TOKEN_NAME_PREFIX} prefix. For types which are not
 * associated with a defined token, this method returns
 * {@link #INVALID_TOKEN_NAME}.
 *
 * @param ttype The token type.
 * @return The name of the token with the specified type.
 */

public String getTokenName(int ttype) {
    // inside any target's char range and is lexer grammar?
    if ( isLexer() &&
         ttype >= Lexer.MIN_CHAR_VALUE && ttype <= Lexer.MAX_CHAR_VALUE )
    {
        return CharSupport.getANTLRCharLiteralForChar(ttype);
    }

    if ( ttype==Token.EOF ) {
        return "EOF";
    }

    if (ttype >= 0 && ttype < typeToTokenList.size() && typeToTokenList.get(ttype) != null) {
        return typeToTokenList.get(ttype);
    }

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


问题


面经


文章

微信
公众号

扫码关注公众号