@@ -285,17 +285,17 @@ impl Executor {
285
285
286
286
// Judge what the token is
287
287
if let Ok ( i) = token. parse :: < f64 > ( ) {
288
- // Push number on stack
288
+ // Push number value on the stack
289
289
self . stack . push ( Type :: Number ( i) ) ;
290
290
} else if token == "true" || token == "false" {
291
- // Push bool on stack
291
+ // Push bool value on the stack
292
292
self . stack . push ( Type :: Bool ( token. parse ( ) . unwrap_or ( true ) ) ) ;
293
293
} else if chars[ 0 ] == '(' && chars[ chars. len ( ) - 1 ] == ')' {
294
- // Push string on stack
294
+ // Push string value on the stack
295
295
self . stack
296
296
. push ( Type :: String ( token[ 1 ..token. len ( ) - 1 ] . to_string ( ) ) ) ;
297
297
} else if chars[ 0 ] == '[' && chars[ chars. len ( ) - 1 ] == ']' {
298
- // Push list on stack
298
+ // Push list value on the stack
299
299
let old_len = self . stack . len ( ) ; // length of old stack
300
300
let slice = & token[ 1 ..token. len ( ) - 1 ] ;
301
301
self . evaluate_program ( slice. to_string ( ) ) ;
@@ -306,10 +306,13 @@ impl Executor {
306
306
}
307
307
list. reverse ( ) ; // reverse list
308
308
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:" , "" ) ) )
309
312
} else if let Some ( i) = self . memory . get ( & token) {
310
313
// Push variable's data on stack
311
314
self . stack . push ( i. clone ( ) ) ;
312
- } else if token . contains ( '#' ) {
315
+ } else if chars [ 0 ] == '#' && chars [ chars . len ( ) - 1 ] == '#' {
313
316
// Processing comments
314
317
self . log_print ( format ! ( "* Comment \" {}\" \n " , token. replace( '#' , "" ) ) ) ;
315
318
} else {
@@ -920,6 +923,7 @@ impl Executor {
920
923
"string" => self . stack . push ( Type :: String ( value. get_string ( ) ) ) ,
921
924
"bool" => self . stack . push ( Type :: Bool ( value. get_bool ( ) ) ) ,
922
925
"list" => self . stack . push ( Type :: List ( value. get_list ( ) ) ) ,
926
+ "error" => self . stack . push ( Type :: Error ( value. get_string ( ) ) ) ,
923
927
_ => self . stack . push ( value) ,
924
928
}
925
929
}
0 commit comments