@@ -244,70 +244,55 @@ 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 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
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
250
251
251
252
for c in code. chars ( ) {
252
253
match c {
253
- '(' => {
254
- in_brackets += 1 ;
254
+ '\\' if !escape => {
255
+ escape = true ;
256
+ }
257
+ '(' if !hash && !escape => {
258
+ brackets += 1 ;
255
259
buffer. push ( '(' ) ;
256
260
}
257
- ')' => {
258
- in_brackets -= 1 ;
261
+ ')' if !hash && !escape => {
262
+ brackets -= 1 ;
259
263
buffer. push ( ')' ) ;
260
264
}
261
- '#' if !in_hash => {
262
- in_hash = true ;
265
+ '#' if !hash && !escape => {
266
+ hash = true ;
263
267
buffer. push ( '#' ) ;
264
268
}
265
- '#' if in_hash => {
266
- in_hash = false ;
269
+ '#' if hash && !escape => {
270
+ hash = false ;
267
271
buffer. push ( '#' ) ;
268
272
}
269
- '[' if in_brackets == 0 => {
270
- in_parentheses += 1 ;
273
+ '[' if !hash && brackets == 0 && !escape => {
274
+ parentheses += 1 ;
271
275
buffer. push ( '[' ) ;
272
276
}
273
- ']' if in_brackets == 0 => {
274
- in_parentheses -= 1 ;
277
+ ']' if !hash && brackets == 0 && !escape => {
278
+ parentheses -= 1 ;
275
279
buffer. push ( ']' ) ;
276
280
}
277
- ' ' if !in_hash && in_parentheses == 0 && in_brackets == 0 => {
281
+ ' ' if !hash && parentheses == 0 && brackets == 0 && !escape => {
278
282
if !buffer. is_empty ( ) {
279
283
syntax. push ( buffer. clone ( ) ) ;
280
284
buffer. clear ( ) ;
281
285
}
282
286
}
283
287
_ => {
284
- <<<<<<< HEAD
285
- buffer. push( c ) ;
286
- =======
287
- <<<<<<< HEAD
288
288
if parentheses == 0 && brackets == 0 && !hash {
289
289
if escape {
290
- <<<<<<< HEAD
291
- <<<<<<< HEAD
292
- =======
293
- >>>>>>> 416 f9ec ( Update main. rs)
294
290
match c {
295
291
'n' => buffer. push_str ( "\\ n" ) ,
296
292
't' => buffer. push_str ( "\\ t" ) ,
297
293
'r' => buffer. push_str ( "\\ r" ) ,
298
294
_ => buffer. push ( c) ,
299
295
}
300
- <<<<<<< HEAD
301
- =======
302
- buffer. push( match c {
303
- 'n' => '\n' ,
304
- 't' => '\t' ,
305
- 'r' => '\r' ,
306
- _ => c,
307
- } )
308
- >>>>>>> e0ee7bf ( Add string escape)
309
- =======
310
- >>>>>>> 416 f9ec ( Update main. rs)
311
296
} else {
312
297
buffer. push ( c) ;
313
298
}
@@ -318,10 +303,6 @@ impl Executor {
318
303
buffer. push ( c) ;
319
304
}
320
305
escape = false ; // Reset escape flag for non-escape characters
321
- =======
322
- buffer. push( c) ;
323
- >>>>>>> 76 e82be ( git)
324
- >>>>>>> upstream-main
325
306
}
326
307
}
327
308
}
@@ -354,11 +335,8 @@ impl Executor {
354
335
self . stack . push ( Type :: Bool ( token. parse ( ) . unwrap_or ( true ) ) ) ;
355
336
} else if chars[ 0 ] == '(' && chars[ chars. len ( ) - 1 ] == ')' {
356
337
// Push string value on the stack
357
- <<<<<<< HEAD
358
338
self . stack
359
339
. push ( Type :: String ( token[ 1 ..token. len ( ) - 1 ] . to_string ( ) ) ) ;
360
- =======
361
- <<<<<<< HEAD
362
340
let string = {
363
341
let mut buffer = String :: new ( ) ; // Temporary storage
364
342
let mut brackets = 0 ; // String's nest structure
@@ -398,27 +376,18 @@ impl Executor {
398
376
_ => {
399
377
if parentheses == 0 && brackets == 0 && !hash {
400
378
if escape {
401
- <<<<<<< HEAD
402
- <<<<<<< HEAD
403
- =======
404
- >>>>>>> 416 f9ec ( Update main. rs)
405
379
match c {
406
380
'n' => buffer. push_str ( "\\ n" ) ,
407
381
't' => buffer. push_str ( "\\ t" ) ,
408
382
'r' => buffer. push_str ( "\\ r" ) ,
409
383
_ => buffer. push ( c) ,
410
384
}
411
- <<<<<<< HEAD
412
- =======
413
385
buffer. push ( match c {
414
386
'n' => '\n' ,
415
387
't' => '\t' ,
416
388
'r' => '\r' ,
417
389
_ => c,
418
390
} )
419
- >>>>>>> e0ee7bf ( Add string escape)
420
- =======
421
- >>>>>>> 416 f9ec ( Update main. rs)
422
391
} else {
423
392
buffer. push ( c) ;
424
393
}
@@ -435,11 +404,8 @@ impl Executor {
435
404
buffer
436
405
} ;
437
406
self . stack . push ( Type :: String ( string) ) ;
438
- =======
439
407
self . stack
440
408
. push ( Type :: String ( token[ 1 ..token. len ( ) - 1 ] . to_string ( ) ) ) ;
441
- >>>>>>> 76e82 be ( git)
442
- >>>>>>> upstream-main
443
409
} else if chars[ 0 ] == '[' && chars[ chars. len ( ) - 1 ] == ']' {
444
410
// Push list value on the stack
445
411
let old_len = self . stack . len ( ) ; // length of old stack
@@ -907,32 +873,7 @@ impl Executor {
907
873
return ;
908
874
}
909
875
}
910
- <<<<<<< HEAD
911
- <<<<<<< HEAD
912
- <<<<<<< HEAD
913
- <<<<<<< HEAD
914
- <<<<<<< HEAD
915
- =======
916
- >>>>>>> cdb5350 ( git )
917
-
918
- self. log_print( String :: from( "Error! item not found in the list\n " ) ) ;
919
- =======
920
- self . log_print( String :: from( "Error! item not found in the list" ) . as_str( ) . to_owned ( ) + "\n " ) ;
921
- >>>>>>> ce3cc7e ( git)
922
- <<<<<<< HEAD
923
- =======
924
-
925
- =======
926
-
927
- >>>>>>> 61 ad1c1 ( Format )
928
- self. log_print( String :: from( "Error! item not found in the list\n " ) ) ;
929
- >>>>>>> 0 c174e6 ( Update main. rs)
930
- =======
931
- >>>>>>> cdb5350 ( git)
932
- =======
933
-
934
876
self . log_print ( String :: from ( "Error! item not found in the list\n " ) ) ;
935
- >>>>>>> 76e82 be ( git)
936
877
self . stack . push ( Type :: Error ( String :: from ( "item-not-found" ) ) ) ;
937
878
}
938
879
@@ -1441,52 +1382,6 @@ impl Executor {
1441
1382
} )
1442
1383
}
1443
1384
1444
- <<<<<<< HEAD
1445
- =======
1446
- <<<<<<< HEAD
1447
- <<<<<<< HEAD
1448
- <<<<<<< HEAD
1449
- <<<<<<< HEAD
1450
- <<<<<<< HEAD
1451
- =======
1452
- =======
1453
- <<<<<<< HEAD
1454
- >>>>>>> ce3cc7e ( git )
1455
- =======
1456
- >>>>>>> ce80cb2 ( git )
1457
- >>>>>>> 74 bbfe3 ( git )
1458
- =======
1459
- =======
1460
- >>>>>>> 1843023 ( git)
1461
- =======
1462
- =======
1463
- =======
1464
- <<<<<<< HEAD
1465
- >>>>>>> ce3cc7e ( git )
1466
- <<<<<<< HEAD
1467
- >>>>>>> cdb5350 ( git )
1468
- =======
1469
- =======
1470
- >>>>>>> ce80cb2 ( git )
1471
- >>>>>>> 74 bbfe3 ( git )
1472
- >>>>>>> e1b0d54 ( git )
1473
- =======
1474
- >>>>>>> 76 e82be ( git )
1475
- >>>>>>> upstream-main
1476
- "index" => {
1477
- let findhint = self . pop_stack ( ) . get_string ( ) ;
1478
- let findtarget = self . pop_stack ( ) . get_list ( ) ;
1479
-
1480
- for index in 0 ..( findtarget. len ( ) ) {
1481
- if findhint == findtarget[ index] . clone ( ) . get_string ( ) {
1482
- self . stack . push ( Type :: Number ( index as f64 ) ) ;
1483
- return ;
1484
- }
1485
- }
1486
- self . log_print ( "Error! item not found in this list" . to_owned ( ) + "\n " ) ;
1487
- self . stack . push ( Type :: Error ( String :: from ( "item-not-found" ) ) ) ;
1488
- }
1489
-
1490
1385
"cls" => {
1491
1386
self . clearscreen ( ) ;
1492
1387
}
@@ -1495,45 +1390,6 @@ impl Executor {
1495
1390
self . clearscreen ( ) ;
1496
1391
}
1497
1392
1498
- <<<<<<< HEAD
1499
- =======
1500
- <<<<<<< HEAD
1501
- <<<<<<< HEAD
1502
- <<<<<<< HEAD
1503
- <<<<<<< HEAD
1504
- <<<<<<< HEAD
1505
- <<<<<<< HEAD
1506
- =======
1507
- >>>>>>> cdb5350 ( git )
1508
- =======
1509
- >>>>>>> e1b0d54 ( git )
1510
- >>>>>>> 887510 b ( git )
1511
- =======
1512
- =======
1513
- >>>>>>> 1 d34bfe ( Refactoring )
1514
- >>>>>>> ce3cc7e ( git)
1515
- <<<<<<< HEAD
1516
- <<<<<<< HEAD
1517
- =======
1518
- >>>>>>> e1b0d54 ( git )
1519
- =======
1520
- =======
1521
- >>>>>>> 1 d34bfe ( Refactoring )
1522
- =======
1523
- >>>>>>> 887510 b ( git )
1524
- >>>>>>> ce80cb2 ( git )
1525
- >>>>>>> 74 bbfe3 ( git)
1526
- <<<<<<< HEAD
1527
- =======
1528
- >>>>>>> 887510 b ( git )
1529
- >>>>>>> 1843023 ( git )
1530
- =======
1531
- >>>>>>> cdb5350 ( git )
1532
- =======
1533
- >>>>>>> e1b0d54 ( git)
1534
- =======
1535
- >>>>>>> 76 e82be ( git )
1536
- >>>>>>> upstream-main
1537
1393
// If it is not recognized as a command, use it as a string.
1538
1394
_ => self . stack . push ( Type :: String ( command) ) ,
1539
1395
}
0 commit comments