@@ -12,41 +12,45 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
12
12
fn main ( ) {
13
13
// コマンドライン引数を読み込む
14
14
let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
15
- // ファイルを開く
16
- if let Ok ( code ) = get_file_contents ( args [ 1 ] . clone ( ) ) {
17
- // 実行モードを判定する
18
- if args . len ( ) > 2 {
15
+ if args . len ( ) > 2 {
16
+ // ファイルを開く
17
+ if let Ok ( code ) = get_file_contents ( args [ 1 ] . clone ( ) ) {
18
+ // 実行モードを判定する
19
19
if args[ 2 ] . contains ( "-d" ) {
20
20
let mut executor = Executor :: new ( Mode :: Debug ) ;
21
21
executor. evaluate_program ( code) ; //デバッグ実行
22
22
} else {
23
23
let mut executor = Executor :: new ( Mode :: Script ) ;
24
24
executor. evaluate_program ( code) ; // スクリプト実行
25
25
}
26
- } else if args. len ( ) > 1 {
27
- // ファイルを開く
26
+ } else {
27
+ println ! ( "エラー! ファイルが見つかりません" )
28
+ }
29
+ } else if args. len ( ) > 1 {
30
+ // ファイルを開く
31
+ if let Ok ( code) = get_file_contents ( args[ 1 ] . clone ( ) ) {
28
32
let mut executor = Executor :: new ( Mode :: Script ) ; //デフォルト値はスクリプト実行
29
33
executor. evaluate_program ( code) ;
30
34
} else {
31
- // タイトルを表示する
32
- println ! ( "Stack プログラミング言語" ) ;
33
- let mut executor = Executor :: new ( Mode :: Debug ) ;
34
- // REPL実行
35
+ println ! ( "エラー! ファイルが見つかりません" )
36
+ }
37
+ } else {
38
+ // タイトルを表示する
39
+ println ! ( "Stack プログラミング言語" ) ;
40
+ let mut executor = Executor :: new ( Mode :: Debug ) ;
41
+ // REPL実行
42
+ loop {
43
+ let mut code = String :: new ( ) ;
35
44
loop {
36
- let mut code = String :: new ( ) ;
37
- loop {
38
- let inputed = input ( "> " ) ;
39
- code += & format ! ( "{inputed}\n " ) ;
40
- if inputed. is_empty ( ) {
41
- break ;
42
- }
45
+ let inputed = input ( "> " ) ;
46
+ code += & format ! ( "{inputed}\n " ) ;
47
+ if inputed. is_empty ( ) {
48
+ break ;
43
49
}
44
-
45
- executor. evaluate_program ( code)
46
50
}
51
+
52
+ executor. evaluate_program ( code)
47
53
}
48
- } else {
49
- println ! ( "エラー! ファイルが見つかりません" )
50
54
}
51
55
}
52
56
0 commit comments