Skip to content

Commit 60c1505

Browse files
author
梶塚太智
committed
Update main.rs
It became can using error value as literal
1 parent 7cc2b60 commit 60c1505

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,17 +285,17 @@ impl Executor {
285285

286286
// Judge what the token is
287287
if let Ok(i) = token.parse::<f64>() {
288-
// Push number on stack
288+
// Push number value on the stack
289289
self.stack.push(Type::Number(i));
290290
} else if token == "true" || token == "false" {
291-
// Push bool on stack
291+
// Push bool value on the stack
292292
self.stack.push(Type::Bool(token.parse().unwrap_or(true)));
293293
} else if chars[0] == '(' && chars[chars.len() - 1] == ')' {
294-
// Push string on stack
294+
// Push string value on the stack
295295
self.stack
296296
.push(Type::String(token[1..token.len() - 1].to_string()));
297297
} else if chars[0] == '[' && chars[chars.len() - 1] == ']' {
298-
// Push list on stack
298+
// Push list value on the stack
299299
let old_len = self.stack.len(); // length of old stack
300300
let slice = &token[1..token.len() - 1];
301301
self.evaluate_program(slice.to_string());
@@ -306,10 +306,13 @@ impl Executor {
306306
}
307307
list.reverse(); // reverse list
308308
self.stack.push(Type::List(list));
309+
} else if token.starts_with("error:") {
310+
// Push error value on the stack
311+
self.stack.push(Type::Error(token.replace("error:", "")))
309312
} else if let Some(i) = self.memory.get(&token) {
310313
// Push variable's data on stack
311314
self.stack.push(i.clone());
312-
} else if token.contains('#') {
315+
} else if chars[0] == '#' && chars[chars.len() - 1] == '#' {
313316
// Processing comments
314317
self.log_print(format!("* Comment \"{}\"\n", token.replace('#', "")));
315318
} else {
@@ -920,6 +923,7 @@ impl Executor {
920923
"string" => self.stack.push(Type::String(value.get_string())),
921924
"bool" => self.stack.push(Type::Bool(value.get_bool())),
922925
"list" => self.stack.push(Type::List(value.get_list())),
926+
"error" => self.stack.push(Type::Error(value.get_string())),
923927
_ => self.stack.push(value),
924928
}
925929
}

0 commit comments

Comments
 (0)