From 5c557596da3b05658a487a379a25eaa58a1373c8 Mon Sep 17 00:00:00 2001 From: Selimaj Dev Date: Tue, 5 May 2026 14:46:22 +0200 Subject: [PATCH] Refactored Path --- parser/src/ast.rs | 19 ++++++++----------- parser/src/lib.rs | 12 ++++++------ src/codegen.rs | 6 +++--- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/parser/src/ast.rs b/parser/src/ast.rs index cbbc186..7dc69b1 100644 --- a/parser/src/ast.rs +++ b/parser/src/ast.rs @@ -20,22 +20,19 @@ pub enum TypePostfix { #[derive(Debug, Clone, Serialize)] pub enum Attribute { /// #[test] - Path(StaticPath), + Path(Path), /// #[name = "value"] - NameValue { path: StaticPath, value: Literal }, + NameValue { path: Path, value: Literal }, /// #[derive(Clone, Copy)] - List { - path: StaticPath, - items: Vec, - }, + List { path: Path, items: Vec }, } #[derive(Debug, Clone, Serialize)] pub enum TypeExprKind { - Path(StaticPath), - PathParams(StaticPath, Vec), + Path(Path), + PathParams(Path, Vec), Tuple(Vec), } @@ -43,7 +40,7 @@ pub enum TypeExprKind { pub struct TypeExpr(pub TypeExprKind, pub Vec); #[derive(Debug, Clone, Serialize)] -pub struct StaticPath(pub Vec); +pub struct Path(pub Vec); #[derive(Debug, Clone, Serialize)] pub enum BinaryOp { @@ -65,7 +62,7 @@ pub struct TopLevel(pub TopLevelKind, pub Vec); #[derive(Debug, Clone, Serialize)] pub enum TopLevelKind { - Include(StaticPath), + Include(Path), StructDecl { export: bool, name: String, @@ -156,7 +153,7 @@ pub struct ForStmt { #[derive(Debug, Clone, Serialize)] pub enum Expression { Literal(Literal), - Path(StaticPath), + Path(Path), Fix { initial: Box, prefixes: Vec, diff --git a/parser/src/lib.rs b/parser/src/lib.rs index a78b54a..cae599f 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -67,7 +67,7 @@ impl From> for TypeExprKind { match rule { Rule::tuple_type => TypeExprKind::Tuple(inner.map(TypeExpr::from).collect()), Rule::path_type => { - let path = StaticPath::from(inner.next().unwrap()); + let path = Path::from(inner.next().unwrap()); let params = inner.map(TypeExpr::from).collect::>(); if params.len() == 0 { @@ -81,11 +81,11 @@ impl From> for TypeExprKind { } } -impl From> for StaticPath { +impl From> for Path { fn from(pair: pest::iterators::Pair<'_, Rule>) -> Self { match pair.as_rule() { Rule::static_path => { - StaticPath(pair.into_inner().map(|i| i.as_str().to_string()).collect()) + Path(pair.into_inner().map(|i| i.as_str().to_string()).collect()) } _ => unimplemented!("{pair:#?}"), } @@ -132,7 +132,7 @@ impl From> for Attribute { let mut inner = pair.into_inner(); // first item is always the path - let path = StaticPath::from(inner.next().unwrap()); + let path = Path::from(inner.next().unwrap()); // check what comes next match inner.next() { @@ -198,7 +198,7 @@ impl From> for TopLevelKind { let mut inner = pair.into_inner(); match rule { - Rule::import => TopLevelKind::Include(StaticPath::from(inner.next().unwrap())), + Rule::import => TopLevelKind::Include(Path::from(inner.next().unwrap())), Rule::function_decl => { let export = if let Some(first) = inner.peek() { @@ -378,7 +378,7 @@ impl From> for Expression { } } Rule::primary => Expression::from(inner.next().unwrap()), - Rule::static_path => Expression::Path(StaticPath::from(pair)), + Rule::static_path => Expression::Path(Path::from(pair)), Rule::integer => { Expression::Literal(Literal::Int(pair.as_str().parse::().unwrap())) } diff --git a/src/codegen.rs b/src/codegen.rs index 4e1e848..b6038d5 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -1,5 +1,5 @@ use parser::ast::{ - BinaryOp, Block, Expression, IfStmt, Literal, Postfix, Prefix, Statement, StaticPath, TopLevel, + BinaryOp, Block, Expression, IfStmt, Literal, Path, Postfix, Prefix, Statement, TopLevel, TopLevelKind, TypeExpr, TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt, WhileStmt, }; @@ -374,7 +374,7 @@ impl GetRust for VarDecl { } } -impl GetRust for StaticPath { +impl GetRust for Path { fn get_rust(&self) -> String { self.0.join("::") } @@ -389,7 +389,7 @@ impl GetRust for TypePostfix { } } -pub fn get_static_type_path(path: &StaticPath) -> String { +pub fn get_static_type_path(path: &Path) -> String { let rust_path = path.get_rust(); if rust_path == "void" {