From 384878703dd1fb97a3d3d60e56e12edb5234ad95 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 28 Apr 2024 18:33:20 +0200 Subject: 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. --- crates/rebel-parse/src/ast.rs | 8 ++++---- crates/rebel-parse/src/grammar/recipe.rs | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'crates/rebel-parse') 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>), Array(Vec>), - Map(Vec>), + Struct(Vec>), } 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(, ) p(']') { ast::Literal::Array(elements) } - / p('{') entries:delimited(, ) p('}') { - ast::Literal::Map(entries) + / p('{') entries:delimited(, ) 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> -- cgit v1.2.3