Tree

Tree

The main tree class.

Creates a new tree, and stores "data" and "children" in attributes of the same name.
Trees can be hashed and compared.

Parameters:
    data: The name of the rule or alias
    children: List of matched sub-rules and terminals
    meta: Line & Column numbers (if ``propagate_positions`` is enabled).
        meta attributes: line, column, start_pos, end_line, end_column, end_pos

Constructor

new Tree()

Source:

Methods

find_data()

Returns all nodes of the tree whose data equals the given data.

Source:

find_data()

Returns all nodes of the tree whose data equals the given data.

Source:

find_pred()

Returns all nodes of the tree that evaluate pred(node) as true.

Source:

find_pred()

Returns all nodes of the tree that evaluate pred(node) as true.

Source:

iter_subtrees()

Depth-first iteration.

    Iterates over all the subtrees, never returning to the same node twice (Lark's parse-tree is actually a DAG).
Source:

iter_subtrees()

Depth-first iteration.

    Iterates over all the subtrees, never returning to the same node twice (Lark's parse-tree is actually a DAG).
Source:

(generator) iter_subtrees_topdown()

Breadth-first iteration.

    Iterates over all the subtrees, return nodes in order like pretty() does.
Source:

(generator) iter_subtrees_topdown()

Breadth-first iteration.

    Iterates over all the subtrees, return nodes in order like pretty() does.
Source:

pretty()

Returns an indented string representation of the tree.

    Great for debugging.
Source:

pretty()

Returns an indented string representation of the tree.

    Great for debugging.
Source:

(generator) scan_values()

Return all values in the tree that evaluate pred(value) as true.

    This can be used to find all the tokens in the tree.

    Example:
        >>> all_tokens = tree.scan_values(lambda v: isinstance(v, Token))
Source:

(generator) scan_values()

Return all values in the tree that evaluate pred(value) as true.

    This can be used to find all the tokens in the tree.

    Example:
        >>> all_tokens = tree.scan_values(lambda v: isinstance(v, Token))
Source:

Tree

The main tree class.

Creates a new tree, and stores "data" and "children" in attributes of the same name.
Trees can be hashed and compared.

Parameters:
    data: The name of the rule or alias
    children: List of matched sub-rules and terminals
    meta: Line & Column numbers (if ``propagate_positions`` is enabled).
        meta attributes: line, column, start_pos, end_line, end_column, end_pos

Constructor

new Tree()

Source:

Methods

find_data()

Returns all nodes of the tree whose data equals the given data.

Source:

find_data()

Returns all nodes of the tree whose data equals the given data.

Source:

find_pred()

Returns all nodes of the tree that evaluate pred(node) as true.

Source:

find_pred()

Returns all nodes of the tree that evaluate pred(node) as true.

Source:

iter_subtrees()

Depth-first iteration.

    Iterates over all the subtrees, never returning to the same node twice (Lark's parse-tree is actually a DAG).
Source:

iter_subtrees()

Depth-first iteration.

    Iterates over all the subtrees, never returning to the same node twice (Lark's parse-tree is actually a DAG).
Source:

(generator) iter_subtrees_topdown()

Breadth-first iteration.

    Iterates over all the subtrees, return nodes in order like pretty() does.
Source:

(generator) iter_subtrees_topdown()

Breadth-first iteration.

    Iterates over all the subtrees, return nodes in order like pretty() does.
Source:

pretty()

Returns an indented string representation of the tree.

    Great for debugging.
Source:

pretty()

Returns an indented string representation of the tree.

    Great for debugging.
Source:

(generator) scan_values()

Return all values in the tree that evaluate pred(value) as true.

    This can be used to find all the tokens in the tree.

    Example:
        >>> all_tokens = tree.scan_values(lambda v: isinstance(v, Token))
Source:

(generator) scan_values()

Return all values in the tree that evaluate pred(value) as true.

    This can be used to find all the tokens in the tree.

    Example:
        >>> all_tokens = tree.scan_values(lambda v: isinstance(v, Token))
Source: