From ccc70b91226e08da93c9cb7e339b7bf92f467d25 Mon Sep 17 00:00:00 2001 From: Edgar Luque Date: Sun, 18 Feb 2024 09:58:58 +0100 Subject: [PATCH] nice --- lib/edlang_ast/src/lib.rs | 2 +- lib/edlang_ir/src/lib.rs | 2 +- lib/edlang_lowering/src/lib.rs | 4 ++-- lib/edlang_parser/src/grammar.lalrpop | 20 ++++++++++++++++++-- what | 1 + 5 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 what diff --git a/lib/edlang_ast/src/lib.rs b/lib/edlang_ast/src/lib.rs index 7e41aadad..4597c58d8 100644 --- a/lib/edlang_ast/src/lib.rs +++ b/lib/edlang_ast/src/lib.rs @@ -194,7 +194,7 @@ pub struct StructInitField { #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct StructInitExpr { - pub name: Ident, + pub name: Type, pub fields: BTreeMap, pub span: Span, } diff --git a/lib/edlang_ir/src/lib.rs b/lib/edlang_ir/src/lib.rs index e2f08abc4..0b320c61d 100644 --- a/lib/edlang_ir/src/lib.rs +++ b/lib/edlang_ir/src/lib.rs @@ -224,7 +224,7 @@ pub enum TypeKind { FnDef(DefId, Vec), // The vec are generic types, not arg types Ptr(Box), Ref(bool, Box), - Struct(DefId), + Struct(DefId), // todo, add generics } impl TypeKind { diff --git a/lib/edlang_lowering/src/lib.rs b/lib/edlang_lowering/src/lib.rs index 9ead97d09..259ca9c04 100644 --- a/lib/edlang_lowering/src/lib.rs +++ b/lib/edlang_lowering/src/lib.rs @@ -496,7 +496,7 @@ fn find_expr_type(builder: &mut BodyBuilder, info: &ast::Expression) -> Option { a: value } +pub(crate) IdentWithOptionalType: ast::Type = { + => ast::Type { + name, + generics: vec![], + is_ref: None, + span: ast::Span::new(lo, hi), + }, + "::" "<" > ">" => ast::Type { + name, + generics, + is_ref: None, + span: ast::Span::new(lo, hi), + }, +} + pub(crate) PathExpr: ast::PathExpr = { => ast::PathExpr { first, @@ -212,7 +228,7 @@ pub(crate) LetStmt: ast::LetStmt = { value, span: ast::Span::new(lo, hi), }, - "let" ":" "=" => ast::LetStmt { + "let" ":" "=" => ast::LetStmt { is_mut: is_mut.is_some(), name, r#type: target_type, @@ -381,7 +397,7 @@ pub(crate) StructInitField: (ast::Ident, ast::StructInitField) = { } pub(crate) StructInitExpr: ast::StructInitExpr = { - "{" > "}" => ast::StructInitExpr { + "{" > "}" => ast::StructInitExpr { name, fields: fields.into_iter().collect(), span: ast::Span::new(lo, hi), diff --git a/what b/what new file mode 100644 index 000000000..6121cde6e --- /dev/null +++ b/what @@ -0,0 +1 @@ + Compiling edlang_parser v0.0.1-alpha.7 (/data2/edgar/edlang/lib/edlang_parser)