Class TokenCharacterSet


  • public class TokenCharacterSet
    extends Token
    A token character set.

    Token character sets allow you to specify that set(s) of characters should be included or excluded. A set that includes "A-F0-9" matches hexidecimal numbers, for example. A character set that excludes "~" matches all of Unicode except the "~" character.

    • Method Detail

      • inclusion

        public static TokenCharacterSet inclusion​(CharacterSet range)
        Create a character set terminal that matches any character in the specified range.
        Parameters:
        range - The character set.
        Returns:
        A TerminalCharacterSet that matches any character in that range.
      • inclusion

        public static TokenCharacterSet inclusion​(CharacterSet range,
                                                  java.util.Collection<ParserAttribute> attributes)
        Create a character set terminal that matches any character in the specified range (with attributes)
        Parameters:
        range - The character set.
        attributes - The attributes.
        Returns:
        A TerminalCharacterSet that matches any character in that range.
      • inclusion

        public static TokenCharacterSet inclusion​(java.util.List<CharacterSet> range)
        Create a character set terminal that matches any character in the specified ranges.
        Parameters:
        range - A list of character set ranges.
        Returns:
        A TerminalCharacterSet that matches any character in any of those ranges.
      • inclusion

        public static TokenCharacterSet inclusion​(java.util.List<CharacterSet> range,
                                                  java.util.Collection<ParserAttribute> attributes)
        Create a character set terminal that matches any character in the specified ranges (with attributes).
        Parameters:
        range - A list of character set ranges.
        attributes - The attributes.
        Returns:
        A TerminalCharacterSet that matches any character in any of those ranges.
      • inclusion

        public static TokenCharacterSet inclusion​(CharacterSet... ranges)
        Create a character set terminal that matches any character in the specified ranges.
        Parameters:
        ranges - A list of character set ranges.
        Returns:
        A TerminalCharacterSet that matches any character in any of those ranges.
      • exclusion

        public static TokenCharacterSet exclusion​(CharacterSet range)
        Create a character set terminal that matches any character not in the specified range.
        Parameters:
        range - The character set.
        Returns:
        A TerminalCharacterSet that matches any character not in that range.
      • exclusion

        public static TokenCharacterSet exclusion​(CharacterSet range,
                                                  java.util.Collection<ParserAttribute> attributes)
        Create a character set terminal that matches any character not in the specified range (with attributes).
        Parameters:
        range - The character set.
        attributes - The attributes.
        Returns:
        A TerminalCharacterSet that matches any character not in that range.
      • exclusion

        public static TokenCharacterSet exclusion​(java.util.List<CharacterSet> range)
        Create a character set terminal that matches any character not in any of the specified ranges.
        Parameters:
        range - A list of character set ranges.
        Returns:
        A TerminalCharacterSet that matches any character not in any of those ranges.
      • exclusion

        public static TokenCharacterSet exclusion​(java.util.List<CharacterSet> range,
                                                  java.util.Collection<ParserAttribute> attributes)
        Create a character set terminal that matches any character not in any of the specified ranges (with attributes).
        Parameters:
        range - A list of character set ranges.
        attributes - The attributes.
        Returns:
        A TerminalCharacterSet that matches any character not in any of those ranges.
      • exclusion

        public static TokenCharacterSet exclusion​(CharacterSet... ranges)
        Create a character set terminal that matches any character not in the specified ranges.
        Parameters:
        ranges - A list of character set ranges.
        Returns:
        A TerminalCharacterSet that matches any character in any of those ranges.
      • isInclusion

        public boolean isInclusion()
        Is this an inclusion characater set?

        If not, it's an exclusion.

        Returns:
        true if this is an inclusion character set
      • getCharacterSets

        public java.util.List<CharacterSet> getCharacterSets()
        What are the character sets?
        Returns:
        the character sets
      • matches

        public boolean matches​(Token token)
        Returns true if and only if the specified token matches.

        Tests that the given character token matches the character set terminal. For inclusions, that it is a character in one of the specified ranges. For exclusions, that it is a character not present in any range.

        This method always returns false if the token specified is not a single character.

        Specified by:
        matches in class Token
        Parameters:
        token - The token character.
        Returns:
        True iff the token matches.
      • equals

        public boolean equals​(java.lang.Object obj)
        Are two token character sets "equal"?

        This method checks to see if they contain the same ranges. That's not the only possible definition of equality. For example, a set with the single range ['0'-'9'] is in some sense "the same" as a set with the ranges ['0'-'5'] and ['6'-'9'], but they would not be equal by this method.

        It's temping to write an equality function in broader terms, but to do it correctly, it would be necessary to be able to compare Unicode classes to other kinds of ranges and that seems impractical.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to test
        Returns:
        true if they are equal
      • getValue

        public java.lang.String getValue()
        Description copied from class: Token
        What is this token?
        Specified by:
        getValue in class Token
        Returns:
        the token string
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object