@@ -100,13 +100,25 @@ impl<StorageT: PrimInt + Unsigned> PartialEq for PathFNode<StorageT> {
100
100
101
101
impl < StorageT : PrimInt + Unsigned > Eq for PathFNode < StorageT > { }
102
102
103
- struct CPCTPlus < ' a , ' b : ' a , ' input : ' b , StorageT : ' static + Eq + Hash , ActionT : ' a > {
104
- parser : & ' a Parser < ' a , ' b , ' input , StorageT , ActionT > ,
103
+ struct CPCTPlus <
104
+ ' a ,
105
+ ' b : ' a ,
106
+ ' input : ' b ,
107
+ LexemeT : Lexeme < StorageT > ,
108
+ StorageT : ' static + Eq + Hash ,
109
+ ActionT : ' a ,
110
+ > {
111
+ parser : & ' a Parser < ' a , ' b , ' input , LexemeT , StorageT , ActionT > ,
105
112
}
106
113
107
- pub ( super ) fn recoverer < ' a , StorageT : ' static + Debug + Hash + PrimInt + Unsigned , ActionT : ' a > (
108
- parser : & ' a Parser < StorageT , ActionT > ,
109
- ) -> Box < dyn Recoverer < StorageT , ActionT > + ' a >
114
+ pub ( super ) fn recoverer <
115
+ ' a ,
116
+ LexemeT : Lexeme < StorageT > ,
117
+ StorageT : ' static + Debug + Hash + PrimInt + Unsigned ,
118
+ ActionT : ' a ,
119
+ > (
120
+ parser : & ' a Parser < LexemeT , StorageT , ActionT > ,
121
+ ) -> Box < dyn Recoverer < LexemeT , StorageT , ActionT > + ' a >
110
122
where
111
123
usize : AsPrimitive < StorageT > ,
112
124
{
@@ -117,21 +129,22 @@ impl<
117
129
' a ,
118
130
' b : ' a ,
119
131
' input : ' b ,
132
+ LexemeT : Lexeme < StorageT > ,
120
133
StorageT : ' static + Debug + Hash + PrimInt + Unsigned ,
121
134
ActionT : ' a ,
122
- > Recoverer < StorageT , ActionT > for CPCTPlus < ' a , ' b , ' input , StorageT , ActionT >
135
+ > Recoverer < LexemeT , StorageT , ActionT > for CPCTPlus < ' a , ' b , ' input , LexemeT , StorageT , ActionT >
123
136
where
124
137
usize : AsPrimitive < StorageT > ,
125
138
{
126
139
fn recover (
127
140
& self ,
128
141
finish_by : Instant ,
129
- parser : & Parser < StorageT , ActionT > ,
142
+ parser : & Parser < LexemeT , StorageT , ActionT > ,
130
143
in_laidx : usize ,
131
144
mut in_pstack : & mut Vec < StIdx > ,
132
- mut astack : & mut Vec < AStackType < ActionT , StorageT > > ,
145
+ mut astack : & mut Vec < AStackType < LexemeT , ActionT > > ,
133
146
mut spans : & mut Vec < Span > ,
134
- ) -> ( usize , Vec < Vec < ParseRepair < StorageT > > > ) {
147
+ ) -> ( usize , Vec < Vec < ParseRepair < LexemeT , StorageT > > > ) {
135
148
// This function implements a minor variant of the algorithm from "Repairing syntax errors
136
149
// in LR parsers" by Rafael Corchuelo, Jose A. Perez, Antonio Ruiz, and Miguel Toro.
137
150
//
@@ -249,9 +262,10 @@ impl<
249
262
' a ,
250
263
' b : ' a ,
251
264
' input : ' b ,
265
+ LexemeT : Lexeme < StorageT > ,
252
266
StorageT : ' static + Debug + Hash + PrimInt + Unsigned ,
253
267
ActionT : ' a ,
254
- > CPCTPlus < ' a , ' b , ' input , StorageT , ActionT >
268
+ > CPCTPlus < ' a , ' b , ' input , LexemeT , StorageT , ActionT >
255
269
where
256
270
usize : AsPrimitive < StorageT > ,
257
271
{
@@ -357,7 +371,7 @@ where
357
371
& self ,
358
372
in_laidx : usize ,
359
373
cnds : Vec < PathFNode < StorageT > > ,
360
- ) -> Vec < Vec < Vec < ParseRepair < StorageT > > > > {
374
+ ) -> Vec < Vec < Vec < ParseRepair < LexemeT , StorageT > > > > {
361
375
fn traverse < StorageT : PrimInt > (
362
376
rm : & Cactus < RepairMerge < StorageT > > ,
363
377
) -> Vec < Vec < Repair < StorageT > > > {
@@ -411,7 +425,7 @@ where
411
425
& self ,
412
426
mut laidx : usize ,
413
427
from : & [ Repair < StorageT > ] ,
414
- ) -> Vec < ParseRepair < StorageT > > {
428
+ ) -> Vec < ParseRepair < LexemeT , StorageT > > {
415
429
from. iter ( )
416
430
. map ( |y| match * y {
417
431
Repair :: InsertTerm ( token_idx) => ParseRepair :: Insert ( token_idx) ,
@@ -432,13 +446,18 @@ where
432
446
433
447
/// Apply the `repairs` to `pstack` starting at position `laidx`: return the resulting parse
434
448
/// distance and a new pstack.
435
- fn apply_repairs < ' a , StorageT : ' static + Debug + Hash + PrimInt + Unsigned , ActionT : ' a > (
436
- parser : & Parser < StorageT , ActionT > ,
449
+ fn apply_repairs <
450
+ ' a ,
451
+ LexemeT : Lexeme < StorageT > ,
452
+ StorageT : ' static + Debug + Hash + PrimInt + Unsigned ,
453
+ ActionT : ' a ,
454
+ > (
455
+ parser : & Parser < LexemeT , StorageT , ActionT > ,
437
456
mut laidx : usize ,
438
457
mut pstack : & mut Vec < StIdx > ,
439
- mut astack : & mut Option < & mut Vec < AStackType < ActionT , StorageT > > > ,
458
+ mut astack : & mut Option < & mut Vec < AStackType < LexemeT , ActionT > > > ,
440
459
mut spans : & mut Option < & mut Vec < Span > > ,
441
- repairs : & [ ParseRepair < StorageT > ] ,
460
+ repairs : & [ ParseRepair < LexemeT , StorageT > ] ,
442
461
) -> usize
443
462
where
444
463
usize : AsPrimitive < StorageT > ,
@@ -474,9 +493,13 @@ where
474
493
}
475
494
476
495
/// Simplifies repair sequences, removes duplicates, and sorts them into order.
477
- fn simplify_repairs < StorageT : ' static + Hash + PrimInt + Unsigned , ActionT > (
478
- parser : & Parser < StorageT , ActionT > ,
479
- all_rprs : & mut Vec < Vec < ParseRepair < StorageT > > > ,
496
+ fn simplify_repairs <
497
+ LexemeT : Lexeme < StorageT > ,
498
+ StorageT : ' static + Hash + PrimInt + Unsigned ,
499
+ ActionT ,
500
+ > (
501
+ parser : & Parser < LexemeT , StorageT , ActionT > ,
502
+ all_rprs : & mut Vec < Vec < ParseRepair < LexemeT , StorageT > > > ,
480
503
) where
481
504
usize : AsPrimitive < StorageT > ,
482
505
{
@@ -494,13 +517,13 @@ fn simplify_repairs<StorageT: 'static + Hash + PrimInt + Unsigned, ActionT>(
494
517
// Use a HashSet as a quick way of deduplicating repair sequences: occasionally we can end up
495
518
// with hundreds of thousands (!), and we don't have a sensible ordering on ParseRepair to make
496
519
// it plausible to do a sort and dedup.
497
- let mut hs: HashSet < Vec < ParseRepair < StorageT > > > = all_rprs. drain ( ..) . collect ( ) ;
520
+ let mut hs: HashSet < Vec < ParseRepair < LexemeT , StorageT > > > = all_rprs. drain ( ..) . collect ( ) ;
498
521
all_rprs. extend ( hs. drain ( ) ) ;
499
522
500
523
// Sort repair sequences:
501
524
// 1) by whether they contain Inserts that are %insert_avoid
502
525
// 2) by the number of repairs they contain
503
- let contains_avoid_insert = |rprs : & Vec < ParseRepair < StorageT > > | -> bool {
526
+ let contains_avoid_insert = |rprs : & Vec < ParseRepair < LexemeT , StorageT > > | -> bool {
504
527
for r in rprs. iter ( ) {
505
528
if let ParseRepair :: Insert ( tidx) = r {
506
529
if parser. grm . avoid_insert ( * tidx) {
@@ -528,13 +551,18 @@ fn simplify_repairs<StorageT: 'static + Hash + PrimInt + Unsigned, ActionT>(
528
551
/// `ParseRepair`s allow the same distance of parsing, then the `ParseRepair` which requires
529
552
/// repairs over the shortest distance is preferred. Amongst `ParseRepair`s of the same rank, the
530
553
/// ordering is non-deterministic.
531
- fn rank_cnds < ' a , StorageT : ' static + Debug + Hash + PrimInt + Unsigned , ActionT : ' a > (
532
- parser : & Parser < StorageT , ActionT > ,
554
+ fn rank_cnds <
555
+ ' a ,
556
+ LexemeT : Lexeme < StorageT > ,
557
+ StorageT : ' static + Debug + Hash + PrimInt + Unsigned ,
558
+ ActionT : ' a ,
559
+ > (
560
+ parser : & Parser < LexemeT , StorageT , ActionT > ,
533
561
finish_by : Instant ,
534
562
in_laidx : usize ,
535
563
in_pstack : & [ StIdx ] ,
536
- in_cnds : Vec < Vec < Vec < ParseRepair < StorageT > > > > ,
537
- ) -> Vec < Vec < ParseRepair < StorageT > > >
564
+ in_cnds : Vec < Vec < Vec < ParseRepair < LexemeT , StorageT > > > > ,
565
+ ) -> Vec < Vec < ParseRepair < LexemeT , StorageT > > >
538
566
where
539
567
usize : AsPrimitive < StorageT > ,
540
568
{
@@ -603,9 +631,9 @@ mod test {
603
631
parser:: { test:: do_parse, LexParseError , ParseRepair , RecoveryKind } ,
604
632
} ;
605
633
606
- fn pp_repairs < StorageT : ' static + Hash + PrimInt + Unsigned > (
634
+ fn pp_repairs < LexemeT : Lexeme < StorageT > , StorageT : ' static + Hash + PrimInt + Unsigned > (
607
635
grm : & YaccGrammar < StorageT > ,
608
- repairs : & [ ParseRepair < StorageT > ] ,
636
+ repairs : & [ ParseRepair < LexemeT , StorageT > ] ,
609
637
) -> String
610
638
where
611
639
usize : AsPrimitive < StorageT > ,
@@ -623,9 +651,12 @@ mod test {
623
651
out. join ( ", " )
624
652
}
625
653
626
- fn check_all_repairs < StorageT : ' static + Debug + Hash + PrimInt + Unsigned > (
654
+ fn check_all_repairs <
655
+ LexemeT : Lexeme < StorageT > ,
656
+ StorageT : ' static + Debug + Hash + PrimInt + Unsigned ,
657
+ > (
627
658
grm : & YaccGrammar < StorageT > ,
628
- err : & LexParseError < StorageT > ,
659
+ err : & LexParseError < LexemeT , StorageT > ,
629
660
expected : & [ & str ] ,
630
661
) where
631
662
usize : AsPrimitive < StorageT > ,
0 commit comments