@@ -11,6 +11,7 @@ use std::process::{Command, Stdio};
11
11
use topological_sort:: TopologicalSort ;
12
12
13
13
use crate :: error:: Error ;
14
+ use anyhow:: Result ;
14
15
15
16
use crate :: parser:: asn:: structs:: module:: Asn1Module ;
16
17
@@ -79,7 +80,7 @@ impl Asn1Compiler {
79
80
/// modules are topologically sorted as well. This makes Error handling for undefined
80
81
/// definitions much easier.
81
82
// FIXME: Support the case where module is imported by a name different from it's actual name.
82
- pub fn resolve_modules ( & mut self ) -> Result < ( ) , Error > {
83
+ pub fn resolve_modules ( & mut self ) -> Result < ( ) > {
83
84
log:: info!( "Resolving imports from all modules." ) ;
84
85
self . resolve_imports ( ) ?;
85
86
@@ -88,7 +89,7 @@ impl Asn1Compiler {
88
89
}
89
90
90
91
/// Generate the code
91
- pub fn generate ( & mut self ) -> Result < ( ) , Error > {
92
+ pub fn generate ( & mut self ) -> Result < ( ) > {
92
93
log:: info!( "Generating code, writing to file: {}" , self . output_filename) ;
93
94
94
95
let input_text = self . generator . generate ( & self . resolver ) ?;
@@ -109,7 +110,7 @@ impl Asn1Compiler {
109
110
}
110
111
111
112
/// Compilation Driver for a String as module(s).
112
- pub fn compile_string ( & mut self , modules_string : & str , parse_only : bool ) -> Result < ( ) , Error > {
113
+ pub fn compile_string ( & mut self , modules_string : & str , parse_only : bool ) -> Result < ( ) > {
113
114
let mut tokens = crate :: tokenizer:: tokenize_string ( modules_string) ?;
114
115
self . parse_tokens_into_modules ( & mut tokens) ?;
115
116
if !parse_only {
@@ -121,10 +122,7 @@ impl Asn1Compiler {
121
122
}
122
123
123
124
/// The Actual compilation driver
124
- pub fn compile_files < T : AsRef < Path > + std:: fmt:: Debug > (
125
- & mut self ,
126
- files : & [ T ] ,
127
- ) -> Result < ( ) , Error > {
125
+ pub fn compile_files < T : AsRef < Path > + std:: fmt:: Debug > ( & mut self , files : & [ T ] ) -> Result < ( ) > {
128
126
for file in files {
129
127
log:: info!( "Processing file: {:?}" , file) ;
130
128
let file = File :: open ( file) . map_err ( |e| io_error ! ( "{:#?}" , e) ) ?;
@@ -136,7 +134,7 @@ impl Asn1Compiler {
136
134
self . generate ( )
137
135
}
138
136
139
- fn parse_tokens_into_modules ( & mut self , tokens : & mut Vec < Token > ) -> Result < ( ) , Error > {
137
+ fn parse_tokens_into_modules ( & mut self , tokens : & mut Vec < Token > ) -> Result < ( ) > {
140
138
log:: debug!( "Parsing {} tokens." , tokens. len( ) ) ;
141
139
let mut modules = crate :: parser:: parse ( tokens) ?;
142
140
loop {
@@ -151,7 +149,7 @@ impl Asn1Compiler {
151
149
Ok ( ( ) )
152
150
}
153
151
154
- fn rustfmt_generated_code ( & self , code : & str ) -> Result < String , Error > {
152
+ fn rustfmt_generated_code ( & self , code : & str ) -> Result < String > {
155
153
log:: debug!( "Runing `rustfmt` on the generated code." ) ;
156
154
let rustfmt_binary = "rustfmt" ; // TODO: Get from `env` , 'custom path' etc.
157
155
let mut cmd = Command :: new ( rustfmt_binary) ;
@@ -177,13 +175,13 @@ impl Asn1Compiler {
177
175
match String :: from_utf8 ( output) {
178
176
Ok ( formatted_output) => match status. code ( ) {
179
177
Some ( 0 ) => Ok ( formatted_output) ,
180
- _ => Err ( resolve_error ! ( "`rustfmt` failed to write some bindings." ) ) ,
178
+ _ => Err ( resolve_error ! ( "`rustfmt` failed to write some bindings." ) . into ( ) ) ,
181
179
} ,
182
180
_ => Ok ( stdin_handle. join ( ) . unwrap ( ) ) ,
183
181
}
184
182
}
185
183
186
- fn resolve_imports ( & self ) -> Result < ( ) , Error > {
184
+ fn resolve_imports ( & self ) -> Result < ( ) > {
187
185
log:: debug!( "Resolving imports." ) ;
188
186
for ( _, module) in self . modules . iter ( ) {
189
187
for ( import, module_name) in module. get_imported_defs ( ) {
@@ -193,7 +191,8 @@ impl Asn1Compiler {
193
191
"Module '{}', corresponding to definition '{}' not found!" ,
194
192
module_name. name_as_str( ) ,
195
193
import
196
- ) ) ;
194
+ )
195
+ . into ( ) ) ;
197
196
}
198
197
}
199
198
}
@@ -226,7 +225,7 @@ impl Asn1Compiler {
226
225
out_vec
227
226
}
228
227
229
- fn resolve_definitions ( & mut self ) -> Result < ( ) , Error > {
228
+ fn resolve_definitions ( & mut self ) -> Result < ( ) > {
230
229
let module_names = self . sorted_modules ( ) ;
231
230
for name in module_names {
232
231
let module = self . modules . get_mut ( & name) . unwrap ( ) ;
0 commit comments