query-accessors {treesitter} | R Documentation |
Query accessors
Description
-
query_pattern_count()
returns the number of patterns in a query. -
query_capture_count()
returns the number of captures in a query. -
query_string_count()
returns the number of string literals in a query. -
query_start_byte_for_pattern()
returns the byte where thei
th pattern starts in the querysource
.
Usage
query_pattern_count(x)
query_capture_count(x)
query_string_count(x)
query_start_byte_for_pattern(x, i)
Arguments
x |
A query. |
i |
The |
Value
-
query_pattern_count()
,query_capture_count()
, andquery_string_count()
return a single double count value. -
query_start_byte_for_pattern()
returns a single double for the start byte if there was ani
th pattern, otherwise it returnsNA
.
Examples
source <- '(binary_operator
lhs: (identifier) @lhs
operator: _ @operator
rhs: (function_definition) @rhs
(#eq? @lhs "fn")
)'
language <- treesitter.r::language()
query <- query(language, source)
query_pattern_count(query)
query_capture_count(query)
query_string_count(query)
text <- "
fn <- function() {}
fn2 <- function() {}
fn <- 5
fn <- function(a, b, c) { a + b + c }
"
parser <- parser(language)
tree <- parser_parse(parser, text)
node <- tree_root_node(tree)
query_matches(query, node)
[Package treesitter version 0.1.0 Index]