summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-05-09 12:08:51 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-05-09 12:08:51 +0000
commit8445fc9a79f6050eafe070e4aec8f89a1274e171 (patch)
tree978cf1cde9247d1db8be9c48d60d47e62d75193e /perl_checker.src
parent564490341f966f7b0c1bda41fca4cb8e36536419 (diff)
downloadperl-MDK-Common-8445fc9a79f6050eafe070e4aec8f89a1274e171.tar
perl-MDK-Common-8445fc9a79f6050eafe070e4aec8f89a1274e171.tar.gz
perl-MDK-Common-8445fc9a79f6050eafe070e4aec8f89a1274e171.tar.bz2
perl-MDK-Common-8445fc9a79f6050eafe070e4aec8f89a1274e171.tar.xz
perl-MDK-Common-8445fc9a79f6050eafe070e4aec8f89a1274e171.zip
for flexible detecting of functional patterns
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser_helper.ml22
1 files changed, 13 insertions, 9 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index a516d04..1f30eb5 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -644,15 +644,19 @@ let cook_call_op op para pos =
| e -> if is_not_a_scalar e then warn_rule (sprintf "\"%s\" is only useful with a scalar" op))
| "foreach" ->
(match para with
- | [ _; Block [ Call_op("if infix", [ List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, (Ident _ as l)) ; Deref(I_scalar, Ident(None, "_", _)) ]) ] ; _ ], _) ; Semi_colon ] ] ->
- let l = string_of_Ident l in
- warn_rule (sprintf "use \"push @%s, grep { ... } ...\" instead of \"foreach (...) { push @%s, $_ if ... }\"\n or sometimes \"@%s = grep { ... } ...\"" l l l)
- | [ _; Block [ Call_op("if infix", [ List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, (Ident _ as l)); _ ]) ] ; _ ], _) ; Semi_colon ] ] ->
- let l = string_of_Ident l in
- warn_rule (sprintf "use \"push @%s, map { ... ? ... : () } ...\" instead of \"foreach (...) { push @%s, ... if ... }\"\n or sometimes \"@%s = map { ... ? ... : () } ...\"\n or sometimes \"@%s = map { if_(..., ...) } ...\"" l l l l)
- | [ _; Block [ List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, (Ident _ as l)); _ ]) ] ; Semi_colon ] ] ->
- let l = string_of_Ident l in
- warn_rule (sprintf "use \"push @%s, map { ... } ...\" instead of \"foreach (...) { push @%s, ... }\"\n or sometimes \"@%s = map { ... } ...\"" l l l)
+ | [ _; Block [ expr ; Semi_colon ] ]
+ | [ _; Block [ expr ] ] ->
+ (match expr with
+ | Call_op("if infix", [ List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, (Ident _ as l)) ; Deref(I_scalar, Ident(None, "_", _)) ]) ] ; _ ], _) ->
+ let l = string_of_Ident l in
+ warn_rule (sprintf "use \"push @%s, grep { ... } ...\" instead of \"foreach (...) { push @%s, $_ if ... }\"\n or sometimes \"@%s = grep { ... } ...\"" l l l)
+ | Call_op("if infix", [ List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, (Ident _ as l)); _ ]) ] ; _ ], _) ->
+ let l = string_of_Ident l in
+ warn_rule (sprintf "use \"push @%s, map { ... ? ... : () } ...\" instead of \"foreach (...) { push @%s, ... if ... }\"\n or sometimes \"@%s = map { ... ? ... : () } ...\"\n or sometimes \"@%s = map { if_(..., ...) } ...\"" l l l l)
+ | List [ Call(Deref(I_func, Ident(None, "push", _)), [ Deref(I_array, (Ident _ as l)); _ ]) ] ->
+ let l = string_of_Ident l in
+ warn_rule (sprintf "use \"push @%s, map { ... } ...\" instead of \"foreach (...) { push @%s, ... }\"\n or sometimes \"@%s = map { ... } ...\"" l l l)
+ | _ -> ())
| _ -> ())
| "if" ->
(match para with