Handle multiple top-level alternations correctly

This commit is contained in:
Hendrik van Antwerpen 2022-01-11 18:06:28 +01:00
parent 8b28f3a8c4
commit ec9b00e5c6
2 changed files with 19 additions and 1 deletions

View file

@ -4003,6 +4003,24 @@ fn test_capture_quantifiers() {
(3, "z", CaptureQuantifier::Zero),
],
},
Row {
description: "multiple alternatives",
language: get_language("javascript"),
pattern: r#"
[
(array (identifier) @x)
(function_declaration name: (identifier)+ @x)
]
[
(array (identifier) @x)
(function_declaration name: (identifier)+ @x)
]
"#,
capture_quantifiers: &[
(0, "x", CaptureQuantifier::OneOrMore),
(1, "x", CaptureQuantifier::OneOrMore),
],
},
];
allocations::record(|| {

View file

@ -1990,7 +1990,7 @@ static TSQueryError ts_query__parse_pattern(
return e;
}
if(start_index == 0) {
if(start_index == starting_step_index) {
capture_quantifiers_replace(capture_quantifiers, &branch_capture_quantifiers);
} else {
capture_quantifiers_join_all(capture_quantifiers, &branch_capture_quantifiers);