Skip to content

Commit 8d06385

Browse files
author
梶塚太智
committed
Update main.rs
1 parent f6a45c8 commit 8d06385

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn main() {
1111
if args.len() > 2 {
1212
// ファイルを開く
1313
if let Ok(code) = get_file_contents(args[2].clone()) {
14-
let code = code.replace("\n", " ").replace("\r", " ");
1514
// 実行モードを判定する
1615
if args[1].contains("d") {
1716
let mut executor = Executor::new(Mode::Debug);
@@ -27,7 +26,7 @@ fn main() {
2726
// ファイルを開く
2827
if let Ok(code) = get_file_contents(args[1].clone()) {
2928
let mut executor = Executor::new(Mode::Script); //デフォルト値はスクリプト実行
30-
executor.evaluate_program(code.replace("\n", " ").replace("\r", " "));
29+
executor.evaluate_program(code);
3130
} else {
3231
println!("エラー! ファイルが見つかりません")
3332
}
@@ -181,6 +180,12 @@ impl Executor {
181180

182181
/// 構文解析
183182
fn analyze_syntax(&mut self, code: String) -> Vec<String> {
183+
let code = code
184+
.replace("\n", " ")
185+
.replace("\r", " ")
186+
.replace("\t", " ")
187+
.replace(" ", " ");
188+
184189
let mut syntax = Vec::new();
185190
let mut buffer = String::new();
186191
let mut in_brackets = 0;
@@ -213,7 +218,7 @@ impl Executor {
213218
in_parentheses -= 1;
214219
buffer.push(']');
215220
}
216-
' ' | ' ' if !in_hash && in_parentheses == 0 && in_brackets == 0 => {
221+
' ' if !in_hash && in_parentheses == 0 && in_brackets == 0 => {
217222
if !buffer.is_empty() {
218223
syntax.push(buffer.clone());
219224
buffer.clear();

0 commit comments

Comments
 (0)