xtc.parser
Class CharClass

java.lang.Object
  extended by xtc.tree.Node
      extended by xtc.parser.Element
          extended by xtc.parser.Terminal
              extended by xtc.parser.CharTerminal
                  extended by xtc.parser.CharClass
All Implemented Interfaces:
java.lang.Iterable<java.lang.Object>, Locatable

public class CharClass
extends CharTerminal

A character class terminal.

Note that equals(Object) only determines whether the two character class terminals have the same structure (that is, are both exclusive or non-exclusive and have the same list of character ranges), but does not determine whether the two character class terminals recognize the same characters.

Version:
$Revision: 1.18 $
Author:
Robert Grimm

Nested Class Summary
static class CharClass.Parser
          Parser for a character class specification.
 
Nested classes/interfaces inherited from class xtc.parser.Element
Element.Tag
 
Field Summary
 boolean exclusive
          The flag for whether the character class is exclusive.
 java.util.List<CharRange> ranges
          The list of character ranges.
 
Constructor Summary
CharClass(boolean exclusive, java.util.List<CharRange> ranges)
          Create a new character class.
CharClass(char c)
          Create a new, non-exclusive character class for the specified character.
CharClass(java.util.List<CharRange> ranges)
          Create a new, non-exclusive character class.
CharClass(java.lang.String s)
          Create a new, non-exclusive character class based on the supplied character class specification.
 
Method Summary
 int count()
          Determine the number of characters covered by this character class.
 boolean equals(java.lang.Object o)
           
 int hashCode()
           
 CharClass normalize()
          Normalize this character class.
 boolean overlaps(CharClass klass)
          Determine whether this character class overlaps the specified character class.
 Element.Tag tag()
          Get this element's tag.
 void write(java.lang.Appendable out)
          Write a human readable representation to the specified appendable.
 
Methods inherited from class xtc.tree.Node
add, add, addAll, addAll, addAll, addAll, addAllTo, addNode, contains, get, getBoolean, getBooleanProperty, getGeneric, getList, getLocation, getName, getNode, getProperty, getString, getStringProperty, getTokenText, hasLocation, hasName, hasProperty, hasTraversal, hasVariable, indexOf, isAnnotation, isEmpty, isGeneric, isList, isToken, iterator, lastIndexOf, properties, remove, removeProperty, set, setLocation, setLocation, setProperty, size, strip, toAnnotation, toList, toString, toToken
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

exclusive

public boolean exclusive
The flag for whether the character class is exclusive.


ranges

public java.util.List<CharRange> ranges
The list of character ranges. Note that, strictly speaking, this should be a set of disjoint character ranges. However, it is implemented as a list so that a character class can be printed as it was specified.

Constructor Detail

CharClass

public CharClass(java.util.List<CharRange> ranges)
Create a new, non-exclusive character class.

Parameters:
ranges - The list of character ranges.

CharClass

public CharClass(boolean exclusive,
                 java.util.List<CharRange> ranges)
Create a new character class.

Parameters:
exclusive - The exclusive flag.
ranges - The list of character ranges.

CharClass

public CharClass(char c)
Create a new, non-exclusive character class for the specified character.

Parameters:
c - The character.

CharClass

public CharClass(java.lang.String s)
Create a new, non-exclusive character class based on the supplied character class specification. Note that the character class specification must not include the leading '[' and trailing ']' characters.

Parameters:
s - The character class specification.
Method Detail

tag

public Element.Tag tag()
Description copied from class: Element
Get this element's tag.

Specified by:
tag in class Element
Returns:
The tag.

normalize

public CharClass normalize()
Normalize this character class. This method sorts the list of character ranges by each range's first character and combines adjacent or overlapping ranges. However, it does not turn exclusive character classes into non-exclusive ones (as that conversion might negatively impact recognition performance).

Returns:
This character class.

overlaps

public boolean overlaps(CharClass klass)
Determine whether this character class overlaps the specified character class. Two character classes overlap if they have common characters, though they need not necessarily be the same.

Parameters:
klass - The other character class.
Returns:
true if the two character classes overlap.
Throws:
java.lang.IllegalStateException - Signals that either this or the specified class is exclusive.

count

public int count()
Determine the number of characters covered by this character class. Note that for exclusive character classes this method returns the number of excluded characters.

Returns:
The number of characters for this character class.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

write

public void write(java.lang.Appendable out)
           throws java.io.IOException
Description copied from class: Node
Write a human readable representation to the specified appendable. If this node supports generic traversal, the default implementation writes this node in algebraic term-format; otherwise, it writes the string returned by Object.toString().

Overrides:
write in class Node
Parameters:
out - The appendable.
Throws:
java.io.IOException - Signals an I/O error.


Copyright © 2012. All Rights Reserved.