public final class TreeRewriteRule<V> extends Object implements TreeRewriter<V>, Serializable
add($x,0) -> $x
mul($x,1) -> $x
The substitution pattern may only use variables, already defined in
the match pattern. So, the creation of the following rewrite rule s
would lead to an IllegalArgumentException:
add($x,0) -> $y
mul(0,1) -> mul($x,1)
| Constructor and Description |
|---|
TreeRewriteRule(TreePattern<V> left,
TreePattern<V> right)
Create a new rewrite rule from the given matching (
left)
and replacement (right) pattern. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
int |
hashCode() |
TreePattern<V> |
left()
Return the rule matching pattern.
|
<B> TreeRewriteRule<B> |
map(Function<? super V,? extends B> mapper)
Maps
this rewrite rule from type V to type B. |
static TreeRewriteRule<String> |
parse(String rule)
Compiles the string representation of a rewrite rule:
|
static <V> TreeRewriteRule<V> |
parse(String rule,
Function<? super String,? extends V> mapper)
Compiles the string representation of a rewrite rule:
|
int |
rewrite(TreeNode<V> tree,
int limit)
Applies the rewriting to the given (mutable)
tree. |
TreePattern<V> |
right()
Return the replacement pattern of the rule.
|
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitconcat, rewrite, rewrite, rewritepublic TreeRewriteRule(TreePattern<V> left, TreePattern<V> right)
left)
and replacement (right) pattern.left - the matching pattern of the ruleright - the substitution patternNullPointerException - if one of the arguments is nullIllegalArgumentException - if the template pattern uses
variables not defined in the matcher patternpublic TreePattern<V> left()
public TreePattern<V> right()
public <B> TreeRewriteRule<B> map(Function<? super V,? extends B> mapper)
this rewrite rule from type V to type B.B - the target typemapper - the type mapperNullPointerException - if the mapper is nullpublic int rewrite(TreeNode<V> tree, int limit)
TreeRewritertree. The tree
rewrite is done in place. Via the limit parameter, the termination
of the tree-rewrite process can be guaranteed.rewrite in interface TreeRewriter<V>tree - the tree to be rewrittenlimit - the maximal number this rewrite rule is applied to the given
tree. This guarantees the termination of the rewrite method.treepublic static <V> TreeRewriteRule<V> parse(String rule, Function<? super String,? extends V> mapper)
add($x,0) -> $x
mul($x,1) -> $x
V - the tree node typerule - the rewrite rulemapper - the mapper function which converts the node value into the
actual type VIllegalArgumentException - if the rewrite rule is invalidNullPointerException - if on of the arguments is nullpublic static TreeRewriteRule<String> parse(String rule)
add($x,0) -> $x
mul($x,1) -> $x
rule - the rewrite ruleIllegalArgumentException - if the rewrite rule is invalidNullPointerException - if on of the arguments is null© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)