@@ -998,7 +998,14 @@ fn conditional_directive_type(
998
998
input : & str ,
999
999
offset : usize ,
1000
1000
) -> ( usize , Option < ConditionalDirectiveKind > ) {
1001
- let end_offset = offset + count_matching ( input, offset, |b| b. is_ascii_alphabetic ( ) ) ;
1001
+ let end_offset = offset
1002
+ + count_matching (
1003
+ input,
1004
+ offset,
1005
+ // Compiler directive names are ASCII only.
1006
+ // They can't start with '_' or a number, but there's no harm in including them.
1007
+ |b| matches ! ( b, b'0' ..=b'9' | b'a' ..=b'z' | b'A' ..=b'Z' | b'_' ) ,
1008
+ ) ;
1002
1009
1003
1010
let directive = & input[ offset..end_offset] ;
1004
1011
@@ -1509,11 +1516,21 @@ mod tests {
1509
1516
#[ test]
1510
1517
fn lex_compiler_directives ( ) {
1511
1518
run_test (
1512
- "(*$message*) {$foo *) } (*$bar aa {}*)" ,
1519
+ "
1520
+ (*$message*)
1521
+ {$foo *) }
1522
+ (*$bar aa {}*)
1523
+ {$if1}
1524
+ {$if9}
1525
+ {$if_}
1526
+ " ,
1513
1527
& [
1514
1528
( "(*$message*)" , TT :: CompilerDirective ) ,
1515
1529
( "{$foo *) }" , TT :: CompilerDirective ) ,
1516
1530
( "(*$bar aa {}*)" , TT :: CompilerDirective ) ,
1531
+ ( "{$if1}" , TT :: CompilerDirective ) ,
1532
+ ( "{$if9}" , TT :: CompilerDirective ) ,
1533
+ ( "{$if_}" , TT :: CompilerDirective ) ,
1517
1534
] ,
1518
1535
) ;
1519
1536
[
0 commit comments