diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-08-12 01:41:41 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-08-12 01:41:41 +0000 |
commit | fd7e662bcbc898d127510e3c45c6735393f5da63 (patch) | |
tree | b2bdd56d562c92f9d6b865eedb45c1237e157241 | |
parent | 540c1df0d4d2569006f839f3fda5496bfbe0782d (diff) | |
download | perl-MDK-Common-fd7e662bcbc898d127510e3c45c6735393f5da63.tar perl-MDK-Common-fd7e662bcbc898d127510e3c45c6735393f5da63.tar.gz perl-MDK-Common-fd7e662bcbc898d127510e3c45c6735393f5da63.tar.bz2 perl-MDK-Common-fd7e662bcbc898d127510e3c45c6735393f5da63.tar.xz perl-MDK-Common-fd7e662bcbc898d127510e3c45c6735393f5da63.zip |
rewrite to allow a special rule for "grep"
-rw-r--r-- | perl_checker.src/parser_helper.ml | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index a32e3fd..3700f2f 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -827,6 +827,14 @@ msgstr \"\" close_out fd let call_raw force_non_builtin_func (e, para) = + let check_anonymous_block f = function + | [ Anonymous_sub _ ; Deref (I_hash, _) ] -> + warn_rule ("a hash is not a valid parameter to function " ^ f) + + | Anonymous_sub _ :: _ -> () + | _ -> warn_rule (sprintf "always use \"%s\" with a block (eg: %s { ... } @list)" f f) + in + match e with | Deref(I_func, Ident(None, f, _)) -> (match f with @@ -867,21 +875,20 @@ let call_raw force_non_builtin_func (e, para) = | [ List(String _ :: _) ] -> die_rule "don't use interpolated translated string, use %s or %d instead" | _ -> die_rule (sprintf "%s() must be used with a string" f)) - | "map" | "grep" | "grep_index" | "map_index" | "partition" | "uniq_" - | "find" - | "any" | "every" - | "find_index" - | "each_index" -> + | "map" -> (match para with | Anonymous_sub(None, Block [ List [ Call(Deref(I_func, Ident(None, "if_", _)), - [ List [ _ ; Deref(I_scalar, Ident(None, "_", _)) ] ]) ] ], _) :: _ when f = "map" -> + [ List [ _ ; Deref(I_scalar, Ident(None, "_", _)) ] ]) ] ], _) :: _ -> warn_rule "you can replace \"map { if_(..., $_) }\" with \"grep { ... }\"" - | [ Anonymous_sub _ ; Deref (I_hash, _) ] -> - warn_rule ("a hash is not a valid parameter to function " ^ f) + | _ -> check_anonymous_block f para) - | Anonymous_sub _ :: _ -> () - | _ -> warn_rule (sprintf "always use \"%s\" with a block (eg: %s { ... } @list)" f f)) + | "grep" + | "grep_index" | "map_index" | "partition" | "uniq_" + | "find" + | "any" | "every" + | "find_index" + | "each_index" -> check_anonymous_block f para | "member" -> (match para with |