summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs2
-rw-r--r--src/parser.rs12
-rw-r--r--src/tokenizer.rs1
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),