summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-04-10 19:29:19 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-04-10 19:29:19 +0000
commit70f90fe903b132a6494a1193ff14e0fbec6c173f (patch)
treea983ec08fdd17b724f55ab3da04b3dff6873597c
parentd113cbbcc0080fb0397835818c69709c5fd43178 (diff)
downloadperl_checker-70f90fe903b132a6494a1193ff14e0fbec6c173f.tar
perl_checker-70f90fe903b132a6494a1193ff14e0fbec6c173f.tar.gz
perl_checker-70f90fe903b132a6494a1193ff14e0fbec6c173f.tar.bz2
perl_checker-70f90fe903b132a6494a1193ff14e0fbec6c173f.tar.xz
perl_checker-70f90fe903b132a6494a1193ff14e0fbec6c173f.zip
enhance non_scalar case for some operators using is_not_a_scalar
-rw-r--r--perl_checker.src/parser_helper.ml30
1 files changed, 20 insertions, 10 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 9b5269f..1ddeebc 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -33,6 +33,15 @@ let is_scalar_context context = context = I_scalar
let is_not_a_scalar = function
| Deref_with(_, context, _, _)
| Deref(context, _) -> non_scalar_context context
+ | List []
+ | List(_ :: _ :: _) -> true
+ | _ -> false
+
+let is_not_a_scalar_or_array = function
+ | Deref_with(_, context, _, _)
+ | Deref(context, _) -> context = I_hash
+ | List []
+ | List(_ :: _ :: _) -> true
| _ -> false
let is_a_scalar = function
@@ -44,6 +53,10 @@ let is_a_scalar = function
| Deref(context, _) -> is_scalar_context context
| _ -> false
+let is_a_string = function
+ | String _ | Raw_string _ -> true
+ | _ -> false
+
let is_parenthesized = function
| List[]
| List[List _] -> true
@@ -562,19 +575,16 @@ let cook_call_op(op, para, pos) =
let call_op_((prio, (prev_ter, op)), ter, para) (sp, pos) =
(match op with
- | "==" | "!=" ->
- if List.exists (function Undef | List(_ :: _ :: _) -> true | _ -> false) para then
- warn_rule "don't do this"
- else if List.exists (function String _ | Raw_string _ -> true | _ -> false) para then
- warn_rule (sprintf "you should use a string operator, not the number operator \"%s\"" op)
- | "<=" | ">=" | ">" | "<" | "<=>" ->
- if List.exists (function Undef | List [] | List(_ :: _ :: _) -> true | _ -> false) para then
- (* nb: allowing @l == () *)
+ | "==" | "!=" | "<=" | ">=" | ">" | "<" | "<=>" ->
+ if List.exists (function
+ | Undef
+ | List [] -> op <> "==" && op <> "!=" (* allowing @l == () *)
+ | e -> is_not_a_scalar_or_array e) para then
warn_rule "don't do this"
- else if List.exists (function String _ | Raw_string _ -> true | _ -> false) para then
+ else if List.exists is_a_string para then
warn_rule (sprintf "you should use a string operator, not the number operator \"%s\"" op)
| "le" | "ge" | "eq" | "ne" | "gt" | "lt" | "cmp" ->
- if List.exists (function Undef | List [] | List(_ :: _ :: _) -> true | _ -> false) para then
+ if List.exists is_not_a_scalar para then
warn_rule "don't do this"
else if List.exists (function Num _ -> true | _ -> false) para then
warn_rule (sprintf "you should use a number operator, not the string operator \"%s\" (or replace the number with a string)" op)