Skip to content

Commit 42e647b

Browse files
committed
git
modified: src/main.rs
1 parent 46cc2ae commit 42e647b

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

src/main.rs

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -244,47 +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
_ => {
284+
<<<<<<< HEAD
288285
if parentheses == 0 && brackets == 0 && !hash {
289286
if escape {
290287
<<<<<<< HEAD
@@ -318,6 +315,9 @@ impl Executor {
318315
buffer.push(c);
319316
}
320317
escape = false; // Reset escape flag for non-escape characters
318+
=======
319+
buffer.push(c);
320+
>>>>>>> 76e82be (git)
321321
}
322322
}
323323
}
@@ -350,6 +350,7 @@ impl Executor {
350350
self.stack.push(Type::Bool(token.parse().unwrap_or(true)));
351351
} else if chars[0] == '(' && chars[chars.len() - 1] == ')' {
352352
// Push string value on the stack
353+
<<<<<<< HEAD
353354
let string = {
354355
let mut buffer = String::new(); // Temporary storage
355356
let mut brackets = 0; // String's nest structure
@@ -426,6 +427,10 @@ impl Executor {
426427
buffer
427428
};
428429
self.stack.push(Type::String(string));
430+
=======
431+
self.stack
432+
.push(Type::String(token[1..token.len() - 1].to_string()));
433+
>>>>>>> 76e82be (git)
429434
} else if chars[0] == '[' && chars[chars.len() - 1] == ']' {
430435
// Push list value on the stack
431436
let old_len = self.stack.len(); // length of old stack
@@ -730,15 +735,10 @@ impl Executor {
730735
// Standard output
731736
"print" => {
732737
let a = self.pop_stack().get_string();
733-
734-
let a = a.replace("\\n", "\n");
735-
let a = a.replace("\\t", "\t");
736-
let a = a.replace("\\r", "\r");
737-
738738
if let Mode::Debug = self.mode {
739739
println!("[Output]: {a}");
740740
} else {
741-
print!("{a}");
741+
println!("{a}");
742742
}
743743
}
744744

@@ -902,6 +902,7 @@ impl Executor {
902902
<<<<<<< HEAD
903903
<<<<<<< HEAD
904904
<<<<<<< HEAD
905+
<<<<<<< HEAD
905906
=======
906907
>>>>>>> cdb5350 (git)
907908

@@ -919,6 +920,10 @@ impl Executor {
919920
>>>>>>> 0c174e6 (Update main.rs)
920921
=======
921922
>>>>>>> cdb5350 (git)
923+
=======
924+
925+
self.log_print(String::from("Error! item not found in the list\n"));
926+
>>>>>>> 76e82be (git)
922927
self.stack.push(Type::Error(String::from("item-not-found")));
923928
}
924929

@@ -1431,6 +1436,7 @@ impl Executor {
14311436
<<<<<<< HEAD
14321437
<<<<<<< HEAD
14331438
<<<<<<< HEAD
1439+
<<<<<<< HEAD
14341440
=======
14351441
=======
14361442
<<<<<<< HEAD
@@ -1453,6 +1459,8 @@ impl Executor {
14531459
>>>>>>> ce80cb2 (git)
14541460
>>>>>>> 74bbfe3 (git)
14551461
>>>>>>> e1b0d54 (git)
1462+
=======
1463+
>>>>>>> 76e82be (git)
14561464
"index" => {
14571465
let findhint = self.pop_stack().get_string();
14581466
let findtarget = self.pop_stack().get_list();
@@ -1480,6 +1488,7 @@ impl Executor {
14801488
<<<<<<< HEAD
14811489
<<<<<<< HEAD
14821490
<<<<<<< HEAD
1491+
<<<<<<< HEAD
14831492
=======
14841493
>>>>>>> cdb5350 (git)
14851494
=======
@@ -1508,6 +1517,8 @@ impl Executor {
15081517
>>>>>>> cdb5350 (git)
15091518
=======
15101519
>>>>>>> e1b0d54 (git)
1520+
=======
1521+
>>>>>>> 76e82be (git)
15111522
// If it is not recognized as a command, use it as a string.
15121523
_ => self.stack.push(Type::String(command)),
15131524
}

0 commit comments

Comments
 (0)