javatools.parsers
Class RegularExpression

java.lang.Object
  extended by javatools.parsers.RegularExpression
All Implemented Interfaces:
java.lang.Iterable<java.util.List<java.lang.String>>

public class RegularExpression
extends java.lang.Object
implements java.lang.Iterable<java.util.List<java.lang.String>>

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). The class represents a regular expression. You can walk through the regular expression by RegExStates. Each RegExState represents one position in the regular expression. Each RegExState knows which other RegExStates are valid sucessors. The regular expression itself knows which RegExStates are valid exit points. The regular expression can also be inverted.
Example:

         D.p(RegularExpression.compile("a|(b c+)+").describe());
         -->
            1(a) -> []             // From a, we're done
            2(b) -> [3(c)]         // From b, go to c
            3(c) -> [3(c), 2(b)]   // From c, go either to c or to b
            Valid exits: 1(a), 3(c),  
         D.p(RegularExpression.compile("a|(b c+)+").inverse().describe());            
         -->
            4(a) -> []
            6(c) -> [5(b), 6(c)]
            5(b) -> [6(c)]    
            Valid exits: 4(a), 5(b),       
   


Nested Class Summary
static class RegularExpression.RegExState
          Represents one position in a regular expression
 
Field Summary
 java.util.List<RegularExpression.RegExState> entries
          RegExStates with which the RegularExpression starts
 java.util.List<RegularExpression.RegExState> exits
          Valid exit states of this RegularExpression
 java.lang.String original
          Holds the original regex
 
Method Summary
static RegularExpression compile(java.lang.String regex)
          Returns a RegularExpression for a string
 java.lang.String describe()
          returns a nice String description
 java.util.List<RegularExpression.RegExState> getEntries()
          Returns the entry states of this RegularExpression
 java.lang.String getOrginal()
          returns the original
 java.util.List<RegularExpression.RegExState> getStates()
          Returns the set of States (expensive)
 RegularExpression inverse()
          Returns the inverse of this Regular Expression (expensive)
 boolean isExit(RegularExpression.RegExState e)
          Tells whether this RegExState is a valid exit
 PeekIterator<java.util.List<java.lang.String>> iterator()
          Returns an iterator over incarnations of the expression
static void main(java.lang.String[] args)
          Test routine
static RegularExpression parseSimple(java.util.StringTokenizer regex)
          Parses a regex from a StringTokenizer
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

entries

public java.util.List<RegularExpression.RegExState> entries
RegExStates with which the RegularExpression starts


exits

public java.util.List<RegularExpression.RegExState> exits
Valid exit states of this RegularExpression


original

public java.lang.String original
Holds the original regex

Method Detail

getOrginal

public java.lang.String getOrginal()
returns the original


compile

public static RegularExpression compile(java.lang.String regex)
Returns a RegularExpression for a string


toString

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

isExit

public boolean isExit(RegularExpression.RegExState e)
Tells whether this RegExState is a valid exit


getEntries

public java.util.List<RegularExpression.RegExState> getEntries()
Returns the entry states of this RegularExpression


parseSimple

public static RegularExpression parseSimple(java.util.StringTokenizer regex)
Parses a regex from a StringTokenizer


describe

public java.lang.String describe()
returns a nice String description


getStates

public java.util.List<RegularExpression.RegExState> getStates()
Returns the set of States (expensive)


inverse

public RegularExpression inverse()
Returns the inverse of this Regular Expression (expensive)


iterator

public PeekIterator<java.util.List<java.lang.String>> iterator()
Returns an iterator over incarnations of the expression

Specified by:
iterator in interface java.lang.Iterable<java.util.List<java.lang.String>>

main

public static void main(java.lang.String[] args)
Test routine