Fix handling of single-node patterns in tree queries
This commit is contained in:
parent
ad3f21b0e5
commit
beb5eec7d9
2 changed files with 33 additions and 1 deletions
|
|
@ -311,6 +311,37 @@ fn test_query_exec_too_many_match_permutations_to_track() {
|
|||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_exec_with_anonymous_tokens() {
|
||||
allocations::record(|| {
|
||||
let language = get_language("javascript");
|
||||
let query = Query::new(
|
||||
language,
|
||||
r#"
|
||||
";" @ punctuation
|
||||
"&&" @ operator
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let source = "foo(a && b);";
|
||||
|
||||
let mut parser = Parser::new();
|
||||
parser.set_language(language).unwrap();
|
||||
let tree = parser.parse(&source, None).unwrap();
|
||||
let context = query.context();
|
||||
let matches = context.exec(tree.root_node());
|
||||
|
||||
assert_eq!(
|
||||
collect_matches(matches, &query, source),
|
||||
&[
|
||||
(1, vec![("operator", "&&")]),
|
||||
(0, vec![("punctuation", ";")]),
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_query_capture_names() {
|
||||
allocations::record(|| {
|
||||
|
|
|
|||
|
|
@ -413,6 +413,7 @@ static TSQueryError ts_query_parse_pattern(
|
|||
.depth = depth,
|
||||
.symbol = symbol,
|
||||
.field = 0,
|
||||
.capture_id = NONE,
|
||||
}));
|
||||
|
||||
if (stream->next != '"') return TSQueryErrorSyntax;
|
||||
|
|
@ -756,7 +757,7 @@ bool ts_query_context_next(TSQueryContext *self) {
|
|||
|
||||
array_push(&self->states, ((QueryState) {
|
||||
.pattern_index = slice->pattern_index,
|
||||
.step_index = slice->step_index + 1,
|
||||
.step_index = slice->step_index,
|
||||
.start_depth = self->depth,
|
||||
.capture_list_id = capture_list_id,
|
||||
.capture_count = 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue