From f36abead9d948b65abc87c0aea43bbfa987442da Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Sun, 28 Sep 2025 11:25:30 +0800 Subject: fix(parser): If not processed properly fix(ast): early exit in the wrong place perf(ast): use metadata instead of direct string cmp --- src/ast.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/ast.rs') diff --git a/src/ast.rs b/src/ast.rs index 472172b..a23c688 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1,3 +1,4 @@ +use crate::tokenizer::If; use std::iter::Peekable; use crate::parser::{Expr, ExprT, Metadata, Scope}; @@ -30,10 +31,8 @@ pub fn parse<'a>(vec: &Vec>) -> Vec> { let else_branch = if let Some(n) = it.peek() { match n.expr { - ExprT::Decision((s, _)) => { - if s.trim_start() - .starts_with("else") - { + ExprT::Decision((_, scope)) => { + if let Scope::If(If::Else) = scope { it.next(); Some(Box::new(parse(&entire_scopes(&mut it)))) } else { @@ -75,9 +74,6 @@ fn entire_scopes<'a>(it: &mut Peekable>>) -> Vec { @@ -93,6 +89,9 @@ fn entire_scopes<'a>(it: &mut Peekable>>) -> Vec