diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-09-28 11:46:19 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-09-28 11:52:48 +0800 |
| commit | 8306b2c99a6af2b22732c612cbd9b202ddc1251f (patch) | |
| tree | e917793726c1ad75f56617e17fc201dbf812ace9 | |
| parent | f36abead9d948b65abc87c0aea43bbfa987442da (diff) | |
fix(parser, tokenizer): println and throw startswith instead of whole str
| -rw-r--r-- | src/main.rs | 2 | ||||
| -rw-r--r-- | src/parser.rs | 12 | ||||
| -rw-r--r-- | src/tokenizer.rs | 1 |
3 files changed, 13 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index baa44b5..ab265d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use java2flowchart::ast::parse; use java2flowchart::parser; fn main() { - let test = "if (first) {firstthen; if (firstthenif) {firstthenifthen} else {firstthenelse}} else {firstelse}"; + let test = "if (first) {firstthen; if (firstthenif) {firstthenifthen} else {firstthenelse}} else {firstelse}println('a')"; println!("{:#?}", parse(&parser::parse(test))); } diff --git a/src/parser.rs b/src/parser.rs index fbeacc5..8e2b63c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -75,7 +75,17 @@ 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) { + if let Some(token) = tokenizer::parse(if let len = s.len() { + if s.starts_with("println") { + "println" + } else if s.starts_with("throw") { + "throw" + } else { + s + } + } else { + s + }) { match token { If(t) => { if let Some(ExprT::Decision((_, Scope::If(If::Else)))) = exp { diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 085c1d3..306770b 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -12,6 +12,7 @@ pub enum Loop { While, } +#[derive(Debug)] pub enum Keyword { If(If), Loop(Loop), |
