Skip to content

Commit

Permalink
[compiler][hir] Compiler support for if let destructuring (#1114)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamChou19815 authored Oct 22, 2023
1 parent 37b39d2 commit 105cda9
Show file tree
Hide file tree
Showing 4 changed files with 411 additions and 45 deletions.
20 changes: 9 additions & 11 deletions crates/samlang-core/src/ast/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ impl Id {
}

pub(crate) mod pattern {
use std::collections::HashSet;

use samlang_heap::PStr;

use super::{Id, Location};
use samlang_heap::PStr;
use std::collections::BTreeMap;

#[derive(Clone, PartialEq, Eq)]
pub(crate) struct TuplePatternElement<Base: Clone, T: Clone> {
Expand Down Expand Up @@ -290,13 +288,13 @@ pub(crate) mod pattern {
}
}

pub(crate) fn bindings(&self) -> HashSet<PStr> {
let mut set = HashSet::new();
self.collect_bindings(&mut set);
set
pub(crate) fn bindings(&self) -> BTreeMap<PStr, &T> {
let mut map = BTreeMap::new();
self.collect_bindings(&mut map);
map
}

fn collect_bindings(&self, collector: &mut HashSet<PStr>) {
fn collect_bindings<'a>(&'a self, collector: &mut BTreeMap<PStr, &'a T>) {
match self {
Self::Tuple(_, ps) => {
for nested in ps {
Expand All @@ -313,8 +311,8 @@ pub(crate) mod pattern {
p.collect_bindings(collector)
}
}
Self::Id(Id { name, .. }, _) => {
collector.insert(*name);
Self::Id(Id { name, .. }, t) => {
collector.insert(*name, t);
}
Self::Wildcard(_) => {}
}
Expand Down
Loading

0 comments on commit 105cda9

Please sign in to comment.