@@ -244,65 +244,44 @@ impl Executor {
244244
245245 let mut syntax = Vec :: new ( ) ; // Token string
246246 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
251250
252251 for c in code. chars ( ) {
253252 match c {
254- '\\' if !escape => {
255- escape = true ;
256- }
257- '(' if !hash && !escape => {
258- brackets += 1 ;
253+ '(' => {
254+ in_brackets += 1 ;
259255 buffer. push ( '(' ) ;
260256 }
261- ')' if !hash && !escape => {
262- brackets -= 1 ;
257+ ')' => {
258+ in_brackets -= 1 ;
263259 buffer. push ( ')' ) ;
264260 }
265- '#' if !hash && !escape => {
266- hash = true ;
261+ '#' if !in_hash => {
262+ in_hash = true ;
267263 buffer. push ( '#' ) ;
268264 }
269- '#' if hash && !escape => {
270- hash = false ;
265+ '#' if in_hash => {
266+ in_hash = false ;
271267 buffer. push ( '#' ) ;
272268 }
273- '[' if !hash && brackets == 0 && !escape => {
274- parentheses += 1 ;
269+ '[' if in_brackets == 0 => {
270+ in_parentheses += 1 ;
275271 buffer. push ( '[' ) ;
276272 }
277- ']' if !hash && brackets == 0 && !escape => {
278- parentheses -= 1 ;
273+ ']' if in_brackets == 0 => {
274+ in_parentheses -= 1 ;
279275 buffer. push ( ']' ) ;
280276 }
281- ' ' if !hash && parentheses == 0 && brackets == 0 && !escape => {
277+ ' ' if !in_hash && in_parentheses == 0 && in_brackets == 0 => {
282278 if !buffer. is_empty ( ) {
283279 syntax. push ( buffer. clone ( ) ) ;
284280 buffer. clear ( ) ;
285281 }
286282 }
287283 _ => {
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) ;
306285 }
307286 }
308287 }
@@ -335,67 +314,8 @@ impl Executor {
335314 self . stack . push ( Type :: Bool ( token. parse ( ) . unwrap_or ( true ) ) ) ;
336315 } else if chars[ 0 ] == '(' && chars[ chars. len ( ) - 1 ] == ')' {
337316 // 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 ( ) ) ) ;
399319 } else if chars[ 0 ] == '[' && chars[ chars. len ( ) - 1 ] == ']' {
400320 // Push list value on the stack
401321 let old_len = self . stack . len ( ) ; // length of old stack
@@ -700,15 +620,10 @@ impl Executor {
700620 // Standard output
701621 "print" => {
702622 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-
708623 if let Mode :: Debug = self . mode {
709624 println ! ( "[Output]: {a}" ) ;
710625 } else {
711- print ! ( "{a}" ) ;
626+ println ! ( "{a}" ) ;
712627 }
713628 }
714629
@@ -868,17 +783,8 @@ impl Executor {
868783 return ;
869784 }
870785 }
871- <<<<<<< HEAD
872-
873- self. log_print( String :: from( "Error! item not found in the list\n " ) ) ;
874- =======
875- <<<<<<< HEAD
876786
877787 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
882788 self . stack . push ( Type :: Error ( String :: from ( "item-not-found" ) ) ) ;
883789 }
884790
@@ -1387,19 +1293,6 @@ impl Executor {
13871293 } )
13881294 }
13891295
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
14031296 "index" => {
14041297 let findhint = self . pop_stack ( ) . get_string ( ) ;
14051298 let findtarget = self . pop_stack ( ) . get_list ( ) ;
@@ -1422,26 +1315,6 @@ impl Executor {
14221315 self . clearscreen ( ) ;
14231316 }
14241317
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
14451318 // If it is not recognized as a command, use it as a string.
14461319 _ => self . stack . push ( Type :: String ( command) ) ,
14471320 }
0 commit comments