Refactoring variable definition parsing

This commit is contained in:
2026-05-04 06:59:31 +02:00
parent 4dcb3fae7b
commit a4c1f787ff
4 changed files with 92 additions and 53 deletions
+12 -4
View File
@@ -3,7 +3,10 @@ use std::collections::HashMap;
use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct ParamList(pub HashMap<String, (bool, TypeExpr)>);
pub struct FieldList(pub HashMap<String, (bool, TypeExpr)>);
#[derive(Debug, Clone, Serialize)]
pub struct ParamList(pub Vec<VarDecl>);
#[derive(Debug, Clone, Serialize)]
pub struct Block(pub Vec<Statement>);
@@ -34,7 +37,7 @@ pub enum TopLevel {
StructDecl {
export: bool,
name: String,
fields: ParamList,
fields: FieldList,
},
FunctionDecl {
export: bool,
@@ -71,13 +74,18 @@ pub enum Statement {
}
#[derive(Debug, Clone, Serialize)]
pub struct VarDeclStmt {
pub struct VarDecl {
pub mutable: bool,
pub name: String,
pub init: Option<Expression>,
pub type_: Option<TypeExpr>,
}
#[derive(Debug, Clone, Serialize)]
pub struct VarDeclStmt {
pub decl: VarDecl,
pub init: Option<Expression>,
}
#[derive(Debug, Clone, Serialize)]
pub struct VarAssignStmt {
pub target: Expression,