diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-30 00:07:20 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-30 00:15:43 +0200 |
commit | 3d9d7fd594323d04f77c48ddc3ef2c2b6dc580b7 (patch) | |
tree | 1a5edf19a43cee9ad2543ff55521bd549536e22e /crates/rebel-parse | |
parent | 29ff7f69c654b5f0d3ea5a9d34ea747fab1e2d3d (diff) | |
download | rebel-3d9d7fd594323d04f77c48ddc3ef2c2b6dc580b7.tar rebel-3d9d7fd594323d04f77c48ddc3ef2c2b6dc580b7.zip |
rebel-parse, rebel-lang: remove array length from types
Tuples are sufficient for fixed-length data. For arrays, the small
increase in type safety is not worth the large increase in complexity -
both for the typechecker, and the usage of the language.
The Coerce parameter of unify() is preserved for now, as it may become
useful again for other types like sets.
Diffstat (limited to 'crates/rebel-parse')
-rw-r--r-- | crates/rebel-parse/src/ast/typ.rs | 9 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 15 |
2 files changed, 3 insertions, 21 deletions
diff --git a/crates/rebel-parse/src/ast/typ.rs b/crates/rebel-parse/src/ast/typ.rs index 18ea827..939b67d 100644 --- a/crates/rebel-parse/src/ast/typ.rs +++ b/crates/rebel-parse/src/ast/typ.rs @@ -11,17 +11,10 @@ pub enum Type<'a> { pub enum Literal<'a> { Unit, Tuple(Vec<Type<'a>>), - Array(Box<Type<'a>>, ArrayLen), + Array(Box<Type<'a>>), Struct(Vec<StructField<'a>>), } -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] -pub enum ArrayLen { - Free, - Fixed(u32), - Dynamic, -} - #[derive(Debug, Clone, PartialEq, Eq)] pub struct StructField<'a> { pub name: &'a str, diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index c9fe1e2..b1ac32f 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -72,24 +72,13 @@ peg::parser! { / p('(') elements:(typ() ** p(',')) p(',')? p(')') { typ::Literal::Tuple(elements) } - / p('[') typ:typ() len:array_len() p(']') { - typ::Literal::Array(Box::new(typ), len) + / p('[') typ:typ() p(']') { + typ::Literal::Array(Box::new(typ)) } / p('{') entries:delimited(<struct_field_typ()>, <p(',')>) p('}') { typ::Literal::Struct(entries) } - rule array_len() -> typ::ArrayLen - = p(';') len:number() { ? - Ok(typ::ArrayLen::Fixed(len.try_into().or(Err("Invalid array length"))?)) - } - / p(';') [Token::Ident(name) if *name == "_"] { - typ::ArrayLen::Free - } - / { - typ::ArrayLen::Dynamic - } - rule pat() -> Pat<'a> = path:path() { Pat::Path(path) } |