Added other struct types #117

This commit is contained in:
2026-07-14 07:32:42 +02:00
parent d834ff595d
commit 5079b10819
5 changed files with 53 additions and 7 deletions
+6
View File
@@ -59,6 +59,12 @@ pub enum TopLevelKind {
generics: GenericsDecl,
fields: Vec<Spanned<FieldDecl>>,
},
StructDeclTupleUnit {
visibility: Visibility,
name: Identifier,
generics: GenericsDecl,
unit: Option<Vec<Spanned<TypeExpr>>>,
},
FunctionDecl(FunctionDecl),
ClassDecl {
visibility: Visibility,
+2 -6
View File
@@ -288,11 +288,7 @@ struct_decl = {
}
tuple_struct_decl = {
visibility? ~ "struct" ~ identifier ~ generics_decl? ~ tuple_type ~ ";"
}
empty_struct_decl = {
visibility? ~ "struct" ~ identifier ~ generics_decl? ~ ";"
visibility? ~ "struct" ~ identifier ~ generics_decl? ~ tuple_type? ~ ";"
}
// ======================================================
@@ -407,7 +403,7 @@ type_alias = { "type" ~ identifier ~ generics_decl? ~ "=" ~ type_expr ~ ";" }
top_level = {
mod_attribute
| (attributes ~ (include_global | include_local | include_use_global | import | impl_for_decl | impl_decl | trait_decl | struct_decl | tuple_struct_decl | empty_struct_decl | enum_decl | class_decl | declare_module | function_decl | const_decl | static_decl | type_alias))
| (attributes ~ (include_global | include_local | include_use_global | import | impl_for_decl | impl_decl | trait_decl | struct_decl | tuple_struct_decl | enum_decl | class_decl | declare_module | function_decl | const_decl | static_decl | type_alias))
}
// ======================================================
+15 -1
View File
@@ -57,6 +57,21 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
fields: collect_recovered(inner.next().unwrap().into_inner())?,
}),
Rule::tuple_struct_decl => Ok(TopLevelKind::StructDeclTupleUnit {
visibility: Visibility::try_from(&mut inner)?,
name: inner.next().unwrap().try_into()?,
generics: consume_rule(&mut inner, Rule::generics_decl)
.map(GenericsDecl::try_from)
.transpose()
.map(|v| v.unwrap_or_default())?,
unit: consume_rule(&mut inner, Rule::tuple_type)
.map(|v| collect_recovered(v.into_inner()))
.transpose()?,
}),
Rule::class_decl => Ok(TopLevelKind::ClassDecl {
visibility: Visibility::try_from(&mut inner)?,
@@ -147,7 +162,6 @@ impl<'a> TryFrom<pest::iterators::Pair<'a, Rule>> for TopLevelKind {
.unwrap()
.to_string(),
)),
_ => AstError::bug_unimplemented(pair),
}
}