Skip to content

Commit

Permalink
Allow map_field_exact in map type
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
alanz committed May 20, 2021
1 parent fa61134 commit 76ea09e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/ast/ty.rs
Expand Up @@ -205,13 +205,19 @@ impl Map {
#[derive(Debug, Clone)]
pub struct MapPair {
pub line: ast::LineNum,
pub is_assoc: bool,
pub key: Type,
pub value: Type,
}
impl_node!(MapPair);
impl MapPair {
pub fn new(line: ast::LineNum, key: Type, value: Type) -> Self {
MapPair { line, key, value }
pub fn new(line: ast::LineNum, is_assoc: bool, key: Type, value: Type) -> Self {
MapPair {
line,
is_assoc,
key,
value,
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/format/raw_abstract_v1.rs
Expand Up @@ -609,8 +609,14 @@ impl<'a> FromTerm<'a> for ty::Map {
}
impl<'a> FromTerm<'a> for ty::MapPair {
fn try_from(term: &'a eetf::Term) -> Result<Self, Unmatch<'a>> {
term.as_match(("type", I32, "map_field_assoc", FixList((ty(), ty()))))
.map(|(_, line, _, (key, value))| Self::new(line, key, value))
term.as_match(Or((
("type", I32, "map_field_exact", FixList((ty(), ty()))),
("type", I32, "map_field_assoc", FixList((ty(), ty()))),
)))
.map(|result| match result {
Union2::A((_, line, _, (key, value))) => Self::new(line, false, key, value),
Union2::B((_, line, _, (key, value))) => Self::new(line, true, key, value),
})
}
}
impl<'a> FromTerm<'a> for ty::Range {
Expand Down

0 comments on commit 76ea09e

Please sign in to comment.