authorgravatar for 11367844+lino-levan@users.noreply.github.comLino Le Van <11367844+lino-levan@users.noreply.github.com> 2024-01-19 13:38:35-08:00
committergravatar for 11367844+lino-levan@users.noreply.github.comLino Le Van <11367844+lino-levan@users.noreply.github.com> 2024-01-19 13:38:35-08:00
log4d704b17fea2557ca0341e28445b8631e91a83d2
treecc9768c5b3be12af5ff8b4decd257f4b5b90c8b3
parenta48e3140847de5e8d23909ef8b34f357ed761ed8

chore: move project forward


3 files changed, 37 insertions(+), 15 deletions(-)

crates/cli/src/main.rs+17-14
...@@ -66,7 +66,11 @@ fn main() -> Result<()> {...@@ -66,7 +66,11 @@ fn main() -> Result<()> {
66 let cli = Cli::parse();66 let cli = Cli::parse();
6767
68 match cli.command {68 match cli.command {
69 Commands::Compile { file, stdout, target: _ } => {69 Commands::Compile {
70 file,
71 stdout,
72 target: _,
73 } => {
70 let contents = std::fs::read_to_string(file.clone()).unwrap();74 let contents = std::fs::read_to_string(file.clone()).unwrap();
71 let result = transpile(contents.clone())?;75 let result = transpile(contents.clone())?;
7276
...@@ -85,35 +89,34 @@ fn main() -> Result<()> {...@@ -85,35 +89,34 @@ fn main() -> Result<()> {
8589
86 let rt = get_runtime(&target);90 let rt = get_runtime(&target);
8791
88 match rt.as_str() {92 let command = match rt.as_str() {
89 "deno" => {93 "deno" => {
90 let output = std::process::Command::new("deno")94 std::process::Command::new("deno")
91 .arg("run")95 .arg("run")
92 .arg("-A")96 .arg("-A")
93 .arg(temp_file)97 .arg(temp_file)
94 .output()98 .spawn()
95 .expect("Failed to execute process");99 .expect("Failed to execute process")
96 println!("{}", String::from_utf8_lossy(&output.stdout));
97 }100 }
98 "node" => {101 "node" => {
99 let output = std::process::Command::new("node")102 std::process::Command::new("node")
100 .arg(temp_file)103 .arg(temp_file)
101 .output()104 .spawn()
102 .expect("Failed to execute process");105 .expect("Failed to execute process")
103 println!("{}", String::from_utf8_lossy(&output.stdout));
104 }106 }
105 "bun" => {107 "bun" => {
106 let output = std::process::Command::new("bun")108 std::process::Command::new("bun")
107 .arg("run")109 .arg("run")
108 .arg(temp_file)110 .arg(temp_file)
109 .output()111 .spawn()
110 .expect("Failed to execute process");112 .expect("Failed to execute process")
111 println!("{}", String::from_utf8_lossy(&output.stdout));
112 }113 }
113 _ => {114 _ => {
114 println!("Unknown runtime: {}", target);115 println!("Unknown runtime: {}", target);
115 }116 }
116 }117 }
118
119 command.wait().unwrap();
117 }120 }
118 }121 }
119122
crates/tokenizer/src/lib.rs+14-1
...@@ -138,7 +138,20 @@ pub fn tokenize(content: String) -> Result<Vec<Token>> {...@@ -138,7 +138,20 @@ pub fn tokenize(content: String) -> Result<Vec<Token>> {
138 _ => tokens.push(Token::Equals),138 _ => tokens.push(Token::Equals),
139 },139 },
140 ';' => tokens.push(Token::Semicolon),140 ';' => tokens.push(Token::Semicolon),
141 '>' => tokens.push(Token::Operator(Operator::GreaterThan)),141 '>' => match chars.peek() {
142 Some((_, '=')) => {
143 chars.next();
144 tokens.push(Token::Operator(Operator::GreaterThanOrEquals));
145 }
146 _ => tokens.push(Token::Operator(Operator::GreaterThan)),
147 },
148 '<' => match chars.peek() {
149 Some((_, '=')) => {
150 chars.next();
151 tokens.push(Token::Operator(Operator::LessThanOrEquals));
152 }
153 _ => tokens.push(Token::Operator(Operator::LessThan)),
154 },
142 '+' => tokens.push(Token::Operator(Operator::Add)),155 '+' => tokens.push(Token::Operator(Operator::Add)),
143 '-' => match chars.peek() {156 '-' => match chars.peek() {
144 Some((_, '>')) => {157 Some((_, '>')) => {
crates/util/src/lib.rs+6
...@@ -7,6 +7,9 @@ pub enum Operator {...@@ -7,6 +7,9 @@ pub enum Operator {
7 Power,7 Power,
8 Equals,8 Equals,
9 GreaterThan,9 GreaterThan,
10 LessThan,
11 GreaterThanOrEqual,
12 LessThanOrEqual,
10}13}
1114
12impl Operator {15impl Operator {
...@@ -19,6 +22,9 @@ impl Operator {...@@ -19,6 +22,9 @@ impl Operator {
19 Self::Power => "**",22 Self::Power => "**",
20 Self::Equals => "===",23 Self::Equals => "===",
21 Self::GreaterThan => ">",24 Self::GreaterThan => ">",
25 Self::LessThan => "<",
26 Self::GreaterThanOrEqual => ">=",
27 Self::LessThanOrEqual => "<=",
22 })28 })
23 }29 }
24}30}