Class: TreeSitter::QueryCursor

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_sitter/query_cursor.rb

Overview

A Cursor for Query.

Instance Method Summary collapse

Instance Method Details

#captures(query, node, src) ⇒ Object

Iterate over all of the individual captures in the order that they appear.

This is useful if you don’t care about which pattern matched, and just want a single, ordered sequence of captures.



22
23
24
25
# File 'lib/tree_sitter/query_cursor.rb', line 22

def captures(query, node, src)
  self.exec(query, node)
  QueryCaptures.new(self, query, src)
end

#matches(query, node, src) ⇒ Object

Iterate over all of the matches in the order that they were found.

Each match contains the index of the pattern that matched, and a list of captures. Because multiple patterns can match the same set of nodes, one match may contain captures that appear before some of the captures from a previous match.



12
13
14
15
# File 'lib/tree_sitter/query_cursor.rb', line 12

def matches(query, node, src)
  self.exec(query, node)
  QueryMatches.new(self, query, src)
end