@@ -25,6 +25,7 @@ pub struct RegexOptions {
2525 pub dot_matches_new_line : bool ,
2626 pub multi_line : bool ,
2727 pub octal : bool ,
28+ pub posix_escapes : bool ,
2829 pub case_insensitive : Option < bool > ,
2930 pub swap_greed : Option < bool > ,
3031 pub ignore_whitespace : Option < bool > ,
@@ -38,6 +39,7 @@ pub const DEFAULT_REGEX_OPTIONS: RegexOptions = RegexOptions {
3839 dot_matches_new_line : true ,
3940 multi_line : true ,
4041 octal : true ,
42+ posix_escapes : false ,
4143 case_insensitive : None ,
4244 ignore_whitespace : None ,
4345 swap_greed : None ,
@@ -650,7 +652,7 @@ mod test {
650652 }
651653
652654 #[ test]
653- fn test_escapes ( ) {
655+ fn test_posix_escapes ( ) {
654656 let src = r#"%%
655657\\ 'slash'
656658\a 'alert'
@@ -663,7 +665,11 @@ mod test {
663665\q 'normal_char'
664666"#
665667 . to_string ( ) ;
666- let lexerdef = LRNonStreamingLexerDef :: < DefaultLexerTypes < u8 > > :: from_str ( & src) . unwrap ( ) ;
668+ let mut options = DEFAULT_REGEX_OPTIONS ;
669+ options. posix_escapes = true ;
670+ let lexerdef =
671+ LRNonStreamingLexerDef :: < DefaultLexerTypes < u8 > > :: new_with_options ( & src, options)
672+ . unwrap ( ) ;
667673 let lexemes = lexerdef
668674 . lexer ( "\\ \x07 \x08 \x0c \n \r \t \x0b q" )
669675 . iter ( )
@@ -676,6 +682,37 @@ mod test {
676682 }
677683 }
678684
685+ #[ test]
686+ fn test_non_posix_escapes ( ) {
687+ let src = r#"%%
688+ \\ 'slash'
689+ \a 'alert'
690+ a\b a 'work_break'
691+ \f 'feed'
692+ \n 'newline'
693+ \r 'return'
694+ \t 'tab'
695+ \v 'vtab'
696+ \q 'normal_char'
697+ "#
698+ . to_string ( ) ;
699+ let mut options = DEFAULT_REGEX_OPTIONS ;
700+ options. posix_escapes = false ;
701+ let lexerdef =
702+ LRNonStreamingLexerDef :: < DefaultLexerTypes < u8 > > :: new_with_options ( & src, options)
703+ . unwrap ( ) ;
704+ let lexemes = lexerdef
705+ . lexer ( "\\ \x07 a a\x0c \n \r \t \x0b q" )
706+ . iter ( )
707+ . map ( |x| x. unwrap ( ) )
708+ . collect :: < Vec < _ > > ( ) ;
709+ assert_eq ! ( lexemes. len( ) , 9 ) ;
710+ for i in 0 ..9u8 {
711+ let lexeme = lexemes[ i as usize ] ;
712+ assert_eq ! ( lexeme. tok_id( ) , i) ;
713+ }
714+ }
715+
679716 #[ test]
680717 fn test_basic_error ( ) {
681718 let src = "
0 commit comments