File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -1033,7 +1033,23 @@ impl<'a> Parser<'a> {
1033
1033
} else {
1034
1034
if let Err ( e) = self . expect ( t) {
1035
1035
fe ( e) ;
1036
- break ;
1036
+ // Attempt to keep parsing if it was a similar separator
1037
+ if let Some ( ref tokens) = t. similar_tokens ( ) {
1038
+ if tokens. contains ( & self . token ) {
1039
+ self . bump ( ) ;
1040
+ }
1041
+ }
1042
+ // Attempt to keep parsing if it was an omitted separator
1043
+ match f ( self ) {
1044
+ Ok ( t) => {
1045
+ v. push ( t) ;
1046
+ continue ;
1047
+ } ,
1048
+ Err ( mut e) => {
1049
+ e. cancel ( ) ;
1050
+ break ;
1051
+ }
1052
+ }
1037
1053
}
1038
1054
}
1039
1055
}
Original file line number Diff line number Diff line change @@ -433,6 +433,16 @@ impl Token {
433
433
} )
434
434
}
435
435
436
+ /// Returns tokens that are likely to be typed accidentally instead of the current token.
437
+ /// Enables better error recovery when the wrong token is found.
438
+ pub fn similar_tokens ( & self ) -> Option < Vec < Token > > {
439
+ match * self {
440
+ Comma => Some ( vec ! [ Dot , Lt ] ) ,
441
+ Semi => Some ( vec ! [ Colon ] ) ,
442
+ _ => None
443
+ }
444
+ }
445
+
436
446
/// Returns `true` if the token is either a special identifier or a keyword.
437
447
pub fn is_reserved_ident ( & self ) -> bool {
438
448
self . is_special_ident ( ) || self . is_used_keyword ( ) || self . is_unused_keyword ( )
You can’t perform that action at this time.
0 commit comments