Class Node

A node within a Tree.

Analogous to TSNode.

Methods

Node:tree () Get the Tree the node belongs to.
Node:type () Get the type of the node.
Node:start_byte () Get the start byte of the node.
Node:start_point () Get the start Point of the node.
Node:end_byte () Get the end byte of the node.
Node:end_point () Get the end Point of the node.
Node:is_named () Check if the node is named.
Node:is_missing () Check if the node is missing.
Node:is_extra () Check if the node is extra.
Node:has_changes () Check if the node has been edited.
Node:has_error () Check if the node is a syntax error or contains any syntax errors.
Node:parent () Get the immediate parent of the node.
Node:child (index) Get the child of the node at a given index.
Node:field_name_for_child (index) Get the field name of the child of the node at a given index.
Node:child_count () Get the number of children the node has.
Node:named_child (index) Get the named child of the node at a given index.
Node:named_child_count () Get the number of named children the node has.
Node:child_by_field_id (id) Get the child of the node by a given field ID.
Node:next_sibling () Get the next sibling of the node.
Node:prev_sibling () Get the previous sibling of the node.
Node:next_named_sibling () Get the next named sibling of the node.
Node:prev_named_sibling () Get the previous named_sibling of the node.
Node:first_child_for_byte (byte) Get the first child of the node that extends beyond the given byte offset.
Node:first_named_child_for_byte (byte) Get the first named child of the node that extends beyond the given byte offset.
Node:descendant_for_byte_range (start_byte, end_byte) Get the smallest node within the node that spans the given range of bytes.
Node:descendant_for_point_range (start_point, end_point) Get the smallest node within the node that spans the given range of Points.
Node:named_descendant_for_byte_range (start_byte, end_byte) Get the smallest named node within the node that spans the given range of bytes.
Node:named_descendant_for_point_range (start_point, end_point) Get the smallest named node within the node that spans the given range of Points.

Metamethods

Node:__eq (other) Check equality of two nodes by value.
Node:__tostring () Convert the node to a S-expression.


Methods

Node:tree ()
Get the Tree the node belongs to.

Returns:

    Tree
Node:type ()
Get the type of the node.

Returns:

    string
Node:start_byte ()
Get the start byte of the node.

Returns:

    integer
Node:start_point ()
Get the start Point of the node.

Returns:

    Point
Node:end_byte ()
Get the end byte of the node.

Returns:

    integer
Node:end_point ()
Get the end Point of the node.

Returns:

    Point
Node:is_named ()
Check if the node is named.

Returns:

    boolean
Node:is_missing ()
Check if the node is missing.

Returns:

    boolean
Node:is_extra ()
Check if the node is extra.

Returns:

    boolean
Node:has_changes ()
Check if the node has been edited.

Returns:

    boolean
Node:has_error ()
Check if the node is a syntax error or contains any syntax errors.

Returns:

    boolean
Node:parent ()
Get the immediate parent of the node.

This method may return nil if no such node exists.

Returns:

    Node or nil
Node:child (index)
Get the child of the node at a given index.

This method may return nil if no such node exists.

Parameters:

  • index integer

Returns:

    Node or nil
Node:field_name_for_child (index)
Get the field name of the child of the node at a given index.

This method may return nil if the node has no field name.

Parameters:

  • index integer

Returns:

    string or nil
Node:child_count ()
Get the number of children the node has.

Returns:

    integer
Node:named_child (index)
Get the named child of the node at a given index.

This method may return nil if no such node exists.

Parameters:

  • index integer

Returns:

    Node or nil
Node:named_child_count ()
Get the number of named children the node has.

Returns:

    integer
Node:child_by_field_id (id)
Get the child of the node by a given field ID.

This method may return nil if no such node exists.

Parameters:

  • id integer

Returns:

    Node or nil
Node:next_sibling ()
Get the next sibling of the node.

This method may return nil if no such node exists.

Returns:

    Node or nil
Node:prev_sibling ()
Get the previous sibling of the node.

This method may return nil if no such node exists.

Returns:

    Node or nil
Node:next_named_sibling ()
Get the next named sibling of the node.

This method may return nil if no such node exists.

Returns:

    Node or nil
Node:prev_named_sibling ()
Get the previous named_sibling of the node.

This method may return nil if no such node exists.

Returns:

    Node or nil
Node:first_child_for_byte (byte)
Get the first child of the node that extends beyond the given byte offset.

This method may return nil if no such node exists.

Parameters:

  • byte integer

Returns:

    Node or nil
Node:first_named_child_for_byte (byte)
Get the first named child of the node that extends beyond the given byte offset.

This method may return nil if no such node exists.

Parameters:

  • byte integer

Returns:

    Node or nil
Node:descendant_for_byte_range (start_byte, end_byte)
Get the smallest node within the node that spans the given range of bytes.

This method may return nil if no such node exists.

Parameters:

  • start_byte integer
  • end_byte integer

Returns:

    Node or nil
Node:descendant_for_point_range (start_point, end_point)
Get the smallest node within the node that spans the given range of Points.

This method may return nil if no such node exists.

Parameters:

  • start_point integer
  • end_point integer

Returns:

    Node or nil
Node:named_descendant_for_byte_range (start_byte, end_byte)
Get the smallest named node within the node that spans the given range of bytes.

This method may return nil if no such node exists.

Parameters:

  • start_byte integer
  • end_byte integer

Returns:

    Node or nil
Node:named_descendant_for_point_range (start_point, end_point)
Get the smallest named node within the node that spans the given range of Points.

This method may return nil if no such node exists.

Parameters:

  • start_point integer
  • end_point integer

Returns:

    Node or nil

Metamethods

Node:__eq (other)
Check equality of two nodes by value.

Parameters:

Returns:

    boolean
Node:__tostring ()
Convert the node to a S-expression.

Returns:

    string
generated by LDoc 1.5.0 Last updated 2024-04-16 14:22:44