@@ -14,25 +14,27 @@ fn main() {
1414 let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
1515 if args. len ( ) > 2 {
1616 // ファイルを開く
17- if let Ok ( code) = get_file_contents ( args[ 1 ] . clone ( ) ) {
18- // 実行モードを判定する
19- if args[ 2 ] . contains ( "-d" ) {
20- let mut executor = Executor :: new ( Mode :: Debug ) ;
21- executor. evaluate_program ( code) ; //デバッグ実行
22- } else {
23- let mut executor = Executor :: new ( Mode :: Script ) ;
24- executor. evaluate_program ( code) ; // スクリプト実行
17+ match get_file_contents ( args[ 1 ] . clone ( ) ) {
18+ Ok ( code) => {
19+ // 実行モードを判定する
20+ if args[ 2 ] . contains ( "-d" ) {
21+ let mut executor = Executor :: new ( Mode :: Debug ) ;
22+ executor. evaluate_program ( code) ; //デバッグ実行
23+ } else {
24+ let mut executor = Executor :: new ( Mode :: Script ) ;
25+ executor. evaluate_program ( code) ; // スクリプト実行
26+ }
2527 }
26- } else {
27- println ! ( "エラー! ファイルが見つかりません" )
28+ Err ( e) => println ! ( "エラー! {e}" ) ,
2829 }
2930 } else if args. len ( ) > 1 {
3031 // ファイルを開く
31- if let Ok ( code) = get_file_contents ( args[ 1 ] . clone ( ) ) {
32- let mut executor = Executor :: new ( Mode :: Script ) ; //デフォルト値はスクリプト実行
33- executor. evaluate_program ( code) ;
34- } else {
35- println ! ( "エラー! ファイルが見つかりません" )
32+ match get_file_contents ( args[ 1 ] . clone ( ) ) {
33+ Ok ( code) => {
34+ let mut executor = Executor :: new ( Mode :: Script ) ; //デフォルト値はスクリプト実行
35+ executor. evaluate_program ( code) ;
36+ }
37+ Err ( e) => println ! ( "エラー! {e}" ) ,
3638 }
3739 } else {
3840 // タイトルを表示する
@@ -183,7 +185,12 @@ impl Executor {
183185 self . log_print ( "メモリ内部の変数 {\n " . to_string ( ) ) ;
184186 let max = self . memory . keys ( ) . map ( |s| s. len ( ) ) . max ( ) . unwrap_or ( 0 ) ;
185187 for ( name, value) in self . memory . clone ( ) {
186- self . log_print ( format ! ( " {:>width$}: {}\n " , name, value. display( ) , width=max) )
188+ self . log_print ( format ! (
189+ " {:>width$}: {}\n " ,
190+ name,
191+ value. display( ) ,
192+ width = max
193+ ) )
187194 }
188195 self . log_print ( "}\n " . to_string ( ) )
189196 }
0 commit comments