|
Rule Designer API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectilog.rules.brl.syntaxtree.IlrSyntaxTree
public class IlrSyntaxTree
IlrSyntaxTree implements the abstract syntax tree that
represents the current state of a BRLDF defined rule instance.
The following code example shows how to print the 'LOCALE VAR' action in a custom BRL.
public void printSimpleAction(IlrSimpleActionStatement stmt, IlrAbstractCodeGenerator codeGenerator) {
IlrIRLCodeGenerator irlCodeGenerator = (IlrIRLCodeGenerator) codeGenerator;
IlrSyntaxTree.Node node = stmt.getNode();
switch (stmt.getKind()) {
case ExtendedBALNodeTranslators.LOCAL_VAR:
IlrSyntaxTree.Node targetNode = node.getSubNode(1);
IlrConcept concept = IlrTranslationHelper.getConcept(targetNode, codeGenerator.getVocabulary());
irlCodeGenerator.print(irlCodeGenerator.getTranslationSupport().getTypeString(concept));
irlCodeGenerator.print(" ");
String varName = IlrBRL.getVariableName(node.getSubNode(0));
irlCodeGenerator.print(IlrTranslationHelper.makeIdentifier(varName));
break;
}
}
A syntax tree represents a business rule. It is made of nodes. Each node represents an operator in the grammar. A syntax tree contains one root node. Use this class to:
You use an iterator to filter nodes in the syntax tree.
A syntax tree can be created from the text of the rule instance using a
BRL parser. For more information, see
IlrBRLParser.
IlrBRLParser,
Serialized Form
| Nested Class Summary | |
|---|---|
static class |
IlrSyntaxTree.Iterator
An iterator which iterates over the nodes of a syntax tree. |
static class |
IlrSyntaxTree.NameTester
Implements IlrSyntaxTree.NodeTester. |
class |
IlrSyntaxTree.Node
The syntax tree is composed of nodes that are instances of IlrSyntaxTree.Node. |
static interface |
IlrSyntaxTree.NodeTester
Specifies a filter for an IlrSyntaxTree.Iterator. |
static interface |
IlrSyntaxTree.Visitor
A visitor interface for syntax nodes. |
| Field Summary | |
|---|---|
static int |
BOTTOM_UP_LEFT_TO_RIGHT
A static constant to create an Iterator which iterates over the
nodes of a tree, from left to right and from bottom to top. |
static int |
BOTTOM_UP_RIGHT_TO_LEFT
A static constant to create an Iterator which iterates over the
nodes of a tree, from right to left and from bottom to top. |
static int |
DOWN
A static constant to create an Iterator which goes down the syntax
tree. |
static int |
LEFT
A static constant to create an Iterator which iterates over the
preceding siblings of the current node. |
static int |
RIGHT
A static constant to create an Iterator which iterates over the
next siblings of the current node. |
static int |
SUBNODES
A static constant to create an Iterator which iterates over the
subnodes of the current node. |
static int |
UP
A static constant to create an Iterator which goes up the syntax
tree. |
| Constructor Summary | |
|---|---|
IlrSyntaxTree(IlrBRLDefinition brlDefinition,
IlrVocabulary vocabulary)
Makes an instance of IlrSyntaxTree, with the given business rule language definition
and vocabulary. |
|
| Method Summary | |
|---|---|
void |
clearProperties()
Clears all properties that have been set on this instance of a syntax tree. |
Object |
clone()
Clones this syntax tree. |
IlrBRLDefinition |
getBRLDefinition()
Returns the business rule language definition from which this syntax tree is an instance. |
IlrSyntaxTree.Node |
getCurrentNode()
Returns the current node being built. |
IlrBRLElement |
getEditedElement()
Allows retrieving the edited element associated to this syntax tree. |
IlrBRLRuleEditingContext |
getEditingContext()
This method retrieve the Editing Context that may have been set to the syntax tree. |
IlrSyntaxTree.Node |
getNodeFromPath(IlrSyntaxTree.Node root,
String nodePath)
Gets a syntax tree node from its path, relatively from the root node. |
IlrSyntaxTree.Node |
getNodeFromPath(String nodePath)
Gets a syntax tree node from its path. |
Object |
getProperty(String propName)
Retrieves a property that has been set on this instance of a syntax tree. |
IlrSyntaxTree.Node |
getRoot()
Gets the root node of this syntax tree. |
IlrVocabulary |
getVocabulary()
Returns the vocabulary associated to this syntax tree. |
String |
getXMLString()
Returns a XML string representation of this syntax tree. |
boolean |
hasErrorRecovery()
Returns true if the syntax tree has nodes that are in error recovery,
false otherwise. |
boolean |
hasPlaceHolders()
Returns true if the syntax tree has nodes that are placeholders,
false otherwise. |
IlrSyntaxTree.Iterator |
iterator()
Gets an iterator over this syntax tree. |
IlrSyntaxTree.Iterator |
iterator(int direction)
Gets an iterator that navigates through the syntax tree, starting from its root node, in the specified direction. |
IlrSyntaxTree.Node |
popNode()
Pops one node off the syntax tree stack, so that the supernode of the current node becomes the current node. |
void |
print(OutputStream os)
Prints an XML representation of this syntax tree in the specified output stream. |
void |
print(Writer writer)
Prints an XML representation of this syntax tree in the given writer. |
IlrSyntaxTree.Node |
pushNode(String name)
Makes a new node called name, and adds it as a subnode of the current node. |
void |
removeProperty(String propName)
Removes a given property from a list of properties stored on a syntax tree. |
void |
setCurrentNode(IlrSyntaxTree.Node node)
Sets the current node to be built. |
void |
setProperty(String propName,
Object value)
Sets a property on this instance of the syntax tree. |
void |
setRoot(IlrSyntaxTree.Node root)
Sets the root node of this syntax tree. |
void |
visit(IlrSyntaxTree.Visitor visitor)
Applies a visitor to this syntax tree. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int UP
Iterator which goes up the syntax
tree. It iterates over the supernode of the current node, until the root of
the tree is found.
public static final int DOWN
Iterator which goes down the syntax
tree. It iterates over the subnodes of the current node, in a depth-first
manner.
public static final int LEFT
Iterator which iterates over the
preceding siblings of the current node.
public static final int RIGHT
Iterator which iterates over the
next siblings of the current node.
public static final int SUBNODES
Iterator which iterates over the
subnodes of the current node.
public static final int BOTTOM_UP_RIGHT_TO_LEFT
Iterator which iterates over the
nodes of a tree, from right to left and from bottom to top.
public static final int BOTTOM_UP_LEFT_TO_RIGHT
Iterator which iterates over the
nodes of a tree, from left to right and from bottom to top.
| Constructor Detail |
|---|
public IlrSyntaxTree(IlrBRLDefinition brlDefinition,
IlrVocabulary vocabulary)
IlrSyntaxTree, with the given business rule language definition
and vocabulary.
brlDefinition - The business rule language definition associated to this syntax tree.vocabulary - The vocabulary associated to this syntax tree.| Method Detail |
|---|
public Object clone()
IlrBRLDefinition.
clone in class Objectpublic IlrBRLElement getEditedElement()
IlrBRLRuleElement. If this syntax
tree is the result of the deserialization of an AST file, this method
returns null.
If an editing context has been set on this AST, the edited element of this context is returned.
null.public IlrBRLRuleEditingContext getEditingContext()
public IlrBRLDefinition getBRLDefinition()
public IlrVocabulary getVocabulary()
public boolean hasPlaceHolders()
true if the syntax tree has nodes that are placeholders,
false otherwise.
true if the syntax tree has nodes that are placeholders.public boolean hasErrorRecovery()
true if the syntax tree has nodes that are in error recovery,
false otherwise. Error recovery nodes are created by the parser when
facing syntactic errors or other kind of errors that prevent from building a consistent AST.
true if the syntax tree has nodes that are in error recovery.public void setRoot(IlrSyntaxTree.Node root)
root - The Node object that is the root of the syntax tree.public IlrSyntaxTree.Node getRoot()
Node object that is the root of the syntax tree.public void setProperty(String propName,
Object value)
propName - The property key.value - The value of the property.public Object getProperty(String propName)
propName - The property key.
null if the property is not registered.public void clearProperties()
public void removeProperty(String propName)
propName - The property key.public IlrSyntaxTree.Node pushNode(String name)
name, and adds it as a subnode of the current node. This method is used when building a syntax tree. If
there is no current node, this node becomes the root of the syntax tree.
This node then becomes the current node.
name - The name of the new node.
public IlrSyntaxTree.Node popNode()
public IlrSyntaxTree.Node getCurrentNode()
public void setCurrentNode(IlrSyntaxTree.Node node)
node - The new current node.public IlrSyntaxTree.Node getNodeFromPath(String nodePath)
throws IlrNodePathError
IlrNodePathErrornodePath - The path of the node.
IlrSyntaxTree.Node.getNodePath()public IlrSyntaxTree.Node getNodeFromPath(IlrSyntaxTree.Node root,
String nodePath)
throws IlrNodePathError
IlrNodePathErrorroot - The root node.nodePath - The path of the node.
IlrSyntaxTree.Node.getNodePath()public IlrSyntaxTree.Iterator iterator()
Iterator object.public IlrSyntaxTree.Iterator iterator(int direction)
The direction must be one of the following: UP,
DOWN,LEFT,RIGHT,SUBNODES.
direction - The direction the iterator takes when it navigates through
the syntax tree.
Iterator object.public void print(OutputStream os)
os - The output stream.public void print(Writer writer)
writer - The writer that handles the printing.public String getXMLString()
print(Writer)public final void visit(IlrSyntaxTree.Visitor visitor)
visit of the root node of this syntax tree with the
visitor as argument.
visitor - The visitor.
|
Rule Designer API | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||