diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-28 18:33:20 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-28 18:33:20 +0200 |
commit | 384878703dd1fb97a3d3d60e56e12edb5234ad95 (patch) | |
tree | 75c457dffac419f9976906aa4fd20ce1e2ff5cd4 /crates/rebel-parse | |
parent | f24dabd0897e802d30e8b652f0b633b84c78865b (diff) | |
download | rebel-384878703dd1fb97a3d3d60e56e12edb5234ad95.tar rebel-384878703dd1fb97a3d3d60e56e12edb5234ad95.zip |
rebel-parse, rebel-lang: rename Map types to Struct
As fields can have different types, calling this a struct is more
appropriate, and it frees up the Map name for actual maps that support
dynamic lookup and iteration.
Diffstat (limited to 'crates/rebel-parse')
-rw-r--r-- | crates/rebel-parse/src/ast.rs | 8 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/crates/rebel-parse/src/ast.rs b/crates/rebel-parse/src/ast.rs index 88853d7..490c2f1 100644 --- a/crates/rebel-parse/src/ast.rs +++ b/crates/rebel-parse/src/ast.rs @@ -250,7 +250,7 @@ pub enum Literal<'a> { }, Tuple(Vec<Expr<'a>>), Array(Vec<Expr<'a>>), - Map(Vec<MapEntry<'a>>), + Struct(Vec<StructField<'a>>), } impl<'a> Literal<'a> { @@ -296,9 +296,9 @@ impl<'a> Literal<'a> { } Ok(()) } - Literal::Map(entries) => { + Literal::Struct(entries) => { let mut keys = HashSet::new(); - for MapEntry { key, value } in entries { + for StructField { key, value } in entries { if !keys.insert(key) { return Err(ValidationError::DuplicateKey); } @@ -334,7 +334,7 @@ impl<'a> TryFrom<&token::StrPiece<'a>> for StrPiece<'a> { } #[derive(Debug, Clone, PartialEq, Eq)] -pub struct MapEntry<'a> { +pub struct StructField<'a> { pub key: &'a str, pub value: Expr<'a>, } diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index aaa40d2..c23786b 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -118,13 +118,13 @@ peg::parser! { / p('[') elements:delimited(<expr()>, <p(',')>) p(']') { ast::Literal::Array(elements) } - / p('{') entries:delimited(<map_entry()>, <p(',')>) p('}') { - ast::Literal::Map(entries) + / p('{') entries:delimited(<struct_field()>, <p(',')>) p('}') { + ast::Literal::Struct(entries) } - rule map_entry() -> ast::MapEntry<'a> + rule struct_field() -> ast::StructField<'a> = key:field() p('=') value:expr() { - ast::MapEntry { key: key.name, value } + ast::StructField { key: key.name, value } } rule path() -> ast::Path<'a> |