Home · Docs · Primer · Examples · Prefixing · Syntax · Rules · Parser · Tree · Actions · Debug


Hapy parsers produce parsing trees as output. To interpret successfully parsed content, your code needs to interpret the parsing tree.

A node of a Hapy parsing trees is a C++ object of the Pree class (Pree stands for Parsing tREE). Pree class is declared in <Hapy/Pree.h>. A node stores a rule identifier corresponding to the parsing rule that produced the node. A node provides access to its "image", a substring of the input that the identified parsing rule matched. Finally, node children (sub-trees) can be accessed individually by their position or rule id as well as iterated sequentially using STL-standard begin/end methods.

Trimmed input on the "left" and on the "right" of the matched input is not included in the node image and is not included in node children. There is a "raw" node interface to access trimmed input and kids, but you are unlikely to need that.

Pree class member Semantics
RuleId rid() identifier of the parsing rule that created the node; RuleId objects can be stored and compared for equality with, for example, the result of a Rule::id() call.
string image() substring matched by the parsing rule that created the node
int count() number of children (subtrees); leaf nodes would always have zero kids count
const_iterator begin() left-most child position, for left-to-right tree traversal
const_iterator end() right-most child position plus one, for left-to-right tree traversal
const Pree &operator [](int idx) child node at a given position
const Pree &find(int rid) first child node produced by a rule with a given identifier; this method does not search any nodes other than the immediate children
ostream &print(ostream &) dumps node structure for debugging purposes; node rule identifier, number of kids, and raw image are printed, followed by indented children

The parsing tree interface is likely to evolve with time. For example, adding rule-specific node data may be needed.

SourceForge Home