@@ -30,12 +30,12 @@ where
30
30
scope : & ' s Scope < L > ,
31
31
start_text : & ' t str ,
32
32
nonterminal_name : & ' static str ,
33
- successes : Vec < ( SuccessfulParse < ' t , T > , Precedence ) > ,
33
+ successes : Vec < SuccessfulParse < ' t , T > > ,
34
34
failures : Set < ParseError < ' t > > ,
35
35
}
36
36
37
- #[ derive( Debug , PartialEq , Eq , PartialOrd , Ord ) ]
38
- struct Precedence ( usize ) ;
37
+ #[ derive( Debug , PartialEq , Eq , PartialOrd , Ord , Clone , Copy ) ]
38
+ pub struct Precedence ( usize ) ;
39
39
40
40
/// The "active variant" struct is the main struct
41
41
/// you will use if you are writing custom parsing logic.
@@ -152,6 +152,8 @@ where
152
152
) ;
153
153
let guard = span. enter ( ) ;
154
154
155
+ let variant_precedence = Precedence ( variant_precedence) ;
156
+
155
157
let mut active_variant = ActiveVariant {
156
158
scope : self . scope ,
157
159
text : self . start_text ,
@@ -172,14 +174,12 @@ where
172
174
active_variant. reductions . push ( variant_name) ;
173
175
}
174
176
175
- self . successes . push ( (
176
- SuccessfulParse {
177
- text : active_variant. text ,
178
- reductions : active_variant. reductions ,
179
- value,
180
- } ,
181
- Precedence ( variant_precedence) ,
182
- ) ) ;
177
+ self . successes . push ( SuccessfulParse {
178
+ text : active_variant. text ,
179
+ reductions : active_variant. reductions ,
180
+ precedence : variant_precedence,
181
+ value,
182
+ } ) ;
183
183
tracing:: trace!( "success: {:?}" , self . successes. last( ) . unwrap( ) ) ;
184
184
}
185
185
@@ -242,7 +242,7 @@ where
242
242
. zip ( 0 ..)
243
243
. all ( |( s_j, j) | i == j || Self :: is_preferable ( s_i, s_j) )
244
244
{
245
- let ( s_i, _ ) = self . successes . into_iter ( ) . skip ( i) . next ( ) . unwrap ( ) ;
245
+ let s_i = self . successes . into_iter ( ) . skip ( i) . next ( ) . unwrap ( ) ;
246
246
// It's better to print this result alongside the main parsing section.
247
247
drop ( guard) ;
248
248
tracing:: trace!( "best parse = `{:?}`" , s_i) ;
@@ -257,19 +257,13 @@ where
257
257
) ;
258
258
}
259
259
260
- fn is_preferable (
261
- s_i : & ( SuccessfulParse < T > , Precedence ) ,
262
- s_j : & ( SuccessfulParse < T > , Precedence ) ,
263
- ) -> bool {
264
- let ( parse_i, prec_i) = s_i;
265
- let ( parse_j, prec_j) = s_j;
266
-
260
+ fn is_preferable ( s_i : & SuccessfulParse < T > , s_j : & SuccessfulParse < T > ) -> bool {
267
261
fn has_prefix < T : Eq > ( l1 : & [ T ] , l2 : & [ T ] ) -> bool {
268
262
l1. len ( ) > l2. len ( ) && ( 0 ..l2. len ( ) ) . all ( |i| l1[ i] == l2[ i] )
269
263
}
270
264
271
- prec_i > prec_j
272
- || ( prec_i == prec_j && has_prefix ( & parse_i . reductions , & parse_j . reductions ) )
265
+ s_i . precedence > s_j . precedence
266
+ || ( s_i . precedence == s_j . precedence && has_prefix ( & s_i . reductions , & s_j . reductions ) )
273
267
}
274
268
}
275
269
@@ -686,6 +680,7 @@ where
686
680
let SuccessfulParse {
687
681
text,
688
682
reductions,
683
+ precedence : _,
689
684
value,
690
685
} = op ( self . scope , self . text ) ?;
691
686
0 commit comments