This commit is contained in:
Edgar 2024-02-18 09:58:58 +01:00
parent 962233f269
commit ccc70b9122
No known key found for this signature in database
GPG key ID: 70ADAE8F35904387
5 changed files with 23 additions and 6 deletions

View file

@ -194,7 +194,7 @@ pub struct StructInitField {
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StructInitExpr { pub struct StructInitExpr {
pub name: Ident, pub name: Type,
pub fields: BTreeMap<Ident, StructInitField>, pub fields: BTreeMap<Ident, StructInitField>,
pub span: Span, pub span: Span,
} }

View file

@ -224,7 +224,7 @@ pub enum TypeKind {
FnDef(DefId, Vec<TypeInfo>), // The vec are generic types, not arg types FnDef(DefId, Vec<TypeInfo>), // The vec are generic types, not arg types
Ptr(Box<TypeInfo>), Ptr(Box<TypeInfo>),
Ref(bool, Box<TypeInfo>), Ref(bool, Box<TypeInfo>),
Struct(DefId), Struct(DefId), // todo, add generics
} }
impl TypeKind { impl TypeKind {

View file

@ -496,7 +496,7 @@ fn find_expr_type(builder: &mut BodyBuilder, info: &ast::Expression) -> Option<T
.get_module_body() .get_module_body()
.symbols .symbols
.structs .structs
.get(&info.name.name) .get(&info.name.name.name)
.expect("struct not found"); .expect("struct not found");
ir::TypeKind::Struct(id) ir::TypeKind::Struct(id)
} }
@ -570,7 +570,7 @@ fn lower_expr(
.get_module_body() .get_module_body()
.symbols .symbols
.structs .structs
.get(&info.name.name) .get(&info.name.name.name)
.expect("struct not found"); .expect("struct not found");
let struct_body = builder.ctx.body.structs.get(&id).unwrap().clone(); let struct_body = builder.ctx.body.structs.get(&id).unwrap().clone();
let ty = TypeKind::Struct(id); let ty = TypeKind::Struct(id);

View file

@ -155,6 +155,22 @@ pub(crate) Type: ast::Type = {
}, },
} }
/// For things like A::<T> { a: value }
pub(crate) IdentWithOptionalType: ast::Type = {
<lo:@L> <name:Ident> <hi:@R> => ast::Type {
name,
generics: vec![],
is_ref: None,
span: ast::Span::new(lo, hi),
},
<lo:@L> <name:Ident> "::" "<" <generics:Comma<Type>> ">" <hi:@R> => ast::Type {
name,
generics,
is_ref: None,
span: ast::Span::new(lo, hi),
},
}
pub(crate) PathExpr: ast::PathExpr = { pub(crate) PathExpr: ast::PathExpr = {
<lo:@L> <first:Ident> <extra:PathSegments?> <hi:@R> => ast::PathExpr { <lo:@L> <first:Ident> <extra:PathSegments?> <hi:@R> => ast::PathExpr {
first, first,
@ -381,7 +397,7 @@ pub(crate) StructInitField: (ast::Ident, ast::StructInitField) = {
} }
pub(crate) StructInitExpr: ast::StructInitExpr = { pub(crate) StructInitExpr: ast::StructInitExpr = {
<lo:@L> <name:Ident> "{" <fields:Comma<StructInitField>> "}" <hi:@R> => ast::StructInitExpr { <lo:@L> <name:IdentWithOptionalType> "{" <fields:Comma<StructInitField>> "}" <hi:@R> => ast::StructInitExpr {
name, name,
fields: fields.into_iter().collect(), fields: fields.into_iter().collect(),
span: ast::Span::new(lo, hi), span: ast::Span::new(lo, hi),

1
what Normal file
View file

@ -0,0 +1 @@
Compiling edlang_parser v0.0.1-alpha.7 (/data2/edgar/edlang/lib/edlang_parser)