struct

Sthx::TreeData

Inherits Struct < Value < Object

Tree consists of two parts: a "header" part with the tree's capture id, begin character index, and span; and a "body" part. TreeData is this body part. It is filled by callees and then wrapped in a tree by the caller after it determines the end position. A tree cannot be constructed without knowing the end position - and a tree "body", TreeData, can.

Constructors

new(children : Pf::Map(Int32, Tree) | Nil = nil, attributes : Pf::Map(String, Bytes) | Nil = nil)
Source

Instance methods

append(tree : Tree)

Returns a copy of self with tree appended as a child tree.

Source
degree

Returns the number of children.

Source
each_attribute

Yields each attribute: its name and a string view of its value.

Source
each_child

Yields each child tree.

Source
empty?

Returns true if this tree data object stores no children and no attributes.

Source
getattr?(name : String) : Bytes | Nil

Returns a string view of the value of the attribute with the given name. If there is no such attribute, returns nil.

Source
getchild?(n : Int32) : Tree | Nil

Returns the nth child tree.

Returns nil if n is out of bounds.

Source
inspect(io, tree, inner, outer)
Source
setattr(name : String, value : Bytes) : TreeData

Returns a copy of self where the attribute with the given name is assigned to value, a string view of the value of the attribute.

Source