All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Java.target.apidocs.org.antlr.v4.runtime.VocabularyImpl.html Maven / Gradle / Ivy

There is a newer version: 4.13.1.5
Show newest version






VocabularyImpl (ANTLR 4 Runtime (Optimized) 4.13.1.3 API)












org.antlr.v4.runtime

Class VocabularyImpl

  • All Implemented Interfaces:
    Vocabulary


    public class VocabularyImpl
    extends Object
    implements Vocabulary
    This class provides a default implementation of the Vocabulary interface.
    Author:
    Sam Harwell
    • Constructor Detail

      • VocabularyImpl

        public VocabularyImpl(@Nullable
                              String[] literalNames,
                              @Nullable
                              String[] symbolicNames)
        Constructs a new instance of VocabularyImpl from the specified literal and symbolic token names.
        Parameters:
        literalNames - The literal names assigned to tokens, or null if no literal names are assigned.
        symbolicNames - The symbolic names assigned to tokens, or null if no symbolic names are assigned.
        See Also:
        getLiteralName(int), getSymbolicName(int)
      • VocabularyImpl

        public VocabularyImpl(@Nullable
                              String[] literalNames,
                              @Nullable
                              String[] symbolicNames,
                              @Nullable
                              String[] displayNames)
        Constructs a new instance of VocabularyImpl from the specified literal, symbolic, and display token names.
        Parameters:
        literalNames - The literal names assigned to tokens, or null if no literal names are assigned.
        symbolicNames - The symbolic names assigned to tokens, or null if no symbolic names are assigned.
        displayNames - The display names assigned to tokens, or null to use the values in literalNames and symbolicNames as the source of display names, as described in getDisplayName(int).
        See Also:
        getLiteralName(int), getSymbolicName(int), getDisplayName(int)
    • Method Detail

      • fromTokenNames

        public static Vocabulary fromTokenNames(@Nullable
                                                String[] tokenNames)
        Returns a VocabularyImpl 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 null for getLiteralName(int) and getSymbolicName(int), and the value from tokenNames for the display names.

        Parameters:
        tokenNames - The token names, or null if no token names are available.
        Returns:
        A Vocabulary instance which uses tokenNames for the display names of tokens.
      • getMaxTokenType

        public int getMaxTokenType()
        Description copied from interface: Vocabulary
        Returns the highest token type value. It can be used to iterate from zero to that number, inclusively, thus querying all stored entries.
        Specified by:
        getMaxTokenType in interface Vocabulary
        Returns:
        the highest token type value
      • getLiteralName

        @Nullable
        public String getLiteralName(int tokenType)
        Description copied from interface: Vocabulary
        Gets the string literal associated with a token type. The string returned by this method, when not null, can be used unaltered in a parser grammar to represent this token type.

        The following table shows examples of lexer rules and the literal names assigned to the corresponding token types.

        Rule Literal Name Java String Literal
        THIS : 'this'; 'this' "'this'"
        SQUOTE : '\''; '\'' "'\\''"
        ID : [A-Z]+; n/a null
        Specified by:
        getLiteralName in interface Vocabulary
        Parameters:
        tokenType - The token type.
        Returns:
        The string literal associated with the specified token type, or null if no string literal is associated with the type.
      • getSymbolicName

        @Nullable
        public String getSymbolicName(int tokenType)
        Description copied from interface: Vocabulary
        Gets the symbolic name associated with a token type. The string returned by this method, when not null, can be used unaltered in a parser grammar to represent this token type.

        This method supports token types defined by any of the following methods:

        • Tokens created by lexer rules.
        • Tokens defined in a tokens{} block in a lexer or parser grammar.
        • The implicitly defined EOF token, which has the token type Token.EOF.

        The following table shows examples of lexer rules and the literal names assigned to the corresponding token types.

        Rule Symbolic Name
        THIS : 'this'; THIS
        SQUOTE : '\''; SQUOTE
        ID : [A-Z]+; ID
        Specified by:
        getSymbolicName in interface Vocabulary
        Parameters:
        tokenType - The token type.
        Returns:
        The symbolic name associated with the specified token type, or null if no symbolic name is associated with the type.
      • getDisplayName

        @NotNull
        public String getDisplayName(int tokenType)
        Description copied from interface: Vocabulary
        Gets the display name of a token type.

        ANTLR provides a default implementation of this method, but applications are free to override the behavior in any manner which makes sense for the application. The default implementation returns the first result from the following list which produces a non-null result.

        1. The result of Vocabulary.getLiteralName(int)
        2. The result of Vocabulary.getSymbolicName(int)
        3. The result of Integer.toString(int, int)
        Specified by:
        getDisplayName in interface Vocabulary
        Parameters:
        tokenType - The token type.
        Returns:
        The display name of the token type, for use in error reporting or other user-visible messages which reference specific token types.

Copyright © 1992–2023 Daniel Sun. All rights reserved.





© 2015 - 2024 Weber Informatics LLC | Privacy Policy