public class TokenCharacterSet extends Token
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.
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Are two token character sets "equal"?
|
static TokenCharacterSet |
exclusion(CharacterSet... ranges)
Create a character set terminal that matches any character not in the specified ranges.
|
static TokenCharacterSet |
exclusion(CharacterSet range)
Create a character set terminal that matches any character not in the specified range.
|
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).
|
static TokenCharacterSet |
exclusion(java.util.List<CharacterSet> range)
Create a character set terminal that matches any character not in any of the specified ranges.
|
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).
|
java.util.List<CharacterSet> |
getCharacterSets()
What are the character sets?
|
java.lang.String |
getValue()
What is this token?
|
static TokenCharacterSet |
inclusion(CharacterSet... ranges)
Create a character set terminal that matches any character in the specified ranges.
|
static TokenCharacterSet |
inclusion(CharacterSet range)
Create a character set terminal that matches any character in the specified range.
|
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)
|
static TokenCharacterSet |
inclusion(java.util.List<CharacterSet> range)
Create a character set terminal that matches any character in the specified ranges.
|
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).
|
boolean |
isInclusion()
Is this an inclusion characater set?
|
boolean |
matches(Token token)
Returns true if and only if the specified token matches.
|
java.lang.String |
toString() |
addAttribute, addAttributes, getAttribute, getAttributes, getAttributesMap, getAttributeValue, hasAttribute
public static TokenCharacterSet inclusion(CharacterSet range)
range
- The character set.public static TokenCharacterSet inclusion(CharacterSet range, java.util.Collection<ParserAttribute> attributes)
range
- The character set.attributes
- The attributes.public static TokenCharacterSet inclusion(java.util.List<CharacterSet> range)
range
- A list of character set ranges.public static TokenCharacterSet inclusion(java.util.List<CharacterSet> range, java.util.Collection<ParserAttribute> attributes)
range
- A list of character set ranges.attributes
- The attributes.public static TokenCharacterSet inclusion(CharacterSet... ranges)
ranges
- A list of character set ranges.public static TokenCharacterSet exclusion(CharacterSet range)
range
- The character set.public static TokenCharacterSet exclusion(CharacterSet range, java.util.Collection<ParserAttribute> attributes)
range
- The character set.attributes
- The attributes.public static TokenCharacterSet exclusion(java.util.List<CharacterSet> range)
range
- A list of character set ranges.public static TokenCharacterSet exclusion(java.util.List<CharacterSet> range, java.util.Collection<ParserAttribute> attributes)
range
- A list of character set ranges.attributes
- The attributes.public static TokenCharacterSet exclusion(CharacterSet... ranges)
ranges
- A list of character set ranges.public boolean isInclusion()
If not, it's an exclusion.
public java.util.List<CharacterSet> getCharacterSets()
public boolean matches(Token token)
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.
public boolean equals(java.lang.Object obj)
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.
equals
in class java.lang.Object
obj
- the object to testpublic java.lang.String getValue()
Token
public java.lang.String toString()
toString
in class java.lang.Object