class Arborist::ParseTree

Overview

A nil parse tree means parse error ParseTree is an abstract base class that defines one required field: finishing_pos : Int32

Direct Known Subclasses

Defined in:

parse_tree.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new #

[View source]

Class Method Detail

def self.to_msgpack(parse_tree : ParseTree) : Bytes #

This method returns a serialized representation of the specified parse tree, encoded with MessagePack. The serialization layout is: Each ParseTree node is represented with the following structure: <node type (ApplyTree | TerminalTree | ...)> <input start position (inclusive)> <input end position (inclusive)> <node label (may be nil)> <parent node ID (may be nil)> <array of captures, where each capture is a 4-tuple (String,Int32,Int32,Int32), representing (capture name, node ID belonging to referenced node, input start position inclusive, input end position inclusive) > <node attributes specific to the type of node (e.g. ApplyTree has a rule_name attribute; TerminalTree has a str attribute; etc.)>


[View source]

Instance Method Detail

def capture(name : String) : ParseTree #

[View source]
def capture?(name : String) : ParseTree | Nil #

[View source]
def captures(name : String) : Array(ParseTree) #

[View source]
def captures : Hash(String, Array(ParseTree)) #

[View source]
def child : ParseTree #

[View source]
def child? : ParseTree | Nil #

[View source]
def children : Array(ParseTree) #

children returns the list of all actual/literal child ParseTree nodes in parse tree structure, rather than skipping some, as with #terms Another way of thinking about this is #children returns concrete children, #terms returns logical children.


[View source]
def descendants : Array(ParseTree) #

returns all descendants listed out in a pre-order traversal


[View source]
def enclosing_rule_name : String | Nil #

returns the name of the rule that, as a result of being evaluated, yielded this parse tree node


[View source]
def finishing_pos : Int32 #

[View source]
def finishing_pos=(finishing_pos : Int32) #

[View source]
def input : CharArray #

[View source]
def input=(input : CharArray) #

[View source]
def label : String | Nil #

[View source]
def label=(label : String | Nil) #

[View source]
def labeled? #

[View source]
def local_captures : Hash(String, Array(ParseTree)) #

[View source]
def parent : ParseTree | Nil #

[View source]
def parent=(parent : ParseTree | Nil) #

[View source]
def parse_tree_type_specific_attributes_to_msgpack(packer : MessagePack::Packer) #

[View source]
def postorder_traverse(&visit : ParseTree -> _) #

[View source]
def postorder_traverse(visit : ParseTree -> _) #

[View source]
def preorder_traverse(visit : ParseTree -> _) #

[View source]
def recursively_populate_parents(parent : ParseTree | Nil = nil) #

call this on the root node in the tree to update all the nodes in the tree with their parent node


[View source]
def root #

[View source]
def root? #

[View source]
def s_exp(indent : Int32 = 0) : String #

[View source]
def self_and_descendants : Array(ParseTree) #

returns all nodes listed out in a pre-order traversal


[View source]
def set_label(label : Nil | String) #

[View source]
def simple_s_exp : String #

[View source]
def start_pos : Int32 #

[View source]
def start_pos=(start_pos : Int32) #

[View source]
def syntax_tree : SyntaxTree #

[View source]
def terminal? #

[View source]
def text : String #

returns the matched substring of the input that this parse tree node represents


[View source]
def to_msgpack(packer : MessagePack::Packer) #

Each ParseTree node is represented with the following structure: <node type (ApplyTree | TerminalTree | ...)> <input start position (inclusive)> <input end position (inclusive)> <node label (may be nil)> <parent node ID (may be nil)> <map of captures, having type Map(String, Array(UInt64)), representing: => [node ID belonging to referenced node, another node ID belonging to referenced node, ...], => [node ID belonging to referenced node, another node ID belonging to referenced node, ...], ...

<node attributes specific to the type of node (e.g. ApplyTree has a rule_name attribute; TerminalTree has a str attribute; etc.)>


[View source]
def visit(visitor : Visitor(R)) forall R #

[View source]