Antlr4.Runtime.Vocabulary.FromTokenNames C# (CSharp) Method

FromTokenNames() public static method

Returns a Vocabulary instance from the specified set of token names. This method acts as a compatibility layer for the single tokenNames array generated by previous releases of ANTLR.

The resulting vocabulary instance returns for GetLiteralName(int) and GetSymbolicName(int) , and the value from tokenNames for the display names.

public static FromTokenNames ( string tokenNames ) : IVocabulary
tokenNames string /// The token names, or /// /// if no token names are /// available. ///
return IVocabulary
        public static IVocabulary FromTokenNames(string[] tokenNames)
        {
            if (tokenNames == null || tokenNames.Length == 0)
            {
                return EmptyVocabulary;
            }
            string[] literalNames = Arrays.CopyOf(tokenNames, tokenNames.Length);
            string[] symbolicNames = Arrays.CopyOf(tokenNames, tokenNames.Length);
            for (int i = 0; i < tokenNames.Length; i++)
            {
                string tokenName = tokenNames[i];
                if (tokenName == null)
                {
                    continue;
                }
                if (tokenName.Length > 0)
                {
                    char firstChar = tokenName[0];
                    if (firstChar == '\'')
                    {
                        symbolicNames[i] = null;
                        continue;
                    }
                    else
                    {
                        if (System.Char.IsUpper(firstChar))
                        {
                            literalNames[i] = null;
                            continue;
                        }
                    }
                }
                // wasn't a literal or symbolic name
                literalNames[i] = null;
                symbolicNames[i] = null;
            }
            return new Vocabulary(literalNames, symbolicNames, tokenNames);
        }