Skip to content

Commit 27ec1d6

Browse files
author
梶塚太智
committed
Update main.rs
Refactoring
1 parent 60a855e commit 27ec1d6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ impl Executor {
205205
}
206206

207207
/// Show inside the stack
208-
fn show_stack(&mut self) {
209-
self.log_print(format!(
208+
fn show_stack(&mut self) -> String {
209+
format!(
210210
"Stack〔 {} 〕",
211211
self.stack
212212
.iter()
213213
.map(|x| x.display())
214214
.collect::<Vec<_>>()
215215
.join(" | ")
216-
))
216+
)
217217
}
218218

219219
/// Parse token by analyzing syntax
@@ -277,8 +277,9 @@ impl Executor {
277277
let syntax: Vec<String> = self.analyze_syntax(code);
278278

279279
for token in syntax {
280-
self.show_stack(); // Show inside stack to debug
281-
self.log_print(format!(" ← {}\n", token));
280+
// Show inside stack to debug
281+
let stack = self.show_stack();
282+
self.log_print(format!("{stack} ← {token}\n"));
282283

283284
// Character vector for token processing
284285
let chars: Vec<char> = token.chars().collect();
@@ -322,8 +323,8 @@ impl Executor {
322323
}
323324

324325
// Show inside stack, after execution
325-
self.show_stack();
326-
self.log_print("\n".to_string());
326+
let stack = self.show_stack();
327+
self.log_print(format!("{stack}\n"));
327328
}
328329

329330
/// execute string as commands

0 commit comments

Comments
 (0)