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/parser.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/parser.rs') diff --git a/src/parser.rs b/src/parser.rs index 87d2470..fbeacc5 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -76,11 +76,16 @@ pub fn process(strs: SplitWithMetadata<'_>) -> Vec> { // TODO: fix one line if else as not delimited by {} for s in str.split_whitespace() { if let Some(token) = tokenizer::parse(s) { - exp = match token { - If(t) => Some(ExprT::Decision((str, Scope::If(t.to_owned())))), - Loop(t) => Some(ExprT::Decision((str, Scope::Loop(t.to_owned())))), - Throw => Some(ExprT::IO(str)), - IO => Some(ExprT::IO(str)), + match token { + If(t) => { + if let Some(ExprT::Decision((_, Scope::If(If::Else)))) = exp { + } else { + exp = Some(ExprT::Decision((str, Scope::If(t.to_owned())))); + } + } + Loop(t) => exp = Some(ExprT::Decision((str, Scope::Loop(t.to_owned())))), + Throw => exp = Some(ExprT::IO(str)), + IO => exp = Some(ExprT::IO(str)), } } } -- cgit v1.2.3