Class AntlrNameDictionary


  • public class AntlrNameDictionary
    extends Object
    Stores the XPath name of antlr terminals. I found no simple way to give names to punctuation (we could add a lexer rule, but it may conflict with other tokens). So their names are hardcoded here.

    Terminal names start with "T-" in XPath to avoid conflicts with other stuff.

    • Constructor Detail

      • AntlrNameDictionary

        public AntlrNameDictionary​(org.antlr.v4.runtime.Vocabulary vocab,
                                   String[] ruleNames)
    • Method Detail

      • getVocabulary

        public org.antlr.v4.runtime.Vocabulary getVocabulary()
      • nonAlphaNumName

        protected @Nullable String nonAlphaNumName​(String name)
        Override this to customize the XPath name of tokes with no symbolic name and with an image that is non-alphanumeric. Return null to give up. The default just gives some name to common punctuation. Remember that the same token may mean several things in different contexts, so eg using "not" as the name of "!" is too specific.
      • getXPathNameOfToken

        public @NonNull String getXPathNameOfToken​(int tokenType)
        Gets the xpath name of a terminal node with a given Token.getType().
        Throws:
        IllegalArgumentException - If the index is invalid
      • getConstantImageOfToken

        public @Nullable String getConstantImageOfToken​(org.antlr.v4.runtime.Token token)
        Returns the constant image of the given token (a shared string), or null if the token has none. This is a memory optimization to avoid creating a new string for tokens with constant images. Antlr does not do this by itself sadly.
      • getXPathNameOfRule

        public @NonNull String getXPathNameOfRule​(int idx)
        Gets the xpath name of an inner node with a given RuleContext.getRuleIndex().
        Throws:
        IndexOutOfBoundsException - If the index is invalid
      • getMaxRuleIndex

        public int getMaxRuleIndex()
      • getMaxTokenType

        public int getMaxTokenType()