jInfer

cz.cuni.mff.ksi.jinfer.base.regexp
Class Regexp<T>

java.lang.Object
  extended by cz.cuni.mff.ksi.jinfer.base.regexp.Regexp<T>
Type Parameters:
T -

public class Regexp<T>
extends Object

Class representing a regular expression of arbitrary type.

Permutation is just syntactic sugar. Each regexp has RegexpInterval associated with it.


Constructor Summary
Regexp(T content, List<Regexp<T>> children, RegexpType type, RegexpInterval interval)
          Creates immutable regexp.
 
Method Summary
 void addChild(Regexp<T> child)
          Shorthand for getChildren().add().
 void branch(int position)
          Converts the i-th position of this concatenation to alternation and inserts the rest as the one and only of its children.
static
<T> Regexp<T>
getAlternation(List<Regexp<T>> children)
          Get immutable alternation regexp with interval set to {1, 1}.
static
<T> Regexp<T>
getAlternation(List<Regexp<T>> children, RegexpInterval interval)
          Get immutable alternation regexp.
 Regexp<T> getChild(int i)
          Shorthand for getChildren().get().
 List<Regexp<T>> getChildren()
           
static
<T> Regexp<T>
getConcatenation(List<Regexp<T>> children)
          Get immutable concatenation regexp with interval set to {1, 1}.
static
<T> Regexp<T>
getConcatenation(List<Regexp<T>> children, RegexpInterval interval)
          Get immutable concatenation regexp.
 T getContent()
           
 Regexp<T> getEnd(int from)
          Returns a new concatenation containing the suffix of the specified concatenation, that is children from index specified by parameter from up to the end.
 RegexpInterval getInterval()
           
static
<T> Regexp<T>
getLambda()
          Get immutable lambda regexp.
static
<T> Regexp<T>
getMutable()
          Get empty (members not set) regexp which is mutable.
static
<T> Regexp<T>
getPermutation(List<Regexp<T>> children)
          Get immutable permutation regexp with interval set to {1, 1}.
static
<T> Regexp<T>
getPermutation(List<Regexp<T>> children, RegexpInterval interval)
          Get immutable permutation regexp.
static
<T> Regexp<T>
getToken(T content)
          Get immutable token regexp with interval set to {1, 1}.
static
<T> Regexp<T>
getToken(T content, RegexpInterval interval)
          Get immutable token regexp.
 List<T> getTokens()
          Returns all tokens contained in this regular expression, inorder from the left to the right.
 RegexpType getType()
           
 boolean isAlternation()
          If it is alternation.
 boolean isConcatenation()
          If it is concatenation type.
 boolean isLambda()
          If it is lambda.
 boolean isPermutation()
          If it is permutation.
 boolean isToken()
          If it is token type.
 void setContent(T content)
          Set content of the regexp if it is mutable.
 void setImmutable()
          Lock the regexp to be immutable from now.
 void setInterval(RegexpInterval interval)
          Set interval of regexp when it is mutable, throws exception when regexp is immutable.
 void setType(RegexpType type)
          Set type of regexp when it is mutable, throws exception when regexp is immutable.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Regexp

public Regexp(T content,
              List<Regexp<T>> children,
              RegexpType type,
              RegexpInterval interval)
Creates immutable regexp. This is the default.

Parameters:
content - content of token regexp or null for not-tokens
children - children of concatenations, alternation and permutation regexps
type - type of regexp
interval - interval of regexp
Method Detail

getMutable

public static <T> Regexp<T> getMutable()
Get empty (members not set) regexp which is mutable. This is the only way to create mutable regexp. Proper use is like this: Regexp r = Regexp.getMutable();
r.setType(RegexpType.LAMBDA);
r.setImmutable();cz.cuni.mff.ksi.jinfer.base

or

Regexp r = Regexp.getMutable();
r.setInterval(...);
r.setType(RegexpType.TOKEN);
r.setContent(...)
r.setImmutable();

or

Regexp r = Regexp.getMutable();
r.setInterval(...);
r.setType(RegexpType.CONCATENATION);
r.addChild(...);
r.addChild(...);
r.addChild(...);
r.setImmutable();
Take care to setup all members correctly and lock regexp.

Type Parameters:
T -
Returns:

getLambda

public static <T> Regexp<T> getLambda()
Get immutable lambda regexp.

Type Parameters:
T -
Returns:

getToken

public static <T> Regexp<T> getToken(T content,
                                     RegexpInterval interval)
Get immutable token regexp.

Type Parameters:
T -
Parameters:
content - symbol of regexp
interval - associated interval, e.g. {3,7}
Returns:

getToken

public static <T> Regexp<T> getToken(T content)
Get immutable token regexp with interval set to {1, 1}.

Type Parameters:
T -
Parameters:
content - symbol of regexp
Returns:

getConcatenation

public static <T> Regexp<T> getConcatenation(List<Regexp<T>> children,
                                             RegexpInterval interval)
Get immutable concatenation regexp.

Type Parameters:
T -
Parameters:
children - of this regexp, that are subregexps.
interval - associated interval, e.g. {3,7}
Returns:

getConcatenation

public static <T> Regexp<T> getConcatenation(List<Regexp<T>> children)
Get immutable concatenation regexp with interval set to {1, 1}.

Type Parameters:
T -
Parameters:
children - of this regexp, that are subregexps.
Returns:

getAlternation

public static <T> Regexp<T> getAlternation(List<Regexp<T>> children,
                                           RegexpInterval interval)
Get immutable alternation regexp.

Type Parameters:
T -
Parameters:
children - of this regexp, that are subregexps.
interval - associated interval, e.g. {3,7}
Returns:

getAlternation

public static <T> Regexp<T> getAlternation(List<Regexp<T>> children)
Get immutable alternation regexp with interval set to {1, 1}.

Type Parameters:
T -
Parameters:
children - of this regexp, that are subregexps.
Returns:

getPermutation

public static <T> Regexp<T> getPermutation(List<Regexp<T>> children,
                                           RegexpInterval interval)
Get immutable permutation regexp.

Type Parameters:
T -
Parameters:
children - of this regexp, that are subregexps.
interval - associated interval, e.g. {3,7}
Returns:

getPermutation

public static <T> Regexp<T> getPermutation(List<Regexp<T>> children)
Get immutable permutation regexp with interval set to {1, 1}.

Type Parameters:
T -
Parameters:
children - of this regexp, that are subregexps.
Returns:

setContent

public void setContent(T content)
Set content of the regexp if it is mutable. Throws exception when regexp is immutable.

Parameters:
content -

getContent

public T getContent()
Returns:
content of token regexp or null if regexp is not token

getChildren

public List<Regexp<T>> getChildren()
Returns:
null - when regexp children are null (regexp is token), immutable (unmodifiable) list, when regexp is immutable and not token, and mutable list when regexp is not token and is mutable.

setType

public void setType(RegexpType type)
Set type of regexp when it is mutable, throws exception when regexp is immutable.

Parameters:
type - desired type

getType

public RegexpType getType()
Returns:
type of regexp

setInterval

public void setInterval(RegexpInterval interval)
Set interval of regexp when it is mutable, throws exception when regexp is immutable.

Parameters:
interval - desired interval

getInterval

public RegexpInterval getInterval()
Returns:
interval associated with regexp.

setImmutable

public void setImmutable()
Lock the regexp to be immutable from now. Throws exception if you are programming badly and tries to lock it twice.


getChild

public Regexp<T> getChild(int i)
Shorthand for getChildren().get().

Parameters:
i - Which child to fetch.
Returns:
I-th child.

addChild

public void addChild(Regexp<T> child)
Shorthand for getChildren().add(). Works only when regexp is mutable, throws exception otherwise.

Parameters:
child - Which child to add.

getTokens

public List<T> getTokens()
Returns all tokens contained in this regular expression, inorder from the left to the right.

Returns:
All tokens of this regexp.

isToken

public boolean isToken()
If it is token type.

Returns:
true iff type of this regexp equals RegexpType.TOKEN

isConcatenation

public boolean isConcatenation()
If it is concatenation type.

Returns:
true iff type of this regexp equals RegexpType.CONCATENATION

isAlternation

public boolean isAlternation()
If it is alternation.

Returns:
true iff type of this regexp equals RegexpType.ALTERNATION

isPermutation

public boolean isPermutation()
If it is permutation.

Returns:
true iff type of this regexp equals RegexpType.PERMUTATION

isLambda

public boolean isLambda()
If it is lambda.

Returns:
true iff type of this regexp equals RegexpType.LAMBDA

branch

public void branch(int position)

Converts the i-th position of this concatenation to alternation and inserts the rest as the one and only of its children.

Example: consider concatenation :
(A B C D)
after applying branch(2) it will look like this:
(A B (C D | ))

If i-th position is already an alternation, nothing happens.

Note that elements of the concatenation are indexed from 0.

Parameters:
position - Where to branch.

getEnd

public Regexp<T> getEnd(int from)
Returns a new concatenation containing the suffix of the specified concatenation, that is children from index specified by parameter from up to the end.

Parameters:
from - Index from which to start taking the suffix.
Returns:
New concatenation containing the suffix.

toString

public String toString()
Overrides:
toString in class Object

jInfer

Generated on Fri Dec 9 00:01:25 CET 2011