Antlr4.Tool.Grammar.GetTokenName C# (CSharp) Méthode

GetTokenName() private méthode

private GetTokenName ( int ttype ) : string
ttype int
Résultat string
        public virtual string GetTokenName(int ttype)
        {
            // inside any target's char range and is lexer grammar?
            if (IsLexer() &&
                 ttype >= Lexer.MinCharValue && ttype <= Lexer.MaxCharValue)
            {
                return CharSupport.GetANTLRCharLiteralForChar(ttype);
            }

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

            if (ttype >= 0 && ttype < typeToTokenList.Count && typeToTokenList[ttype] != null)
            {
                return typeToTokenList[ttype];
            }

            return INVALID_TOKEN_NAME;
        }

Usage Example

Exemple #1
0
        /** Get a meaningful name for a token type useful during code generation.
         *  Literals without associated names are converted to the string equivalent
         *  of their integer values. Used to generate x==ID and x==34 type comparisons
         *  etc...  Essentially we are looking for the most obvious way to refer
         *  to a token type in the generated code.
         */
        public virtual string GetTokenTypeAsTargetLabel(Grammar g, int ttype)
        {
            string name = g.GetTokenName(ttype);
            // If name is not valid, return the token type instead
            if (Grammar.INVALID_TOKEN_NAME.Equals(name))
            {
                return ttype.ToString();
            }

            return name;
        }