An abstract syntax tree is an instance of the XML schema that defines an abstract syntax, and specifies the structure of the XML object that represents a rule. It does not, therefore, depend on the locale.
The abstract syntax tree is the result of the parsing or editing of the text of a rule. It generates IRL code for the rule.
You can access the abstract syntax tree through the IlrSyntaxTree class. This class offers a simple API to navigate through the nodes of the abstract syntax tree and their children, and to retrieve the text content of an element. The abstract syntax tree is composed of nodes. The IlrSyntaxTree.Node class represents a node in the tree. There is a single root node in a syntax tree. Each node has a name corresponding to an element in the abstract syntax.
Each node can contain:
A list of subnodes, which you can access with the methods subNodesCount and getSubNode(int index)
Some text content, which you can retrieve with the method getContents
You can retrieve the parent of a node with the method getSuperNode. This method returns null for the root node.
You use the iterator method to iterate over subnodes from a given node, in a depth-first way. You can specify an additional argument to filter the nodes to be iterated over, by passing an instance of the IlrSyntaxTree.NodeTester interface. This interface specifies a single method:
public boolean acceptNode(IlrSyntaxTree.Node node)
You can use a predefined class of IlrSyntaxTree.NodeTester, named IlrSyntaxTree.NameTester, to test the name of a node.
For example, if you want to iterate over all subnodes named class:
IlrSyntaxTree.Iterator iterator = node.iterator(“class”)
while (iterator.hasNextNode()) {
System.out.println("subnode: "+ subnode.getName())
}
You can also specify a direction argument that specifies the way that the iterator navigates in the syntax tree.
The iterator works as follows, depending on the value of the direction argument:
IlrSyntaxTree.DOWN iterates over the subnodes of the start node, in a depth-first manner. The iterator starts at the start node, then goes down its subnodes until if finds one that matches the tester. If it fails to find one, when it reaches a leaf node it then goes up again and continues with the next sibling of this leaf node.
IlrSyntaxTree.UP iterates over the supernodes of the start node until it reaches the tree root node.
IlrSyntaxTree.LEFT iterates over the preceding siblings of the start node, until it reaches the first sibling node.
IlrSyntaxTree.RIGHT iterates over the next siblings of the start node, until it reaches the last sibling node.
IlrSyntaxTree.SUBNODES iterates over the subnodes of the start node, and does not go deeper.