From dc1e0c5271eb328d543755e0683f07cfc2104f36 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Wed, 1 Oct 2003 09:22:30 +0000 Subject: new warnings: - you can replace [^\s] with \S - you can replace [^\w] with \W --- perl_checker.src/lexer.mll | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'perl_checker.src') diff --git a/perl_checker.src/lexer.mll b/perl_checker.src/lexer.mll index 672ff5c..6703aaf 100644 --- a/perl_checker.src/lexer.mll +++ b/perl_checker.src/lexer.mll @@ -241,7 +241,8 @@ let building_current_interpolated_string = Stack.create() let building_current_string = Stack.create() let current_string_start_pos = ref 0 let current_string_start_line = ref 0 -let warn lexbuf err = print_endline_flush (pos2sfull_with (lexeme_start lexbuf) (lexeme_end lexbuf) ^ err) +let warn_with_pos (start, end_) err = print_endline_flush (pos2sfull_with start end_ ^ err) +let warn lexbuf err = warn_with_pos (pos lexbuf) err let die lexbuf err = failwith (pos2sfull_with (lexeme_start lexbuf) (lexeme_end lexbuf) ^ err) let die_in_string lexbuf err = failwith (pos2sfull_with !current_string_start_pos (lexeme_end lexbuf) ^ err) @@ -280,6 +281,14 @@ let next_s s t lexbuf = t lexbuf let next t lexbuf = next_s (lexeme lexbuf) t lexbuf +let ins_re re_delimited_string lexbuf = + let s, pos = ins re_delimited_string lexbuf in + List.iter (fun (s, _) -> + if str_contains s "[^\\s]" then warn lexbuf "you can replace [^\\s] with \\S"; + if str_contains s "[^\\w]" then warn lexbuf "you can replace [^\\w] with \\W" + ) s ; + s, pos + let string_interpolate token pre lexbuf = let s = lexeme lexbuf in let local_lexbuf = Lexing.from_string (pre ^ s ^ " ") in (* add a space to help tokenizing "xxx$$" *) @@ -519,7 +528,7 @@ rule token = parse else ( delimit_char := '/' ; current_string_start_line := !current_file_current_line; - let s, pos = ins re_delimited_string lexbuf in + let s, pos = ins_re re_delimited_string lexbuf in let opts, _ = raw_ins pattern_options lexbuf in check_multi_line_delimited_string (Some opts) pos ; PATTERN(s, opts, pos) @@ -531,7 +540,7 @@ rule token = parse else ( putback lexbuf 1 ; delimit_char := '/' ; - let s, pos = ins re_delimited_string lexbuf in + let s, pos = ins_re re_delimited_string lexbuf in let opts, _ = raw_ins pattern_options lexbuf in PATTERN(s, opts, pos) ) @@ -540,7 +549,7 @@ rule token = parse | "m" pattern_separator { set_delimit_char lexbuf "m" ; current_string_start_line := !current_file_current_line; - let s, pos = ins re_delimited_string lexbuf in + let s, pos = ins_re re_delimited_string lexbuf in let opts, _ = raw_ins pattern_options lexbuf in check_multi_line_delimited_string (Some opts) pos ; PATTERN(s, opts, pos) @@ -549,7 +558,7 @@ rule token = parse | "qr" pattern_separator { set_delimit_char lexbuf "qr" ; current_string_start_line := !current_file_current_line; - let s, pos = ins re_delimited_string lexbuf in + let s, pos = ins_re re_delimited_string lexbuf in let opts, _ = raw_ins pattern_options lexbuf in check_multi_line_delimited_string (Some opts) pos ; QR_PATTERN(s, opts, pos) @@ -558,7 +567,7 @@ rule token = parse | "s" pattern_separator { set_delimit_char lexbuf "s" ; current_string_start_line := !current_file_current_line; - let s1, (start, _) = ins re_delimited_string lexbuf in + let s1, (start, _) = ins_re re_delimited_string lexbuf in let s2, (_, end_) = ins delimited_string lexbuf in let opts, _ = raw_ins pattern_options lexbuf in let pos = start, end_ in -- cgit v1.2.1