Class UnchainingRewriteRule
java.lang.Object
com.singularsys.extensions.rewrite.AbstractRewrite
com.singularsys.extensions.chained.UnchainingRewriteRule
- All Implemented Interfaces:
RewriteRuleI,JepComponent,Serializable
A rule which transforms a chain of functions into a nested function calls.
For example
Calling the
[1..5] . map(x=>x^2) . last() will be transformed to last(map(x=>x^2, [1..5])).
To use:
var rw = new RewriteVisitor();
rw.add(new UnchainingRewriteRule());
rw.init(jep);
OverloadResolver or = new OverloadResolver();
or.init(jep);
Node node = jep.parse("[1..5] . map(x=>x^2) . last()");
or.visit(node);
Node rewritten = rw.rewrite(node,false);
Object result = jep.evaluate(rewritten);
OverloadResolver
before the rewrite is necessary resolve the overloaded dot operator and convert
functions implementing ChainableBinaryFunction in ChainedBinaryFunction
and similar for other types. Using these two operators
will slightly speed up evaluation times.- Since:
- Jep 4.1
- See Also:
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(ASTFunNode node, List<Node> children) Rewrites the nodebooleantest(ASTFunNode node, List<Node> children) Returns true if node needs to be rewritten, according to this rule.Methods inherited from class com.singularsys.extensions.rewrite.AbstractRewrite
getLightWeightInstance, init, toString
-
Constructor Details
-
UnchainingRewriteRule
public UnchainingRewriteRule()
-
-
Method Details
-
test
Description copied from interface:RewriteRuleIReturns true if node needs to be rewritten, according to this rule.- Throws:
ParseException- if for some reason rewriting cannot be performed.
-
apply
Description copied from interface:RewriteRuleIRewrites the node- Throws:
ParseException
-