Abstract syntax tree and abstract tree nodes

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:

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: