diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-28 11:25:30 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-28 11:25:30 +0800 |
| commit | f36abead9d948b65abc87c0aea43bbfa987442da (patch) | |
| tree | 60f944d3e956a56aa9f9aba4872d540e4282b2e2 /src/ast.rs | |
| parent | ba8f84cf1bbc1f02187c754eeb9facd375e5885c (diff) | |
fix(parser): If not processed properly
fix(ast): early exit in the wrong place
perf(ast): use metadata instead of direct string cmp
Diffstat (limited to 'src/ast.rs')
| -rw-r--r-- | src/ast.rs | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -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<Expr<'a>>) -> Vec<DepthExpr<'a>> { 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<std::slice::Iter<'_, Expr<'a>>>) -> Vec<E let mut scope_count: u32 = 1; // assume we already entered the scope for i in it { - if scope_count == 0 { - break; - } if let Some(meta) = i.meta { match meta { Metadata::StartScope => { @@ -93,6 +89,9 @@ fn entire_scopes<'a>(it: &mut Peekable<std::slice::Iter<'_, Expr<'a>>>) -> Vec<E } } exprs.push(*i); + if scope_count == 0 { + break; + } } exprs |
