diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2024-05-22 01:46:12 +0100 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2024-05-22 01:46:12 +0100 |
commit | 8bed45f4dcce5fb9396d0b662d795eac3c7d0e2f (patch) | |
tree | 9bb0df652949b1ab2d10d1fcf610a5ea9b3c1d36 | |
parent | a9bcee7733bf5fc792b66a2290b58459e8c4a65a (diff) |
Define an id_map helper
-rw-r--r-- | src/parse/syntax.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/parse/syntax.rs b/src/parse/syntax.rs index bdde5934d..4958d118c 100644 --- a/src/parse/syntax.rs +++ b/src/parse/syntax.rs @@ -364,6 +364,30 @@ pub(crate) fn init_all_info<'a>(lhs_roots: &[&'a Syntax<'a>], rhs_roots: &[&'a S init_next_prev(rhs_roots); } +pub(crate) fn build_id_map<'a>( + lhs_roots: &[&'a Syntax<'a>], + rhs_roots: &[&'a Syntax<'a>], +) -> DftHashMap<NonZeroU32, &'a Syntax<'a>> { + let mut id_map = DftHashMap::default(); + build_id_map_(lhs_roots, &mut id_map); + build_id_map_(rhs_roots, &mut id_map); + + id_map +} + +fn build_id_map_<'a>( + nodes: &[&'a Syntax<'a>], + id_map: &mut DftHashMap<NonZeroU32, &'a Syntax<'a>>, +) { + for node in nodes { + id_map.insert(node.id(), *node); + + if let List { children, .. } = node { + build_id_map_(children, id_map); + } + } +} + fn init_info<'a>(lhs_roots: &[&'a Syntax<'a>], rhs_roots: &[&'a Syntax<'a>]) { let mut id = NonZeroU32::new(1).unwrap(); init_info_on_side(lhs_roots, &mut id); |