@@ -149,13 +149,11 @@ where
149
149
} ;
150
150
}
151
151
152
- let pop_stack_before_return = |r : ParseResult < ' t , T > | {
153
- STACK . with_borrow_mut ( |stack| {
154
- let top = stack. pop ( ) . unwrap ( ) ;
155
- assert ! ( top. matches:: <L , T >( scope, text) ) ;
156
- } ) ;
157
- r
158
- } ;
152
+ // Pop the stack before we return
153
+ final_fn:: final_fn!( STACK . with_borrow_mut( |stack| {
154
+ let top = stack. pop( ) . unwrap( ) ;
155
+ assert!( top. matches:: <L , T >( scope, text) ) ;
156
+ } ) ) ;
159
157
160
158
// EXAMPLE: Consider this grammar
161
159
//
@@ -192,13 +190,13 @@ where
192
190
let mut values = vec ! [ ] ;
193
191
match op ( ) {
194
192
Ok ( v) => values. push ( v) ,
195
- Err ( errs) => return pop_stack_before_return ( Err ( errs) ) ,
193
+ Err ( errs) => return Err ( errs) ,
196
194
} ;
197
195
198
196
// Check whether there was recursion to begin with.
199
197
let observed = with_top ! ( |top| top. observed) ;
200
198
if !observed {
201
- return pop_stack_before_return ( Ok ( values. pop ( ) . unwrap ( ) ) ) ; // If not, we are done.
199
+ return Ok ( values. pop ( ) . unwrap ( ) ) ; // If not, we are done.
202
200
}
203
201
204
202
// OK, this is the interesting case. We may be able to get a better parse.
@@ -219,7 +217,7 @@ where
219
217
// Invoke the operation. As noted above, if we get a failed parse NOW,
220
218
// we know we already found the best result, so we can just use it.
221
219
let Ok ( value1) = op ( ) else {
222
- return pop_stack_before_return ( Ok ( values. pop ( ) . unwrap ( ) ) ) ; // If not, we are done.
220
+ return Ok ( values. pop ( ) . unwrap ( ) ) ; // If not, we are done.
223
221
} ;
224
222
225
223
tracing:: trace!( "left-recursive grammar yielded: value1 = {:?}" , value1) ;
@@ -230,7 +228,7 @@ where
230
228
// succeeds, but we have to try again to see if there's a more complex
231
229
// expression that can be produced (there isn't).
232
230
if values. iter ( ) . any ( |v| * v == value1) {
233
- return pop_stack_before_return ( Ok ( values. pop ( ) . unwrap ( ) ) ) ; // If not, we are done.
231
+ return Ok ( values. pop ( ) . unwrap ( ) ) ; // If not, we are done.
234
232
}
235
233
236
234
// Otherwise, we have to try again.
0 commit comments