@@ -57,6 +57,7 @@ pub enum HeaderErrorKind {
57
57
MissingGrmtoolsSection ,
58
58
IllegalName ,
59
59
ExpectedToken ( char ) ,
60
+ UnexpectedToken ( char , & ' static str ) ,
60
61
DuplicateEntry ,
61
62
InvalidEntry ( & ' static str ) ,
62
63
ConversionError ( & ' static str , & ' static str ) ,
@@ -67,7 +68,10 @@ impl fmt::Display for HeaderErrorKind {
67
68
let s = match self {
68
69
HeaderErrorKind :: MissingGrmtoolsSection => "Missing %grmtools section" ,
69
70
HeaderErrorKind :: IllegalName => "Illegal name" ,
70
- HeaderErrorKind :: ExpectedToken ( c) => & format ! ( "Expected token: '{}" , c) ,
71
+ HeaderErrorKind :: ExpectedToken ( c) => & format ! ( "Expected token: '{}'" , c) ,
72
+ HeaderErrorKind :: UnexpectedToken ( c, hint) => {
73
+ & format ! ( "Unxpected token: '{}', {} " , c, hint)
74
+ }
71
75
HeaderErrorKind :: InvalidEntry ( s) => & format ! ( "Invalid entry: '{}'" , s) ,
72
76
HeaderErrorKind :: DuplicateEntry => "Duplicate Entry" ,
73
77
HeaderErrorKind :: ConversionError ( t, err_str) => {
@@ -430,7 +434,16 @@ impl<'input> GrmtoolsSectionParser<'input> {
430
434
break ;
431
435
}
432
436
}
433
- if let Some ( i) = self . lookahead_is ( "}" , i) {
437
+ if let Some ( j) = self . lookahead_is ( "*" , i) {
438
+ errs. push ( HeaderError {
439
+ kind : HeaderErrorKind :: UnexpectedToken (
440
+ '*' ,
441
+ "perhaps this is a glob, in which case it requires string quoting." ,
442
+ ) ,
443
+ locations : vec ! [ Span :: new( i, j) ] ,
444
+ } ) ;
445
+ Err ( errs)
446
+ } else if let Some ( i) = self . lookahead_is ( "}" , i) {
434
447
if errs. is_empty ( ) {
435
448
Ok ( ( ret, i) )
436
449
} else {
@@ -439,7 +452,7 @@ impl<'input> GrmtoolsSectionParser<'input> {
439
452
} else {
440
453
errs. push ( HeaderError {
441
454
kind : HeaderErrorKind :: ExpectedToken ( '}' ) ,
442
- locations : vec ! [ Span :: new( section_start_pos, self . src . len ( ) ) ] ,
455
+ locations : vec ! [ Span :: new( section_start_pos, i ) ] ,
443
456
} ) ;
444
457
Err ( errs)
445
458
}
@@ -470,10 +483,22 @@ impl<'input> GrmtoolsSectionParser<'input> {
470
483
i + m. end ( ) ,
471
484
) )
472
485
}
473
- None => Err ( HeaderError {
474
- kind : HeaderErrorKind :: IllegalName ,
475
- locations : vec ! [ Span :: new( i, i) ] ,
476
- } ) ,
486
+ None => {
487
+ if self . src [ i..] . starts_with ( "*" ) {
488
+ Err ( HeaderError {
489
+ kind : HeaderErrorKind :: UnexpectedToken (
490
+ '*' ,
491
+ "perhaps this is a glob, in which case it requires string quoting." ,
492
+ ) ,
493
+ locations : vec ! [ Span :: new( i, i) ] ,
494
+ } )
495
+ } else {
496
+ Err ( HeaderError {
497
+ kind : HeaderErrorKind :: IllegalName ,
498
+ locations : vec ! [ Span :: new( i, i) ] ,
499
+ } )
500
+ }
501
+ }
477
502
}
478
503
}
479
504
@@ -697,4 +722,25 @@ mod test {
697
722
assert_eq ! ( errs[ 0 ] . locations. len( ) , 3 ) ;
698
723
}
699
724
}
725
+
726
+ #[ test]
727
+ fn test_unquoted_globs ( ) {
728
+ let srcs = [
729
+ "%grmtools {test_files: *.test,}" ,
730
+ "%grmtools {test_files: foo*.test,}" ,
731
+ ] ;
732
+ for src in srcs {
733
+ let parser = GrmtoolsSectionParser :: new ( src, true ) ;
734
+ let res = parser. parse ( ) ;
735
+ let errs = res. unwrap_err ( ) ;
736
+ assert_eq ! ( errs. len( ) , 1 ) ;
737
+ match errs[ 0 ] {
738
+ HeaderError {
739
+ kind : HeaderErrorKind :: UnexpectedToken ( '*' , _) ,
740
+ locations : _,
741
+ } => ( ) ,
742
+ _ => panic ! ( "Expected glob specific error" ) ,
743
+ }
744
+ }
745
+ }
700
746
}
0 commit comments