diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2003-04-15 21:20:00 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2003-04-15 21:20:00 +0000 |
commit | 4e5d62458a90c5f42aa03dbf4e70b19d73506f5e (patch) | |
tree | 8d8ad7fafbb218881fbc2eaa5d025391b1cadb18 | |
parent | 3e23d94c2ebcb964d19dcaa3d0b7829c7f44c52e (diff) | |
download | perl_checker-4e5d62458a90c5f42aa03dbf4e70b19d73506f5e.tar perl_checker-4e5d62458a90c5f42aa03dbf4e70b19d73506f5e.tar.gz perl_checker-4e5d62458a90c5f42aa03dbf4e70b19d73506f5e.tar.bz2 perl_checker-4e5d62458a90c5f42aa03dbf4e70b19d73506f5e.tar.xz perl_checker-4e5d62458a90c5f42aa03dbf4e70b19d73506f5e.zip |
forbid "unless (...) { ... } else { ... }" and "unless (...) { ... } elsif (...) { ... }
-rw-r--r-- | perl_checker.src/parser.mly | 2 | ||||
-rw-r--r-- | perl_checker.src/parser_helper.ml | 4 | ||||
-rw-r--r-- | perl_checker.src/parser_helper.mli | 2 |
3 files changed, 7 insertions, 1 deletions
diff --git a/perl_checker.src/parser.mly b/perl_checker.src/parser.mly index f578f4d..0b27e80 100644 --- a/perl_checker.src/parser.mly +++ b/perl_checker.src/parser.mly @@ -117,7 +117,7 @@ line: if_then_else: /* Real conditional expressions */ | IF PAREN expr PAREN_END BRACKET lines BRACKET_END elsif else_ {sp_p($1); sp_n($2); sp_0($3); sp_0_or_cr($4); sp_p($5); mcontext_check M_scalar $3; check_block_sub $6 $7; to_Call_op (if $9.any = [] then M_none else mcontext_lmerge ($6.mcontext :: mcontext_lmaybe $8 @ [$9.mcontext])) "if" (prio_lo P_loose $3 :: Block $6.any :: $8.any @ $9.any) $1 $9} -| UNLESS PAREN expr PAREN_END BRACKET lines BRACKET_END elsif else_ {sp_p($1); sp_n($2); sp_0($3); sp_0_or_cr($4); sp_p($5); mcontext_check M_scalar $3; check_block_sub $6 $7; to_Call_op M_none "unless" (prio_lo P_loose $3 :: Block $6.any :: $8.any @ $9.any) $1 $9} +| UNLESS PAREN expr PAREN_END BRACKET lines BRACKET_END elsif else_ {sp_p($1); sp_n($2); sp_0($3); sp_0_or_cr($4); sp_p($5); mcontext_check M_scalar $3; check_block_sub $6 $7; check_unless_else $8 $9; to_Call_op M_none "unless" (prio_lo P_loose $3 :: Block $6.any :: $8.any @ $9.any) $1 $9} elsif: | {default_esp []} diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index d4c5842..0092a9f 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -466,6 +466,10 @@ let check_block_ref esp_lines esp_BRACKET_END = if esp_BRACKET_END.spaces <> Space_cr then (if l <> [] && last l = Semi_colon then warn_verb (get_pos_end esp_lines) "spurious \";\" before closing block") +let check_unless_else elsif else_ = + if elsif.any <> [] then warn elsif.pos "don't use \"elsif\" with \"unless\" (replace \"unless\" with \"if\")"; + if else_.any <> [] then warn else_.pos "don't use \"else\" with \"unless\" (replace \"unless\" with \"if\")" + let check_my_our_paren { any = ((comma_closed, _), _) } = if not comma_closed then die_rule "syntax error" diff --git a/perl_checker.src/parser_helper.mli b/perl_checker.src/parser_helper.mli index 9334d58..03d9af9 100644 --- a/perl_checker.src/parser_helper.mli +++ b/perl_checker.src/parser_helper.mli @@ -121,6 +121,8 @@ val check_block_sub : val check_block_ref : Types.fromparser list Types.any_spaces_pos -> 'a Types.any_spaces_pos -> unit +val check_unless_else : + 'a list Types.any_spaces_pos -> 'b list Types.any_spaces_pos -> unit val check_my_our_paren : ((bool * 'a) * 'b) Types.any_spaces_pos -> unit val check_simple_pattern : Types.fromparser list -> unit val only_one : Types.fromparser list Types.any_spaces_pos -> Types.fromparser |