@@ -244,65 +244,44 @@ impl Executor {
244
244
245
245
let mut syntax = Vec :: new ( ) ; // Token string
246
246
let mut buffer = String :: new ( ) ; // Temporary storage
247
- let mut brackets = 0 ; // String's nest structure
248
- let mut parentheses = 0 ; // List's nest structure
249
- let mut hash = false ; // Is it Comment
250
- let mut escape = false ; // Flag to indicate next character is escaped
247
+ let mut in_brackets = 0 ; // String's nest structure
248
+ let mut in_parentheses = 0 ; // List's nest structure
249
+ let mut in_hash = false ; // Is it Comment
251
250
252
251
for c in code. chars ( ) {
253
252
match c {
254
- '\\' if !escape => {
255
- escape = true ;
256
- }
257
- '(' if !hash && !escape => {
258
- brackets += 1 ;
253
+ '(' => {
254
+ in_brackets += 1 ;
259
255
buffer. push ( '(' ) ;
260
256
}
261
- ')' if !hash && !escape => {
262
- brackets -= 1 ;
257
+ ')' => {
258
+ in_brackets -= 1 ;
263
259
buffer. push ( ')' ) ;
264
260
}
265
- '#' if !hash && !escape => {
266
- hash = true ;
261
+ '#' if !in_hash => {
262
+ in_hash = true ;
267
263
buffer. push ( '#' ) ;
268
264
}
269
- '#' if hash && !escape => {
270
- hash = false ;
265
+ '#' if in_hash => {
266
+ in_hash = false ;
271
267
buffer. push ( '#' ) ;
272
268
}
273
- '[' if !hash && brackets == 0 && !escape => {
274
- parentheses += 1 ;
269
+ '[' if in_brackets == 0 => {
270
+ in_parentheses += 1 ;
275
271
buffer. push ( '[' ) ;
276
272
}
277
- ']' if !hash && brackets == 0 && !escape => {
278
- parentheses -= 1 ;
273
+ ']' if in_brackets == 0 => {
274
+ in_parentheses -= 1 ;
279
275
buffer. push ( ']' ) ;
280
276
}
281
- ' ' if !hash && parentheses == 0 && brackets == 0 && !escape => {
277
+ ' ' if !in_hash && in_parentheses == 0 && in_brackets == 0 => {
282
278
if !buffer. is_empty ( ) {
283
279
syntax. push ( buffer. clone ( ) ) ;
284
280
buffer. clear ( ) ;
285
281
}
286
282
}
287
283
_ => {
288
- if parentheses == 0 && brackets == 0 && !hash {
289
- if escape {
290
- match c {
291
- 'n' => buffer. push_str ( "\\ n" ) ,
292
- 't' => buffer. push_str ( "\\ t" ) ,
293
- 'r' => buffer. push_str ( "\\ r" ) ,
294
- _ => buffer. push ( c) ,
295
- }
296
- } else {
297
- buffer. push ( c) ;
298
- }
299
- } else {
300
- if escape {
301
- buffer. push ( '\\' ) ;
302
- }
303
- buffer. push ( c) ;
304
- }
305
- escape = false ; // Reset escape flag for non-escape characters
284
+ buffer. push ( c) ;
306
285
}
307
286
}
308
287
}
@@ -335,67 +314,8 @@ impl Executor {
335
314
self . stack . push ( Type :: Bool ( token. parse ( ) . unwrap_or ( true ) ) ) ;
336
315
} else if chars[ 0 ] == '(' && chars[ chars. len ( ) - 1 ] == ')' {
337
316
// Push string value on the stack
338
- let string = {
339
- let mut buffer = String :: new ( ) ; // Temporary storage
340
- let mut brackets = 0 ; // String's nest structure
341
- let mut parentheses = 0 ; // List's nest structure
342
- let mut hash = false ; // Is it Comment
343
- let mut escape = false ; // Flag to indicate next character is escaped
344
-
345
- for c in token[ 1 ..token. len ( ) - 1 ] . to_string ( ) . chars ( ) {
346
- match c {
347
- '\\' if !escape => {
348
- escape = true ;
349
- }
350
- '(' if !hash && !escape => {
351
- brackets += 1 ;
352
- buffer. push ( '(' ) ;
353
- }
354
- ')' if !hash && !escape => {
355
- brackets -= 1 ;
356
- buffer. push ( ')' ) ;
357
- }
358
- '#' if !hash && !escape => {
359
- hash = true ;
360
- buffer. push ( '#' ) ;
361
- }
362
- '#' if hash && !escape => {
363
- hash = false ;
364
- buffer. push ( '#' ) ;
365
- }
366
- '[' if !hash && brackets == 0 && !escape => {
367
- parentheses += 1 ;
368
- buffer. push ( '[' ) ;
369
- }
370
- ']' if !hash && brackets == 0 && !escape => {
371
- parentheses -= 1 ;
372
- buffer. push ( ']' ) ;
373
- }
374
- _ => {
375
- if parentheses == 0 && brackets == 0 && !hash {
376
- if escape {
377
- match c {
378
- 'n' => buffer. push_str ( "\\ n" ) ,
379
- 't' => buffer. push_str ( "\\ t" ) ,
380
- 'r' => buffer. push_str ( "\\ r" ) ,
381
- _ => buffer. push ( c) ,
382
- }
383
- } else {
384
- buffer. push ( c) ;
385
- }
386
- } else {
387
- if escape {
388
- buffer. push ( '\\' ) ;
389
- }
390
- buffer. push ( c) ;
391
- }
392
- escape = false ; // Reset escape flag for non-escape characters
393
- }
394
- }
395
- }
396
- buffer
397
- } ;
398
- self . stack . push ( Type :: String ( string) ) ;
317
+ self . stack
318
+ . push ( Type :: String ( token[ 1 ..token. len ( ) - 1 ] . to_string ( ) ) ) ;
399
319
} else if chars[ 0 ] == '[' && chars[ chars. len ( ) - 1 ] == ']' {
400
320
// Push list value on the stack
401
321
let old_len = self . stack . len ( ) ; // length of old stack
@@ -700,15 +620,10 @@ impl Executor {
700
620
// Standard output
701
621
"print" => {
702
622
let a = self . pop_stack ( ) . get_string ( ) ;
703
-
704
- let a = a. replace ( "\\ n" , "\n " ) ;
705
- let a = a. replace ( "\\ t" , "\t " ) ;
706
- let a = a. replace ( "\\ r" , "\r " ) ;
707
-
708
623
if let Mode :: Debug = self . mode {
709
624
println ! ( "[Output]: {a}" ) ;
710
625
} else {
711
- print ! ( "{a}" ) ;
626
+ println ! ( "{a}" ) ;
712
627
}
713
628
}
714
629
@@ -868,17 +783,8 @@ impl Executor {
868
783
return ;
869
784
}
870
785
}
871
- <<<<<<< HEAD
872
-
873
- self. log_print( String :: from( "Error! item not found in the list\n " ) ) ;
874
- =======
875
- <<<<<<< HEAD
876
786
877
787
self . log_print ( String :: from ( "Error! item not found in the list\n " ) ) ;
878
- =======
879
- self . log_print ( String :: from ( "Error! item not found in the list" ) . as_str ( ) . to_owned ( ) + "\n " ) ;
880
- >>>>>>> ce3cc7e ( git)
881
- >>>>>>> Stack -Programing -Community -main
882
788
self . stack . push ( Type :: Error ( String :: from ( "item-not-found" ) ) ) ;
883
789
}
884
790
@@ -1387,19 +1293,6 @@ impl Executor {
1387
1293
} )
1388
1294
}
1389
1295
1390
- <<<<<<< HEAD
1391
- <<<<<<< HEAD
1392
- =======
1393
- =======
1394
- <<<<<<< HEAD
1395
- >>>>>>> ce80cb2 ( git )
1396
- =======
1397
- <<<<<<< HEAD
1398
- >>>>>>> ce3cc7e ( git )
1399
- =======
1400
- >>>>>>> ce80cb2 ( git )
1401
- >>>>>>> 74 bbfe3 ( git )
1402
- >>>>>>> Stack -Programing -Community -main
1403
1296
"index" => {
1404
1297
let findhint = self . pop_stack ( ) . get_string ( ) ;
1405
1298
let findtarget = self . pop_stack ( ) . get_list ( ) ;
@@ -1422,26 +1315,6 @@ impl Executor {
1422
1315
self . clearscreen ( ) ;
1423
1316
}
1424
1317
1425
- <<<<<<< HEAD
1426
- <<<<<<< HEAD
1427
- =======
1428
- <<<<<<< HEAD
1429
- >>>>>>> 887510 b ( git )
1430
- =======
1431
- =======
1432
- >>>>>>> 1 d34bfe ( Refactoring )
1433
- >>>>>>> ce3cc7e ( git )
1434
- =======
1435
- >>>>>>> Stack -Programing -Community -main
1436
- =======
1437
- >>>>>>> 1 d34bfe ( Refactoring )
1438
- =======
1439
- >>>>>>> 887510 b ( git)
1440
- >>>>>>> ce80cb2 ( git)
1441
- <<<<<<< HEAD
1442
- =======
1443
- >>>>>>> 74 bbfe3 ( git )
1444
- >>>>>>> Stack -Programing -Community -main
1445
1318
// If it is not recognized as a command, use it as a string.
1446
1319
_ => self . stack . push ( Type :: String ( command) ) ,
1447
1320
}
0 commit comments