Treeql API

Treeql is a fairly thin query facility over tree-structured data types. It implements an ordered set of nodes (really a list) which are generated and filtered by application of the treeql query language to each node in turn.

TreeQL Object Interface

TreeQL is a Snit type which implements the treeql query language.

This group of methods provides the tcl interface to the treeql language.

TreeQL name -tree tree ?-query query? ?-nodes nodes? args a new query object

name names the object to be constructed

-query specifies a parent query

-nodes specifies an initial node list

-tree specifies the underlying tree over which this

args are the query operations to be performed

query query args perform the new query args query result return the node set as a list query discard returns result, and destroys this query (useful in constructing a sub-query)
Structural generators
These tree-structural operations add nodes to the node set
ancestors all nodes on the path from node to root rootpath all nodes on the path from root to node parent node parent children node children left previous sibling right next sibling prev previous siblings in reverse order esib previous siblings in tree order next next siblings in tree order root the tree root tree all nodes in the tree descendants all subtrees rooted at node forward flattened next subtrees backward flattened previous subtrees in reverse tree order later flattened next subtrees Synonym for [forward] earlier flattened previous subtrees in tree order
Attribute Filters
These operations filter the node set by reference to attributes
hasatt attr Reduce to nodes with attribute attr (can be a glob) withatt attr value Reduce to nodes with attribute attr of value withatt! attr val Reduce to nodes with attribute attr of value attr must exist in each node of node set attof attr vals Reduce to nodes with attribute attr value one of list of vals attmatch attr match Reduce to nodes whose attribute attr [string match]es match
Attribute Mutators
These operators change node attributes within the underlying tree.
string op attr apply string operation op to attribute attr on each node set attr val Side Effect: set attribute attr to val unset attr Side Effect: unset attribute attr
Attribute String Accessors

These operators change node attributes within the underlying tree.

Their results are stored in the node set, but are not actually nodes.

getvals pattern returns the list of attribute values of attributes matching pattern get attr returns the list of attribute values of attributes matching attr attlist returns list of attribute values of the current node, in an unspecified order. attrs glob returns list of lists of attributes of each node attval attname returns values of attribute attname
SubQueries
SubQueries yield node sets which can augment, reduce or replace the current node set
andq query Replace node set with the set-intersection of the subquery query orq query Replace node set with the set-union of the subquery query notq query Replace node set with the set of nodes from subquery query which are not in the current node set
Node Set Operations unique remove duplicate nodes, preserving order select select the first node of the node set transform var query body replace the node set with result of the subquery quote val append the literal val to node set replace val replace the node set with the literal Node Set Iterators foreach var query body perform a subquery query then map body over results with query body perform a query, then evaluate body over varbody map body over node set delete delete all nodes in node set Typed node support
These filters and accessors assume the existence of an attribute called '@type', and are short-hand forms useful for cost-like tree query, html tree editing, and so on.
nodetype returns the node type of nodes oftype t Reduce to nodes of type t nottype t Reduce to nodes not of type t oftypes attrs Reduce to nodes whose @type is one of attrs