summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-11-26 12:54:14 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-11-26 12:54:14 +0000
commit55b89e5b576264e738827bc5f6dbfb0483b59207 (patch)
treea3a9fc12519cfe37ee30d33207a566f1e14ecaca /perl_checker.src
parentc25787f5286ecd4c765fbf41e203036891c5f3ad (diff)
downloadperl_checker-55b89e5b576264e738827bc5f6dbfb0483b59207.tar
perl_checker-55b89e5b576264e738827bc5f6dbfb0483b59207.tar.gz
perl_checker-55b89e5b576264e738827bc5f6dbfb0483b59207.tar.bz2
perl_checker-55b89e5b576264e738827bc5f6dbfb0483b59207.tar.xz
perl_checker-55b89e5b576264e738827bc5f6dbfb0483b59207.zip
check sub { { ... }; }
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser.mly8
-rw-r--r--perl_checker.src/parser_helper.ml20
-rw-r--r--perl_checker.src/parser_helper.mli6
3 files changed, 21 insertions, 13 deletions
diff --git a/perl_checker.src/parser.mly b/perl_checker.src/parser.mly
index 22c7454..680297e 100644
--- a/perl_checker.src/parser.mly
+++ b/perl_checker.src/parser.mly
@@ -142,7 +142,7 @@ for_my:
cont: /* Continue blocks */
| {default_esp ()}
-| CONTINUE BRACKET lines BRACKET_END {sp_p($1); sp_n($2); check_block_sub $3 $4; new_esp $3.mcontext () $1 $4}
+| CONTINUE BRACKET lines BRACKET_END {sp_p($1); sp_n($2); check_block_lines $3 $4; new_esp $3.mcontext () $1 $4}
sideff: /* An expression which may have a side-effect */
| expr { new_1esp $1.any.expr $1 }
@@ -157,9 +157,9 @@ decl:
| FORMAT ASSIGN {new_esp M_none Too_complex $1 $2}
| func_decl semi_colon {if snd $1.any = None then die_rule "there is no need to pre-declare in Perl!" else (warn_rule [Warn_normalized_expressions] "please don't use prototype pre-declaration" ; new_esp M_special Too_complex $1 $2) }
| func_decl BRACKET BRACKET_END {sp_n($2); sp_0_or_cr($3); let name, proto = $1.any in new_esp M_none (sub_declaration (name, proto) [] Real_sub_declaration) $1 $3}
-| func_decl BRACKET lines BRACKET_END {sp_n($2); check_block_sub $3 $4; new_esp M_none (sub_declaration $1.any (fst $3.any) Real_sub_declaration) $1 $4}
-| func_decl BRACKET BRACKET expr BRACKET_END BRACKET_END {sp_n($2); sp_p($3); sp_p($4); sp_p($5); sp_p($6); new_esp M_none (sub_declaration $1.any [hash_ref $4] Real_sub_declaration) $1 $6}
-| func_decl BRACKET BRACKET expr BRACKET_END semi_colon BRACKET_END {sp_n($2); sp_p($3); sp_p($4); sp_p($5); sp_p($7); new_esp M_none (sub_declaration $1.any [hash_ref $4; Semi_colon] Real_sub_declaration) $1 $7}
+| func_decl BRACKET lines BRACKET_END {sp_n($2); check_block_lines $3 $4; new_esp M_none (sub_declaration $1.any (fst $3.any) Real_sub_declaration) $1 $4}
+| func_decl BRACKET BRACKET expr BRACKET_END BRACKET_END {sp_n($2); sp_p($3); sp_p($4); sp_p($5); check_block_expr false Undef $5 $6; new_esp M_none (sub_declaration $1.any [hash_ref $4] Real_sub_declaration) $1 $6}
+| func_decl BRACKET BRACKET expr BRACKET_END semi_colon BRACKET_END {sp_n($2); sp_p($3); sp_p($4); sp_p($5); check_block_expr true Semi_colon $6 $7; new_esp M_none (sub_declaration $1.any [hash_ref $4; Semi_colon] Real_sub_declaration) $1 $7}
| PACKAGE word semi_colon {sp_0_or_cr($1); sp_1($2); new_esp M_none (Package $2.any) $1 $3}
| BEGIN BRACKET lines BRACKET_END {sp_0_or_cr($1); sp_1($2); new_esp M_none (Sub_declaration(Ident(None, "BEGIN", get_pos $1), None, lines_to_Block $3 $4, Glob_assign)) $1 $4}
| END BRACKET lines BRACKET_END {sp_0_or_cr($1); sp_1($2); new_esp M_none (Sub_declaration(Ident(None, "END", get_pos $1), None, lines_to_Block $3 $4, Glob_assign)) $1 $4}
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index 0376cbb..3a0927a 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -582,18 +582,21 @@ let check_for_foreach esp arg =
| _ ->
if esp.any = "for" then warn [Warn_normalized_expressions] esp.pos "write \"foreach\" instead of \"for\""
-let check_block_sub esp_lines esp_BRACKET_END =
+let check_block_expr has_semi_colon last_expr esp_last esp_BRACKET_END =
+ sp_p esp_BRACKET_END ;
+
+ if esp_BRACKET_END.spaces = Space_cr then
+ (if not has_semi_colon then warn_verb [Warn_white_space] (get_pos_end esp_last) "missing \";\"")
+ else
+ (if last_expr = Semi_colon then warn_verb [Warn_white_space] (get_pos_end esp_last) "spurious \";\" before closing block")
+
+let check_block_lines esp_lines esp_BRACKET_END =
match fst esp_lines.any with
| [] ->
sp_0_or_cr esp_BRACKET_END
| l ->
(if List.hd l = Semi_colon then sp_0 else sp_p) esp_lines ;
- sp_p esp_BRACKET_END ;
-
- if esp_BRACKET_END.spaces = Space_cr then
- (if not (snd esp_lines.any) then warn_verb [Warn_white_space] (get_pos_end esp_lines) "missing \";\"")
- else
- (if last l = Semi_colon then warn_verb [Warn_white_space] (get_pos_end esp_lines) "spurious \";\" before closing block")
+ check_block_expr (snd esp_lines.any) (last l) esp_lines esp_BRACKET_END
let check_block_ref esp_lines esp_BRACKET_END =
let l = esp_lines.any in
@@ -679,7 +682,7 @@ let to_Deref_with(from_context, to_context, ref_, para) =
Deref_with(from_context, to_context, ref_, para)
let lines_to_Block esp_lines esp_BRACKET_END =
- check_block_sub esp_lines esp_BRACKET_END;
+ check_block_lines esp_lines esp_BRACKET_END;
Block (fst esp_lines.any)
let to_Local esp =
@@ -1301,6 +1304,7 @@ let mcontext_check_none msg expr esp =
| M_mixed l when List.exists (fun c -> c = M_none) l -> ()
| M_tuple l ->
(match expr with
+ | [Block [List l_expr]]
| [List l_expr]
| [List l_expr ; Semi_colon] ->
let rec iter = function
diff --git a/perl_checker.src/parser_helper.mli b/perl_checker.src/parser_helper.mli
index 82a57ef..ae4c55a 100644
--- a/perl_checker.src/parser_helper.mli
+++ b/perl_checker.src/parser_helper.mli
@@ -125,7 +125,11 @@ val check_for : string Types.any_spaces_pos -> unit
val check_for_foreach :
string Types.any_spaces_pos ->
Types.fromparser Types.prio_anyexpr Types.any_spaces_pos -> unit
-val check_block_sub :
+val check_block_expr :
+ bool ->
+ Types.fromparser ->
+ 'a Types.any_spaces_pos -> 'b Types.any_spaces_pos -> unit
+val check_block_lines :
(Types.fromparser list * bool) Types.any_spaces_pos ->
'a Types.any_spaces_pos -> unit
val check_block_ref :