Packages

Tree-sitter bindings (nif) for elixir. Currently small subset of the tree-sitter api is supported, but happy to accept merge requests/patches

Current section

Files

Jump to
treesitter_elixir lib treesitter querycursor.ex
Raw

lib/treesitter/querycursor.ex

defmodule TreeSitter.QueryCursor do
@doc """
Create a Stream using the given cursor and query
"""
def to_stream(cursor, query) do
Stream.unfold(cursor, fn cursor ->
case TreeSitter.Nif.query_cursor_next_match(cursor) do
{:error, _} ->
nil
{:ok, {_, pattern_index, nodes}} ->
case TreeSitter.Nif.query_capture_name_for_id(query, pattern_index) do
{:ok, lbl} ->
{{
to_string(lbl),
nodes
}, cursor}
{:error, _} ->
nil
end
end
end)
end
end