Class TokenCharacterSet
- java.lang.Object
-
- org.nineml.coffeegrinder.util.Decoratable
-
- org.nineml.coffeegrinder.tokens.Token
-
- org.nineml.coffeegrinder.tokens.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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)Are two token character sets "equal"?static TokenCharacterSetexclusion(java.util.List<CharacterSet> range)Create a character set terminal that matches any character not in any of the specified ranges.static TokenCharacterSetexclusion(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).static TokenCharacterSetexclusion(CharacterSet range)Create a character set terminal that matches any character not in the specified range.static TokenCharacterSetexclusion(CharacterSet... ranges)Create a character set terminal that matches any character not in the specified ranges.static TokenCharacterSetexclusion(CharacterSet range, java.util.Collection<ParserAttribute> attributes)Create a character set terminal that matches any character not in the specified range (with attributes).java.util.List<CharacterSet>getCharacterSets()What are the character sets?java.lang.StringgetValue()What is this token?static TokenCharacterSetinclusion(java.util.List<CharacterSet> range)Create a character set terminal that matches any character in the specified ranges.static TokenCharacterSetinclusion(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).static TokenCharacterSetinclusion(CharacterSet range)Create a character set terminal that matches any character in the specified range.static TokenCharacterSetinclusion(CharacterSet... ranges)Create a character set terminal that matches any character in the specified ranges.static TokenCharacterSetinclusion(CharacterSet range, java.util.Collection<ParserAttribute> attributes)Create a character set terminal that matches any character in the specified range (with attributes)booleanisInclusion()Is this an inclusion characater set?booleanmatches(Token token)Returns true if and only if the specified token matches.java.lang.StringtoString()-
Methods inherited from class org.nineml.coffeegrinder.util.Decoratable
addAttribute, addAttributes, getAttribute, getAttributes, getAttributesMap, getAttributeValue, hasAttribute
-
-
-
-
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
falseif the token specified is not a single character.
-
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:
equalsin classjava.lang.Object- Parameters:
obj- the object to test- Returns:
- true if they are equal
-
getValue
public java.lang.String getValue()
Description copied from class:TokenWhat is this token?
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-