From b120e413d21a9d4d1961bb814dff88531a7a4855 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sat, 27 Sep 2025 18:22:50 +0800 Subject: fix(parser): EndScope not preserved chore(parser): simplify --- src/ast.rs | 26 ++++++++++++++++++++++++++ src/parser.rs | 26 +++++++++++++------------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 8b13789..9777d4e 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1 +1,27 @@ +use crate::parser::{self, Expr, ExprT, Scope}; +pub enum DepthExpr<'a> { + Decision { + cond: Box>, + t: Scope, + else_branch: Option>>, + }, + IO(&'a str), + Process(&'a str), +} + +fn parse(vec: Vec) -> Vec { + let exprs = Vec::new(); + + let mut it = vec + .iter() + .peekable(); + + while let Some(e) = it.next() { + if let ExprT::Decision((cond, scope)) = e.expr { + let cond = parser::parse(cond); + } + } + + exprs +} diff --git a/src/parser.rs b/src/parser.rs index 544c296..1475fce 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -41,23 +41,23 @@ pub fn delimit(s: &str) -> SplitWithMetadata<'_> { .char_indices() .next_back() { - let body = if ch == ';' || ch == '{' || ch == '}' { - part[..i].trim() - } else { - part.trim() - }; - if !body.is_empty() { - acc.push((body, None)); - } + acc.push(( + if ch == ';' || ch == '{' || ch == '}' { + part[..i].trim() + } else { + part.trim() + }, + None, + )); match ch { '{' => { - if let Some(last) = acc.last_mut() { - last.1 = Some(Metadata::StartScope); + if let Some((_, meta)) = acc.last_mut() { + *meta = Some(Metadata::StartScope); } } '}' => { - if let Some(last) = acc.last_mut() { - last.1 = Some(Metadata::EndScope); + if let Some((_, meta)) = acc.last_mut() { + *meta = Some(Metadata::EndScope); } } _ => {} @@ -92,7 +92,7 @@ pub fn process(strs: SplitWithMetadata<'_>) -> Vec> { }), None => exprs.push(Expr { expr: ExprT::Process(str), - meta: None, + meta, }), } } -- cgit v1.2.3