refactoring the grammar

This commit is contained in:
2026-05-05 14:12:49 +02:00
parent f4a14789c3
commit 1d00667b18
2 changed files with 17 additions and 12 deletions
+12 -4
View File
@@ -1,6 +1,7 @@
use parser::ast::{
BinaryOp, Block, Expression, IfStmt, Literal, Postfix, Prefix, Statement, StaticPath, TopLevel,
TypeExpr, TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, WhileStmt,
TopLevelKind, TypeExpr, TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt,
WhileStmt,
};
// ---------------------------------------------------------------------------
@@ -226,13 +227,19 @@ impl ToRust for Block {
}
impl ToRust for TopLevel {
fn to_rust(&self, cg: &mut RustCodegen) {
self.0.to_rust(cg);
}
}
impl ToRust for TopLevelKind {
fn to_rust(&self, cg: &mut RustCodegen) {
match self {
TopLevel::Include(path) => {
Self::Include(path) => {
cg.addln(&format!("use {};", path.get_rust()));
}
TopLevel::StructDecl {
Self::StructDecl {
export,
name,
fields,
@@ -250,7 +257,7 @@ impl ToRust for TopLevel {
cg.addln("}\n");
}
TopLevel::FunctionDecl {
Self::FunctionDecl {
export,
name,
params,
@@ -278,6 +285,7 @@ impl ToRust for TopLevel {
cg.indent -= 1;
cg.addln("}\n");
}
Self::EOI => {}
}
}
}