From e336462a5acd23f5e42234b7ad9345bbd1258c54 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 8 Apr 2024 14:02:32 +0200 Subject: [PATCH] Fix nested bindings in queries (#927) Cherry-picked from https://github.com/NomicFoundation/slang/pull/884/commits/bb9238437941400b84a8b40f0d9ef953f26611f1. We need this for 0.14 to allow for more interesting queries for https://github.com/NomicFoundation/hardhat-vscode/issues/547. Co-authored-by: Antony Blakey --- crates/codegen/parser/runtime/src/query/engine.rs | 1 + .../slang_solidity/src/generated/query/engine.rs | 1 + .../slang_testlang/src/generated/query/engine.rs | 1 + .../outputs/cargo/tests/src/query/engine_tests.rs | 11 +++++++++++ 4 files changed, 14 insertions(+) diff --git a/crates/codegen/parser/runtime/src/query/engine.rs b/crates/codegen/parser/runtime/src/query/engine.rs index cb41f382d..7be82f413 100644 --- a/crates/codegen/parser/runtime/src/query/engine.rs +++ b/crates/codegen/parser/runtime/src/query/engine.rs @@ -181,6 +181,7 @@ impl Combinator for BindingCombinator { .entry(self.matcher.name.clone()) .or_default() .push(self.cursor.clone()); + self.child.accumulate_bindings(bindings); } } diff --git a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs index 6cdb482c5..63ea8aa85 100644 --- a/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs +++ b/crates/solidity/outputs/cargo/slang_solidity/src/generated/query/engine.rs @@ -183,6 +183,7 @@ impl Combinator for BindingCombinator { .entry(self.matcher.name.clone()) .or_default() .push(self.cursor.clone()); + self.child.accumulate_bindings(bindings); } } diff --git a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs index 6cdb482c5..63ea8aa85 100644 --- a/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs +++ b/crates/testlang/outputs/cargo/slang_testlang/src/generated/query/engine.rs @@ -183,6 +183,7 @@ impl Combinator for BindingCombinator { .entry(self.matcher.name.clone()) .or_default() .push(self.cursor.clone()); + self.child.accumulate_bindings(bindings); } } diff --git a/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs b/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs index 2d406bf0d..e102eedef 100644 --- a/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs +++ b/crates/testlang/outputs/cargo/tests/src/query/engine_tests.rs @@ -250,3 +250,14 @@ fn test_optional() { }, ); } + +#[test] +fn test_nested() { + run_query_test( + &common_test_tree(), + "@root [TreeNode ... @z [DelimitedIdentifier] [_] ]", + query_results! { + {root: ["ABCDE"], z: ["C"]} + }, + ); +}