@@ -12,41 +12,45 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
1212fn main ( ) {
1313 // コマンドライン引数を読み込む
1414 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+ // 実行モードを判定する
1919 if args[ 2 ] . contains ( "-d" ) {
2020 let mut executor = Executor :: new ( Mode :: Debug ) ;
2121 executor. evaluate_program ( code) ; //デバッグ実行
2222 } else {
2323 let mut executor = Executor :: new ( Mode :: Script ) ;
2424 executor. evaluate_program ( code) ; // スクリプト実行
2525 }
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 ( ) ) {
2832 let mut executor = Executor :: new ( Mode :: Script ) ; //デフォルト値はスクリプト実行
2933 executor. evaluate_program ( code) ;
3034 } 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 ( ) ;
3544 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 ;
4349 }
44-
45- executor. evaluate_program ( code)
4650 }
51+
52+ executor. evaluate_program ( code)
4753 }
48- } else {
49- println ! ( "エラー! ファイルが見つかりません" )
5054 }
5155}
5256
0 commit comments