summaryrefslogtreecommitdiff
path: root/src/parser.rs
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-09-28 11:25:30 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-09-28 11:25:30 +0800
commitf36abead9d948b65abc87c0aea43bbfa987442da (patch)
tree60f944d3e956a56aa9f9aba4872d540e4282b2e2 /src/parser.rs
parentba8f84cf1bbc1f02187c754eeb9facd375e5885c (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/parser.rs')
-rw-r--r--src/parser.rs15
1 files changed, 10 insertions, 5 deletions
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<Expr<'_>> {
// 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)),
}
}
}