diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2003-02-06 00:30:07 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2003-02-06 00:30:07 +0000 |
commit | 6725c24385e0605dba75400f6da3a46af6439d7a (patch) | |
tree | c51a0a2a4728d1a31ea3afacbcb9a7f40723bae3 | |
parent | bc6a36327b8adf17f4ece815cd9600902e0ca3ae (diff) | |
download | perl-MDK-Common-6725c24385e0605dba75400f6da3a46af6439d7a.tar perl-MDK-Common-6725c24385e0605dba75400f6da3a46af6439d7a.tar.gz perl-MDK-Common-6725c24385e0605dba75400f6da3a46af6439d7a.tar.bz2 perl-MDK-Common-6725c24385e0605dba75400f6da3a46af6439d7a.tar.xz perl-MDK-Common-6725c24385e0605dba75400f6da3a46af6439d7a.zip |
handle "\x{hex}"
-rw-r--r-- | perl_checker.src/lexer.mll | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/perl_checker.src/lexer.mll b/perl_checker.src/lexer.mll index e5d8af5..502acda 100644 --- a/perl_checker.src/lexer.mll +++ b/perl_checker.src/lexer.mll @@ -321,6 +321,18 @@ let check_multi_line_delimited_string opts (start, end_) = if check then if !current_file_current_line <> !current_string_start_line then failwith (pos2sfull_with start end_ ^ "multi-line patterns are not allowed (or use /x modifier)") + +let hex_in_string lexbuf next_rule s = + let i = + try int_of_string ("0x" ^ s) + with Failure("int_of_string") -> die_in_string lexbuf ("Bad_hex_in_string \"" ^ lexeme lexbuf ^ "\"") + in + let s = + if i < 256 then + String.make 1 (Char.chr i) + else + "\\x{" ^ s ^ "}" in + next_s s (Stack.pop next_rule) lexbuf } let stash = [ '$' '@' '%' '&' '*' ] @@ -722,12 +734,8 @@ and string_escape = parse | '\\'{ next_s "\\" (Stack.pop next_rule) lexbuf } | 'n' { next_s "\n" (Stack.pop next_rule) lexbuf } | 't' { next_s "\t" (Stack.pop next_rule) lexbuf } -| 'x' _ _ { - try - let s = String.make 1 (Char.chr (int_of_string ("0" ^ lexeme lexbuf))) in - next_s s (Stack.pop next_rule) lexbuf - with Failure("int_of_string") -> die_in_string lexbuf ("Bad_hex_in_string \"" ^ lexeme lexbuf ^ "\"") - } +| "x{" [^ '}']* '}' { hex_in_string lexbuf next_rule (skip_n_char_ 2 1 (lexeme lexbuf)) } +| 'x' [^ '{'] _ { hex_in_string lexbuf next_rule (skip_n_char 1 (lexeme lexbuf)) } | '\n' { die lexbuf "do not use \"\\\" before end-of-line, it's useless and generally bad" } | _ { next_s ("\\" ^ lexeme lexbuf) (Stack.pop next_rule) lexbuf } |