From ec9b00e5c684bbfc6d107769a6da403db830dd54 Mon Sep 17 00:00:00 2001 From: Hendrik van Antwerpen Date: Tue, 11 Jan 2022 18:06:28 +0100 Subject: [PATCH] Handle multiple top-level alternations correctly --- cli/src/tests/query_test.rs | 18 ++++++++++++++++++ lib/src/query.c | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cli/src/tests/query_test.rs b/cli/src/tests/query_test.rs index 0513f3a1..6634c62f 100644 --- a/cli/src/tests/query_test.rs +++ b/cli/src/tests/query_test.rs @@ -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(|| { diff --git a/lib/src/query.c b/lib/src/query.c index 7d2bd8cf..af393572 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -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);