Exemplo n.º 1
0
  /**
   * Given a token type, get a meaningful name for it such as the ID or string literal. If this is a
   * lexer and the ttype is in the char vocabulary, compute an ANTLR-valid (possibly escaped) char
   * literal.
   */
  public String getTokenDisplayName(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 == Token.INVALID_TYPE) {
      return INVALID_TOKEN_NAME;
    }

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

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

    return String.valueOf(ttype);
  }
Exemplo n.º 2
0
 /**
  * Given a token type, get a meaningful name for it such as the ID or string literal. If this is a
  * lexer and the ttype is in the char vocabulary, compute an ANTLR-valid (possibly escaped) char
  * literal.
  */
 public String getTokenDisplayName(int ttype) {
   String tokenName = null;
   // 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);
   } else if (ttype == Token.EOF) {
     tokenName = "EOF";
   } else {
     if (ttype < typeToTokenList.size()) {
       tokenName = typeToTokenList.get(ttype);
       if (tokenName != null
           && tokenName.startsWith(AUTO_GENERATED_TOKEN_NAME_PREFIX)
           && ttype < typeToStringLiteralList.size()
           && typeToStringLiteralList.get(ttype) != null) {
         tokenName = typeToStringLiteralList.get(ttype);
       }
     } else {
       tokenName = String.valueOf(ttype);
     }
   }
   //		tool.log("grammar", "getTokenDisplayName ttype="+ttype+", name="+tokenName);
   return tokenName;
 }