summaryrefslogtreecommitdiffstats
path: root/perl_checker.src/parser_helper.ml
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-12-15 16:17:52 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-12-15 16:17:52 +0000
commit5fbb34c76f4ab00cd06d337468807e21d7bef91a (patch)
treedb488c58cc909564b4c8c79a0748326b305cf5fc /perl_checker.src/parser_helper.ml
parentdc3fdb3c7a039aa6e2a1c7932ad0d232115407fc (diff)
downloadperl-MDK-Common-5fbb34c76f4ab00cd06d337468807e21d7bef91a.tar
perl-MDK-Common-5fbb34c76f4ab00cd06d337468807e21d7bef91a.tar.gz
perl-MDK-Common-5fbb34c76f4ab00cd06d337468807e21d7bef91a.tar.bz2
perl-MDK-Common-5fbb34c76f4ab00cd06d337468807e21d7bef91a.tar.xz
perl-MDK-Common-5fbb34c76f4ab00cd06d337468807e21d7bef91a.zip
check what is on the left side of "xxx =~ s///"
Diffstat (limited to 'perl_checker.src/parser_helper.ml')
-rw-r--r--perl_checker.src/parser_helper.ml10
1 files changed, 8 insertions, 2 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 74fad21..13191a5 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -63,6 +63,7 @@ let is_a_scalar = function
| Num _
| Raw_string _
| String _ -> true
+ | My_our(_, [ context, _ ], _)
| Deref_with(_, context, _, _)
| Deref(context, _) -> is_scalar_context context
| _ -> false
@@ -439,8 +440,13 @@ let check_unneeded_var_dollar_not esp =
if is_var_dollar_ esp.any.expr then warn esp.pos "\"$_ !~ /regexp/\" can be written \"!/regexp/\"" else
if is_var_number_match esp.any.expr then warn esp.pos "do not use the result of a match (eg: $1) to match another pattern"
let check_unneeded_var_dollar_s esp =
- if is_var_dollar_ esp.any.expr then warn esp.pos "\"$_ =~ s/regexp/.../\" can be written \"s/regexp/.../\"" else
- if is_var_number_match esp.any.expr then die_with_rawpos esp.pos "do not modify the result of a match (eg: $1)"
+ let expr = esp.any.expr in
+ if is_var_dollar_ expr then warn esp.pos "\"$_ =~ s/regexp/.../\" can be written \"s/regexp/.../\"" else
+ if is_var_number_match expr then die_with_rawpos esp.pos "do not modify the result of a match (eg: $1)" else
+ let expr = match expr with
+ | List [List [Call_op("=", [ expr; _], _)]] -> expr (* check $xx in ($xx = ...) =~ ... *)
+ | _ -> expr in
+ if is_a_string expr || not (is_a_scalar expr) then warn esp.pos "you can only use s/// on a variable"
let check_my esp = if esp.any <> "my" then die_rule "syntax error"
let check_foreach esp = if esp.any = "for" then warn esp.pos "write \"foreach\" instead of \"for\""