Class RewriteVisitor
java.lang.Object
com.singularsys.jep.walkers.GenericDoNothingVisitor<Void>
com.singularsys.jep.walkers.GenericDeepCopyVisitor<Void>
com.singularsys.extensions.rewrite.RewriteVisitor
- All Implemented Interfaces:
GenericVisitor<Node,,Void, ParseException> JepComponent,Serializable
A visitor which allows rewrite rules to be added and applied.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDefine a rule which may modify a constant node.static interfaceDefine a rule which may modify a variable node. -
Field Summary
FieldsFields inherited from class com.singularsys.jep.walkers.GenericDoNothingVisitor
ft, nf, ot -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for use in standalone context -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(RewriteRuleI rule) Add a rewriting rulebooleanAdds a rule modifying constant nodesbooleanAdds a rule modifying variable nodesvoidclear()Clear all rules of all typesGets a light-weight instance suitable for using in multiple threads.getRules()Gets the current set of rulesvoidInitialize the component.Applies the set of rules to the nodevisit(ASTConstant node, Void data) Visit a constant nodevisit(ASTFunNode node, Void data) Visit a function nodeVisit an operator nodevisit(ASTVarNode node, Void data) Visit a variable nodevisitFun(ASTFunNode node) Methods inherited from class com.singularsys.jep.walkers.GenericDeepCopyVisitor
visitMethods inherited from class com.singularsys.jep.walkers.GenericDoNothingVisitor
childrenHaveChanged, copyChildrenIfNeeded, copyChildrenIfNeeded, makeExceptionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.singularsys.jep.GenericVisitor
makeException, visitChildren
-
Field Details
-
rules
-
-
Constructor Details
-
RewriteVisitor
public RewriteVisitor() -
RewriteVisitor
Constructor for use in standalone context- Parameters:
j- Jep instance to use
-
-
Method Details
-
init
Description copied from interface:JepComponentInitialize the component. This method 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:
initin interfaceJepComponent- Overrides:
initin classGenericDoNothingVisitor<Void>- Parameters:
j- the current Jep instance
-
rewrite
Applies the set of rules to the node- Parameters:
node- node to apply rewriting toclean- whether to clean the result- Returns:
- Throws:
ParseException
-
visit
Description copied from interface:GenericVisitorVisit an operator node- Specified by:
visitin interfaceGenericVisitor<Node,Void, ParseException> - Overrides:
visitin classGenericDeepCopyVisitor<Void>- Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
ParseException
-
visit
Description copied from interface:GenericVisitorVisit a function node- Specified by:
visitin interfaceGenericVisitor<Node,Void, ParseException> - Overrides:
visitin classGenericDeepCopyVisitor<Void>- Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
ParseException
-
visitFun
- Throws:
ParseException
-
visit
Description copied from interface:GenericVisitorVisit a constant node- Specified by:
visitin interfaceGenericVisitor<Node,Void, ParseException> - Overrides:
visitin classGenericDeepCopyVisitor<Void>- Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
ParseException
-
visit
Description copied from interface:GenericVisitorVisit a variable node- Specified by:
visitin interfaceGenericVisitor<Node,Void, ParseException> - Overrides:
visitin classGenericDeepCopyVisitor<Void>- Parameters:
node- current nodedata- context data- Returns:
- the result of visiting the node
- Throws:
ParseException
-
add
Add a rewriting rule- Parameters:
rule- rule to add- Returns:
-
getRules
Gets the current set of rules- Returns:
-
add
Adds a rule modifying variable nodes- Parameters:
rule- the rule- Returns:
- true
- Since:
- Jep 4.0/Extensions 2.1
-
add
Adds a rule modifying constant nodes- Parameters:
rule- the rule- Returns:
- true
- Since:
- Jep 4.0/Extensions 2.1
-
getVariableRules
-
getConstantRules
-
clear
public void clear()Clear all rules of all types- Since:
- Jep 4.0
-
getLightWeightInstance
Description copied from interface:JepComponentGets a light-weight instance suitable for using in multiple threads.- Specified by:
getLightWeightInstancein interfaceJepComponent- Overrides:
getLightWeightInstancein classGenericDeepCopyVisitor<Void>- Returns:
- either a new instance, null or 'this'.
-