@@ -8,8 +8,7 @@ pub(super) fn parse_var<'a>(
8
8
vcd : & ' a mut VCD ,
9
9
signal_map : & mut HashMap < String , SignalIdx >
10
10
) -> Result < ( ) , String > {
11
- let err = format ! ( "Error near {}:{}. No more words left in vcd file." , file!( ) , line!( ) ) ;
12
- let ( word, cursor) = word_reader. next_word ( ) . ok_or ( & err) ?;
11
+ let ( word, cursor) = word_reader. next_word ( ) ?;
13
12
let expected_types = [ "integer" , "parameter" , "real" , "reg" , "string" , "wire" , "tri1" , "time" ] ;
14
13
15
14
// $var parameter 3 a IDLE $end
@@ -24,12 +23,14 @@ pub(super) fn parse_var<'a>(
24
23
"tri1" => { Ok ( SigType :: Tri1 ) }
25
24
"time" => { Ok ( SigType :: Time ) }
26
25
_ => {
27
- let err = format ! ( "found keyword `{word}` but expected one of {expected_types:?} on {cursor:?}" ) ;
26
+ let err = format ! ( "Error near {}:{} \
27
+ found keyword `{word}` but expected one of \
28
+ {expected_types:?} on {cursor:?}", file!( ) , line!( ) ) ;
28
29
Err ( err)
29
30
}
30
31
} ?;
31
32
32
- let ( word, cursor) = word_reader. next_word ( ) . ok_or ( & err ) ?;
33
+ let ( word, cursor) = word_reader. next_word ( ) ?;
33
34
let parse_err = format ! ( "failed to parse as usize on {cursor:?}" ) ;
34
35
35
36
// $var parameter 3 a IDLE $end
@@ -48,14 +49,14 @@ pub(super) fn parse_var<'a>(
48
49
49
50
// $var parameter 3 a IDLE $end
50
51
// ^ - signal_alias
51
- let ( word, _) = word_reader. next_word ( ) . ok_or ( & err ) ?;
52
+ let ( word, _) = word_reader. next_word ( ) ?;
52
53
let signal_alias = word. to_string ( ) ;
53
54
54
55
// $var parameter 3 a IDLE $end
55
56
// ^^^^ - full_signal_name(can extend until $end)
56
57
let mut full_signal_name = Vec :: < String > :: new ( ) ;
57
58
loop {
58
- let ( word, _) = word_reader. next_word ( ) . ok_or ( & err ) ?;
59
+ let ( word, _) = word_reader. next_word ( ) ?;
59
60
match word {
60
61
"$end" => { break }
61
62
_ => { full_signal_name. push ( word. to_string ( ) ) }
@@ -145,25 +146,17 @@ fn parse_orphaned_vars<'a>(
145
146
parse_var ( word_reader, scope_idx, vcd, signal_map) ?;
146
147
147
148
loop {
148
- let next_word = word_reader. next_word ( ) ;
149
-
150
- // we shouldn't reach the end of the file here...
151
- if next_word. is_none ( ) {
152
- let err = format ! ( "Error near {}:{}. No more words left in vcd file." , file!( ) , line!( ) ) ;
153
- Err ( err) ?;
154
- } ;
155
-
156
- let ( word, cursor) = next_word. unwrap ( ) ;
149
+ let ( word, cursor) = word_reader. next_word ( ) ?;
157
150
158
151
match word {
159
152
"$var" => {
160
153
parse_var ( word_reader, scope_idx, vcd, signal_map) ?;
161
154
}
162
155
"$scope" => { break }
163
156
_ => {
164
- let ( f , l ) = ( file ! ( ) , line ! ( ) ) ;
165
- let msg = format ! ( "Error near {f}:{l}. \
166
- Expected $scope or $var, found {word} at {cursor:?}") ;
157
+ let msg = format ! ( "Error near {}:{}. \
158
+ Expected $scope or $var, found \
159
+ {word} at {cursor:?}", file! ( ) , line! ( ) ) ;
167
160
Err ( msg) ?;
168
161
}
169
162
} ;
@@ -181,20 +174,21 @@ pub(super) fn parse_signal_tree<'a>(
181
174
182
175
// $scope module reg_mag_i $end
183
176
// ^^^^^^ - module keyword
184
- let err = format ! ( "Error near {}:{}. No more words left in vcd file." , file!( ) , line!( ) ) ;
185
- let ( keyword, cursor) = word_reader. next_word ( ) . ok_or ( & err) ?;
177
+ let ( keyword, cursor) = word_reader. next_word ( ) ?;
186
178
187
179
let expected = [ "module" , "begin" , "task" , "function" ] ;
188
180
if expected. contains ( & keyword) {
189
181
Ok ( ( ) )
190
182
} else {
191
- let err = format ! ( "found keyword `{keyword}` but expected one of `{expected:?}` on {cursor:?}" ) ;
183
+ let err = format ! ( "Error near {}:{}. \
184
+ found keyword `{keyword}` but expected one of \
185
+ {expected:?} on {cursor:?}", file!( ) , line!( ) ) ;
192
186
Err ( err)
193
187
} ?;
194
188
195
189
// $scope module reg_mag_i $end
196
190
// ^^^^^^^^^ - scope name
197
- let ( scope_name, _) = word_reader. next_word ( ) . ok_or ( & err ) ?;
191
+ let ( scope_name, _) = word_reader. next_word ( ) ?;
198
192
199
193
let curr_scope_idx = ScopeIdx ( vcd. all_scopes . len ( ) ) ;
200
194
@@ -227,7 +221,7 @@ pub(super) fn parse_signal_tree<'a>(
227
221
ident ( word_reader, "$end" ) ?;
228
222
229
223
loop {
230
- let ( word, cursor) = word_reader. next_word ( ) . ok_or ( & err ) ?;
224
+ let ( word, cursor) = word_reader. next_word ( ) ?;
231
225
let ParseResult { matched, residual} = tag ( word, "$" ) ;
232
226
match matched {
233
227
// we hope that this word starts with a `$`
@@ -251,13 +245,18 @@ pub(super) fn parse_signal_tree<'a>(
251
245
}
252
246
}
253
247
_ => {
254
- let err = format ! ( "found keyword `{residual}` but expected `$scope`, `$var`, `$comment`, or `$upscope` on {cursor:?}" ) ;
248
+ let err = format ! ( "Error near {}:{}. \
249
+ found keyword `{residual}` but expected \
250
+ `$scope`, `$var`, `$comment`, or `$upscope` \
251
+ on {cursor:?}", file!( ) , line!( ) ) ;
255
252
return Err ( err)
256
253
}
257
254
}
258
255
}
259
256
_ => {
260
- let err = format ! ( "found keyword `{matched}` but expected `$` on {cursor:?}" ) ;
257
+ let err = format ! ( "Error near {}:{}. \
258
+ found keyword `{matched}` but \
259
+ expected `$` on {cursor:?}", file!( ) , line!( ) ) ;
261
260
return Err ( err)
262
261
}
263
262
}
@@ -272,25 +271,24 @@ pub(super) fn parse_scopes<'a>(
272
271
signal_map : & mut HashMap < String , SignalIdx >
273
272
) -> Result < ( ) , String > {
274
273
// get the current word
275
- let err = format ! ( "Error near {}:{}. No more words left in vcd file." , file!( ) , line!( ) ) ;
276
- let ( word, _) = word_reader. curr_word ( ) . ok_or ( & err) ?;
274
+ let ( word, _) = word_reader. curr_word ( ) ?;
277
275
278
276
// we may have orphaned vars that occur before the first scope
279
277
if word == "$var" {
280
278
parse_orphaned_vars ( word_reader, vcd, signal_map) ?;
281
279
}
282
280
283
281
// get the current word
284
- let ( word, cursor) = word_reader. curr_word ( ) . ok_or ( & err ) ?;
282
+ let ( word, cursor) = word_reader. curr_word ( ) ?;
285
283
286
284
// the current word should be "scope", as `parse_orphaned_vars`(if it
287
285
// was called), should have terminated upon encountering "$scope".
288
286
// If `parse_orphaned_vars` was not called, `parse_scopes` should still
289
287
// have only been called if the caller encountered the word "$scope"
290
288
if word != "$scope" {
291
- let ( f , l ) = ( file ! ( ) , line ! ( ) ) ;
292
- let msg = format ! ( "Error near {f}:{l}. \
293
- Expected $scope or $var, found {word} at {cursor:?}") ;
289
+ let msg = format ! ( "Error near {}:{}. \
290
+ Expected $scope or $var, found \
291
+ {word} at {cursor:?}", file! ( ) , line! ( ) ) ;
294
292
return Err ( msg)
295
293
}
296
294
@@ -305,7 +303,7 @@ pub(super) fn parse_scopes<'a>(
305
303
// because this loop gets a word from `next_word` instead of
306
304
// `curr_word()`.
307
305
loop {
308
- let ( word, cursor) = word_reader. next_word ( ) . ok_or ( & err ) ?;
306
+ let ( word, cursor) = word_reader. next_word ( ) ?;
309
307
match word {
310
308
"$scope" => {
311
309
parse_signal_tree ( word_reader, None , vcd, signal_map) ?;
@@ -322,8 +320,9 @@ pub(super) fn parse_scopes<'a>(
322
320
}
323
321
}
324
322
_ => {
325
- let err = format ! ( "found keyword `{word}` but expected one \
326
- of `{expected_keywords:?}` on {cursor:?}") ;
323
+ let err = format ! ( "Error near {}:{} \
324
+ found keyword `{word}` but expected one of \
325
+ {expected_keywords:?} on {cursor:?}", file!( ) , line!( ) ) ;
327
326
return Err ( err)
328
327
329
328
}
0 commit comments