24
24
{
25
25
scope : & ' s Scope < L > ,
26
26
start_text : & ' t str ,
27
- #[ allow( dead_code) ]
28
- tracing_span : tracing:: span:: EnteredSpan ,
29
27
nonterminal_name : & ' static str ,
30
28
successes : Vec < ( SuccessfulParse < ' t , T > , Precedence ) > ,
31
29
failures : Set < ParseError < ' t > > ,
@@ -96,21 +94,20 @@ where
96
94
name = nonterminal_name,
97
95
?scope,
98
96
?text
99
- )
100
- . entered ( ) ;
97
+ ) ;
98
+ let guard = tracing_span . enter ( ) ;
101
99
102
100
let mut parser = Self {
103
101
scope,
104
102
start_text : text,
105
103
nonterminal_name,
106
- tracing_span,
107
104
successes : vec ! [ ] ,
108
105
failures : set ! [ ] ,
109
106
} ;
110
107
111
108
op ( & mut parser) ;
112
109
113
- parser. finish ( )
110
+ parser. finish ( guard )
114
111
}
115
112
116
113
/// Shorthand for `parse_variant` where the parsing operation is to
@@ -184,7 +181,7 @@ where
184
181
}
185
182
}
186
183
187
- fn finish ( self ) -> ParseResult < ' t , T > {
184
+ fn finish ( self , guard : tracing :: span :: Entered < ' _ > ) -> ParseResult < ' t , T > {
188
185
// If we did not parse anything successfully, then return an error.
189
186
// There are two possibilities: some of our variants may have made
190
187
// progress but ultimately failed. If so, self.failures will be non-empty,
@@ -195,6 +192,8 @@ where
195
192
// observe that we did not consume any tokens and will ignore our messawge
196
193
// and put its own (e.g., "failed to find a Y here").
197
194
if self . successes . is_empty ( ) {
195
+ // It's better to print this result alongside the main parsing section.
196
+ drop ( guard) ;
198
197
return if self . failures . is_empty ( ) {
199
198
tracing:: trace!( "parsing failed: no variants were able to consume a single token" ) ;
200
199
Err ( ParseError :: at (
@@ -228,6 +227,8 @@ where
228
227
. all ( |( s_j, j) | i == j || Self :: is_preferable ( s_i, s_j) )
229
228
{
230
229
let ( s_i, _) = self . successes . into_iter ( ) . skip ( i) . next ( ) . unwrap ( ) ;
230
+ // It's better to print this result alongside the main parsing section.
231
+ drop ( guard) ;
231
232
tracing:: trace!( "best parse = `{:?}`" , s_i) ;
232
233
return Ok ( s_i) ;
233
234
}
0 commit comments