From 6718f07f55b742c66b1ab0ed2d8e32d05b2a6f22 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 5 May 2024 20:57:34 +0200 Subject: rebel-parse, rebel-lang: remove struct keyword again In addition, the order of match rules is adjusted to check structs before blocks for improved performance in common cases - structs are likely more frequent than block expressions in most code, and the struct rule can be rejected quickly. --- crates/rebel-lang/src/typing.rs | 2 +- crates/rebel-lang/src/value.rs | 2 +- crates/rebel-parse/src/grammar/recipe.rs | 6 +++--- crates/rebel-parse/src/grammar/tokenize.rs | 1 - crates/rebel-parse/src/token.rs | 1 - examples/recipes/gmp/build.recipe | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/rebel-lang/src/typing.rs b/crates/rebel-lang/src/typing.rs index 5e9998d..bd6ed71 100644 --- a/crates/rebel-lang/src/typing.rs +++ b/crates/rebel-lang/src/typing.rs @@ -673,7 +673,7 @@ impl Display for Type { return f.write_str("()"); } let mut first = true; - f.write_str("struct {")?; + f.write_str("{")?; for (key, typ) in entries { if !first { f.write_str(", ")?; diff --git a/crates/rebel-lang/src/value.rs b/crates/rebel-lang/src/value.rs index 81b9c41..4d7e587 100644 --- a/crates/rebel-lang/src/value.rs +++ b/crates/rebel-lang/src/value.rs @@ -588,7 +588,7 @@ impl Display for Value { return f.write_str("()"); } let mut first = true; - f.write_str("struct {")?; + f.write_str("{")?; for (key, value) in entries { if !first { f.write_str(", ")?; diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index 96ef61d..1c417d3 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -78,7 +78,7 @@ peg::parser! { / [Token::Keyword(Keyword::Map)] p('{') key:typ() p2('=', '>') value:typ() p('}') { typ::Literal::Map(Box::new(key), Box::new(value)) } - / [Token::Keyword(Keyword::Struct)] p('{') entries:delimited(, ) p('}') { + / p('{') entries:delimited(, ) p('}') { typ::Literal::Struct(entries) } @@ -147,8 +147,8 @@ peg::parser! { { Expr::IfElse { if_blocks, else_block } } - / p('{') block:block() p('}') { Expr::Block(block) } / lit:literal() { Expr::Literal(lit) } + / p('{') block:block() p('}') { Expr::Block(block) } / path:path() { Expr::Path(path) } rule cond_block() -> (Expr<'a>, ast::Block<'a>) @@ -184,7 +184,7 @@ peg::parser! { / [Token::Keyword(Keyword::Map)] p('{') entries:delimited(, ) p('}') { expr::Literal::Map(entries) } - / [Token::Keyword(Keyword::Struct)] p('{') entries:delimited(, ) p('}') { + / p('{') entries:delimited(, ) p('}') { expr::Literal::Struct(entries) } diff --git a/crates/rebel-parse/src/grammar/tokenize.rs b/crates/rebel-parse/src/grammar/tokenize.rs index a4e25b5..551f157 100644 --- a/crates/rebel-parse/src/grammar/tokenize.rs +++ b/crates/rebel-parse/src/grammar/tokenize.rs @@ -13,7 +13,6 @@ static KEYWORDS: phf::Map<&'static str, Keyword> = phf::phf_map! { "mut" => Keyword::Mut, "recipe" => Keyword::Recipe, "set" => Keyword::Set, - "struct" => Keyword::Struct, "task" => Keyword::Task, "true" => Keyword::True, }; diff --git a/crates/rebel-parse/src/token.rs b/crates/rebel-parse/src/token.rs index 59582c3..c86d13e 100644 --- a/crates/rebel-parse/src/token.rs +++ b/crates/rebel-parse/src/token.rs @@ -19,7 +19,6 @@ pub enum Keyword { Mut, Recipe, Set, - Struct, Task, True, } diff --git a/examples/recipes/gmp/build.recipe b/examples/recipes/gmp/build.recipe index 34fb10b..19a25f6 100644 --- a/examples/recipes/gmp/build.recipe +++ b/examples/recipes/gmp/build.recipe @@ -54,7 +54,7 @@ task compile(host: Platform) { task install(host: Platform) { task.parent = compile(host); - task.output["default"] = struct { + task.output["default"] = { runtime_depends: [host_depend(toolchain::depends)], }; -- cgit v1.2.3