Skip to content

Commit fea4209

Browse files
author
梶塚太智
committed
Debug processing of string literal
1 parent 4a76dca commit fea4209

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/main.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ impl Executor {
334334
// Push bool value on the stack
335335
self.stack.push(Type::Bool(token.parse().unwrap_or(true)));
336336
} else if chars[0] == '(' && chars[chars.len() - 1] == ')' {
337-
// Push string value on the stack
338-
self.stack
339-
.push(Type::String(token[1..token.len() - 1].to_string()));
337+
// Processing string escape
340338
let string = {
341339
let mut buffer = String::new(); // Temporary storage
342340
let mut brackets = 0; // String's nest structure
@@ -382,12 +380,6 @@ impl Executor {
382380
'r' => buffer.push_str("\\r"),
383381
_ => buffer.push(c),
384382
}
385-
buffer.push(match c {
386-
'n' => '\n',
387-
't' => '\t',
388-
'r' => '\r',
389-
_ => c,
390-
})
391383
} else {
392384
buffer.push(c);
393385
}
@@ -402,10 +394,8 @@ impl Executor {
402394
}
403395
}
404396
buffer
405-
};
397+
};// Push string value on the stack
406398
self.stack.push(Type::String(string));
407-
self.stack
408-
.push(Type::String(token[1..token.len() - 1].to_string()));
409399
} else if chars[0] == '[' && chars[chars.len() - 1] == ']' {
410400
// Push list value on the stack
411401
let old_len = self.stack.len(); // length of old stack
@@ -710,10 +700,15 @@ impl Executor {
710700
// Standard output
711701
"print" => {
712702
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+
713708
if let Mode::Debug = self.mode {
714709
println!("[Output]: {a}");
715710
} else {
716-
println!("{a}");
711+
print!("{a}");
717712
}
718713
}
719714

0 commit comments

Comments
 (0)