summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2024-05-05 20:57:34 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2024-05-05 21:42:40 +0200
commit6718f07f55b742c66b1ab0ed2d8e32d05b2a6f22 (patch)
tree56bcec8afd482ce9ce30f354469afe01916e4d55
parent29ad178117be9f7e3a659c860aafe21525d906dd (diff)
downloadrebel-6718f07f55b742c66b1ab0ed2d8e32d05b2a6f22.tar
rebel-6718f07f55b742c66b1ab0ed2d8e32d05b2a6f22.zip
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.
-rw-r--r--crates/rebel-lang/src/typing.rs2
-rw-r--r--crates/rebel-lang/src/value.rs2
-rw-r--r--crates/rebel-parse/src/grammar/recipe.rs6
-rw-r--r--crates/rebel-parse/src/grammar/tokenize.rs1
-rw-r--r--crates/rebel-parse/src/token.rs1
-rw-r--r--examples/recipes/gmp/build.recipe2
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(<struct_field_typ()>, <p(',')>) p('}') {
+ / p('{') entries:delimited(<struct_field_typ()>, <p(',')>) 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(<map_entry()>, <p(',')>) p('}') {
expr::Literal::Map(entries)
}
- / [Token::Keyword(Keyword::Struct)] p('{') entries:delimited(<struct_field()>, <p(',')>) p('}') {
+ / p('{') entries:delimited(<struct_field()>, <p(',')>) 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)],
};