summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-10-01 09:22:30 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-10-01 09:22:30 +0000
commitdc1e0c5271eb328d543755e0683f07cfc2104f36 (patch)
tree9cb11377d59a5551024f809f59ce62cdda620c76 /perl_checker.src
parentacc88e52f399dbc121170ab7ec3b0d4b99d58a72 (diff)
downloadperl-MDK-Common-dc1e0c5271eb328d543755e0683f07cfc2104f36.tar
perl-MDK-Common-dc1e0c5271eb328d543755e0683f07cfc2104f36.tar.gz
perl-MDK-Common-dc1e0c5271eb328d543755e0683f07cfc2104f36.tar.bz2
perl-MDK-Common-dc1e0c5271eb328d543755e0683f07cfc2104f36.tar.xz
perl-MDK-Common-dc1e0c5271eb328d543755e0683f07cfc2104f36.zip
new warnings:
- you can replace [^\s] with \S - you can replace [^\w] with \W
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/lexer.mll21
1 files changed, 15 insertions, 6 deletions
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