From 4d704b17fea2557ca0341e28445b8631e91a83d2 Mon Sep 17 00:00:00 2001 From: Lino Le Van <11367844+lino-levan@users.noreply.github.com> Date: Fri, 19 Jan 2024 13:38:35 -0800 Subject: [PATCH] chore: move project forward --- crates/cli/src/main.rs | 31 +++++++++++++++++-------------- crates/tokenizer/src/lib.rs | 15 ++++++++++++++- crates/util/src/lib.rs | 6 ++++++ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 0e1507c1329d2075ae77dcb59b09b203698b5400..57c2b3be96a87cabd8b8d15e3f93d23187d49b47 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -66,7 +66,11 @@ fn main() -> Result<()> { let cli = Cli::parse(); match cli.command { - Commands::Compile { file, stdout, target: _ } => { + Commands::Compile { + file, + stdout, + target: _, + } => { let contents = std::fs::read_to_string(file.clone()).unwrap(); let result = transpile(contents.clone())?; @@ -85,35 +89,34 @@ fn main() -> Result<()> { let rt = get_runtime(&target); - match rt.as_str() { + let command = match rt.as_str() { "deno" => { - let output = std::process::Command::new("deno") + std::process::Command::new("deno") .arg("run") .arg("-A") .arg(temp_file) - .output() - .expect("Failed to execute process"); - println!("{}", String::from_utf8_lossy(&output.stdout)); + .spawn() + .expect("Failed to execute process") } "node" => { - let output = std::process::Command::new("node") + std::process::Command::new("node") .arg(temp_file) - .output() - .expect("Failed to execute process"); - println!("{}", String::from_utf8_lossy(&output.stdout)); + .spawn() + .expect("Failed to execute process") } "bun" => { - let output = std::process::Command::new("bun") + std::process::Command::new("bun") .arg("run") .arg(temp_file) - .output() - .expect("Failed to execute process"); - println!("{}", String::from_utf8_lossy(&output.stdout)); + .spawn() + .expect("Failed to execute process") } _ => { println!("Unknown runtime: {}", target); } } + + command.wait().unwrap(); } } diff --git a/crates/tokenizer/src/lib.rs b/crates/tokenizer/src/lib.rs index 7e2ae39951da2165efdf34c6e38391072362aaab..4892985ab5abfd83a772b786ba469e88436e6a7c 100644 --- a/crates/tokenizer/src/lib.rs +++ b/crates/tokenizer/src/lib.rs @@ -138,7 +138,20 @@ pub fn tokenize(content: String) -> Result> { _ => tokens.push(Token::Equals), }, ';' => tokens.push(Token::Semicolon), - '>' => tokens.push(Token::Operator(Operator::GreaterThan)), + '>' => match chars.peek() { + Some((_, '=')) => { + chars.next(); + tokens.push(Token::Operator(Operator::GreaterThanOrEquals)); + } + _ => tokens.push(Token::Operator(Operator::GreaterThan)), + }, + '<' => match chars.peek() { + Some((_, '=')) => { + chars.next(); + tokens.push(Token::Operator(Operator::LessThanOrEquals)); + } + _ => tokens.push(Token::Operator(Operator::LessThan)), + }, '+' => tokens.push(Token::Operator(Operator::Add)), '-' => match chars.peek() { Some((_, '>')) => { diff --git a/crates/util/src/lib.rs b/crates/util/src/lib.rs index 28b0b425b3367c040ceb35a390723518c2c1e8b6..b68414ce5400c0bbb3a9f2f536f0fd16f1707a3c 100644 --- a/crates/util/src/lib.rs +++ b/crates/util/src/lib.rs @@ -7,6 +7,9 @@ pub enum Operator { Power, Equals, GreaterThan, + LessThan, + GreaterThanOrEqual, + LessThanOrEqual, } impl Operator { @@ -19,6 +22,9 @@ impl Operator { Self::Power => "**", Self::Equals => "===", Self::GreaterThan => ">", + Self::LessThan => "<", + Self::GreaterThanOrEqual => ">=", + Self::LessThanOrEqual => "<=", }) } } -- 2.54.0