Class RewriteVisitor
- java.lang.Object
-
- com.singularsys.jep.walkers.DoNothingVisitor
-
- com.singularsys.extensions.rewrite.RewriteVisitor
-
- All Implemented Interfaces:
JepComponent
,ParserVisitor
,java.io.Serializable
public class RewriteVisitor extends DoNothingVisitor
A visitor which allows rewrite rules to be added and applied.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RewriteVisitor.ConstantRuleI
static interface
RewriteVisitor.VariableRuleI
Define a rule which may modify a variable node.
-
Constructor Summary
Constructors Constructor Description RewriteVisitor()
RewriteVisitor(Jep j)
Constructor for use in standalone context
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(RewriteRuleI rule)
Add a rewriting ruleboolean
add(RewriteVisitor.ConstantRuleI rule)
Adds a rule modifying constant nodesboolean
add(RewriteVisitor.VariableRuleI rule)
Adds a rule modifying variable nodesvoid
clear()
Clear all rules of all typesjava.util.List<RewriteVisitor.ConstantRuleI>
getConstantRules()
java.util.List<RewriteRuleI>
getRules()
Gets the current set of rulesjava.util.List<RewriteVisitor.VariableRuleI>
getVariableRules()
void
init(Jep j)
Initialize the component.Node
rewrite(Node node, boolean clean)
Applies the set of rules to the nodejava.lang.Object
visit(ASTConstant node, java.lang.Object data)
Visit a constant node.java.lang.Object
visit(ASTFunNode node, java.lang.Object data)
Visit a function node.java.lang.Object
visit(ASTOpNode node, java.lang.Object data)
Visit a operator node.java.lang.Object
visit(ASTVarNode node, java.lang.Object data)
Visit a variable node.java.lang.Object
visitFun(ASTFunNode node, java.lang.Object data)
-
Methods inherited from class com.singularsys.jep.walkers.DoNothingVisitor
childrenHaveChanged, copyChildrenIfNeeded, getFunctionTable, getLightWeightInstance, getNodeFactory, getOperatorTable, getVariableTable, visit, visitChildren, visitNode
-
-
-
-
Constructor Detail
-
RewriteVisitor
public RewriteVisitor()
-
RewriteVisitor
public RewriteVisitor(Jep j)
Constructor for use in standalone context- Parameters:
j
- Jep instance to use
-
-
Method Detail
-
init
public void init(Jep j)
Description copied from interface:JepComponent
Initialize the component. This methods is called whenever a component is added to Jep. Hence it allows components to keep track of the other components they may rely on.- Specified by:
init
in interfaceJepComponent
- Overrides:
init
in classDoNothingVisitor
- Parameters:
j
- the current Jep instance
-
rewrite
public Node rewrite(Node node, boolean clean) throws ParseException
Applies the set of rules to the node- Parameters:
node
- node to apply rewriting toclean
- whether to clean the result- Returns:
- Throws:
ParseException
-
visit
public java.lang.Object visit(ASTOpNode node, java.lang.Object data) throws JepException
Description copied from class:DoNothingVisitor
Visit a operator node. Can be overridden by sub-classes.- Specified by:
visit
in interfaceParserVisitor
- Overrides:
visit
in classDoNothingVisitor
- Throws:
JepException
-
visit
public java.lang.Object visit(ASTFunNode node, java.lang.Object data) throws JepException
Description copied from class:DoNothingVisitor
Visit a function node. Can be overridden by sub-classes.- Specified by:
visit
in interfaceParserVisitor
- Overrides:
visit
in classDoNothingVisitor
- Throws:
JepException
-
visitFun
public java.lang.Object visitFun(ASTFunNode node, java.lang.Object data) throws JepException
- Throws:
JepException
-
visit
public java.lang.Object visit(ASTConstant node, java.lang.Object data) throws JepException
Description copied from class:DoNothingVisitor
Visit a constant node. Can be overridden by sub-classes.- Specified by:
visit
in interfaceParserVisitor
- Overrides:
visit
in classDoNothingVisitor
- Throws:
JepException
-
visit
public java.lang.Object visit(ASTVarNode node, java.lang.Object data) throws JepException
Description copied from class:DoNothingVisitor
Visit a variable node. Can be overridden by sub-classes.- Specified by:
visit
in interfaceParserVisitor
- Overrides:
visit
in classDoNothingVisitor
- Throws:
JepException
-
add
public boolean add(RewriteRuleI rule)
Add a rewriting rule- Parameters:
rule
- rule to add- Returns:
-
getRules
public java.util.List<RewriteRuleI> getRules()
Gets the current set of rules- Returns:
-
add
public boolean add(RewriteVisitor.VariableRuleI rule)
Adds a rule modifying variable nodes- Parameters:
rule
- the rule- Returns:
- true
- Since:
- Jep 4.0/Extentions 2.1
-
add
public boolean add(RewriteVisitor.ConstantRuleI rule)
Adds a rule modifying constant nodes- Parameters:
rule
- the rule- Returns:
- true
- Since:
- Jep 4.0/Extentions 2.1
-
getVariableRules
public java.util.List<RewriteVisitor.VariableRuleI> getVariableRules()
-
getConstantRules
public java.util.List<RewriteVisitor.ConstantRuleI> getConstantRules()
-
clear
public void clear()
Clear all rules of all types- Since:
- Jep 4.0
-
-