summaryrefslogtreecommitdiffstats
path: root/perl_checker.src
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-04-28 12:34:42 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-04-28 12:34:42 +0000
commit213d18c0842317ae689d860d2882aac0543aeeea (patch)
tree156054215090c433bf9136a08b6626a2e2489940 /perl_checker.src
parent5086a51d09b7d5333b8b39927dba18f04c249237 (diff)
downloadperl_checker-213d18c0842317ae689d860d2882aac0543aeeea.tar
perl_checker-213d18c0842317ae689d860d2882aac0543aeeea.tar.gz
perl_checker-213d18c0842317ae689d860d2882aac0543aeeea.tar.bz2
perl_checker-213d18c0842317ae689d860d2882aac0543aeeea.tar.xz
perl_checker-213d18c0842317ae689d860d2882aac0543aeeea.zip
get_pos_from_expr() (previously named get_pos_from_tree()) is useful, even in parser_helper
Diffstat (limited to 'perl_checker.src')
-rw-r--r--perl_checker.src/parser_helper.ml34
-rw-r--r--perl_checker.src/parser_helper.mli2
-rw-r--r--perl_checker.src/tree.ml36
3 files changed, 37 insertions, 35 deletions
diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml
index cefff7b..fc578a1 100644
--- a/perl_checker.src/parser_helper.ml
+++ b/perl_checker.src/parser_helper.ml
@@ -168,6 +168,40 @@ let from_array esp =
| Deref(I_array, ident) -> ident
| _ -> internal_error "from_array"
+let rec get_pos_from_expr = function
+ | Anonymous_sub(_, _, pos)
+ | String(_, pos)
+ | Call_op(_, _, pos)
+ | Perl_checker_comment(_, pos)
+ | My_our(_, _, pos)
+ | Raw_string(_, pos)
+ | Num(_, pos)
+ | Ident(_, _, pos)
+ -> pos
+
+ | Package e
+ | Ref(_, e)
+ | Deref(_, e)
+ | Sub_declaration(e, _, _, _)
+ | Deref_with(_, _, e, _)
+ | Use(e, _)
+ | Call(e, _)
+ | Method_call(_, e, _)
+ -> get_pos_from_expr e
+
+ | Diamond(option_e)
+ -> if option_e = None then raw_pos2pos bpos else get_pos_from_expr (some option_e)
+
+ | List l
+ | Block l
+ -> if l = [] then raw_pos2pos bpos else get_pos_from_expr (List.hd l)
+
+ | Semi_colon
+ | Too_complex
+ | Undef
+ | Label _
+ -> raw_pos2pos bpos
+
let msg_with_rawpos (start, end_) msg = Info.pos2sfull_current start end_ ^ msg
let die_with_rawpos raw_pos msg = failwith (msg_with_rawpos raw_pos msg)
let warn raw_pos msg = print_endline_flush (msg_with_rawpos raw_pos msg)
diff --git a/perl_checker.src/parser_helper.mli b/perl_checker.src/parser_helper.mli
index effa227..0478477 100644
--- a/perl_checker.src/parser_helper.mli
+++ b/perl_checker.src/parser_helper.mli
@@ -43,6 +43,7 @@ val is_a_string : Types.fromparser -> bool
val is_parenthesized : Types.fromparser -> bool
val un_parenthesize : Types.fromparser -> Types.fromparser
val un_parenthesize_full : Types.fromparser -> Types.fromparser
+val un_parenthesize_full_l : Types.fromparser list -> Types.fromparser list
val is_always_true : Types.fromparser -> bool
val is_always_false : Types.fromparser -> bool
val not_complex : Types.fromparser -> bool
@@ -53,6 +54,7 @@ val variable2s : Types.context * string -> string
val is_same_fromparser : Types.fromparser -> Types.fromparser -> bool
val from_scalar : Types.fromparser Types.any_spaces_pos -> Types.fromparser
val from_array : Types.fromparser Types.any_spaces_pos -> Types.fromparser
+val get_pos_from_expr : Types.fromparser -> Types.pos
val msg_with_rawpos : int * int -> string -> string
val die_with_rawpos : int * int -> string -> 'a
val warn : int * int -> string -> unit
diff --git a/perl_checker.src/tree.ml b/perl_checker.src/tree.ml
index 112c8b3..5c762ac 100644
--- a/perl_checker.src/tree.ml
+++ b/perl_checker.src/tree.ml
@@ -64,40 +64,6 @@ let s2context s =
| _ -> I_raw, s
-let rec get_pos_in_tree = function
- | Anonymous_sub(_, _, pos)
- | String(_, pos)
- | Call_op(_, _, pos)
- | Perl_checker_comment(_, pos)
- | My_our(_, _, pos)
- | Raw_string(_, pos)
- | Num(_, pos)
- | Ident(_, _, pos)
- -> pos
-
- | Package e
- | Ref(_, e)
- | Deref(_, e)
- | Sub_declaration(e, _, _, _)
- | Deref_with(_, _, e, _)
- | Use(e, _)
- | Call(e, _)
- | Method_call(_, e, _)
- -> get_pos_in_tree e
-
- | Diamond(option_e)
- -> if option_e = None then raw_pos2pos bpos else get_pos_in_tree (some option_e)
-
- | List l
- | Block l
- -> if l = [] then raw_pos2pos bpos else get_pos_in_tree (List.hd l)
-
- | Semi_colon
- | Too_complex
- | Undef
- | Label _
- -> raw_pos2pos bpos
-
let get_current_package t =
match t with
| Package(Ident _ as ident) :: body ->
@@ -127,7 +93,7 @@ let from_qw_raw = function
| String([s, List []], pos)
| Raw_string(s, pos) -> Some(s, pos)
| Ident(_, _, pos) as ident -> Some(string_of_Ident ident, pos)
- | e -> warn_with_pos (get_pos_in_tree e) "not recognised yet"; None
+ | e -> warn_with_pos (get_pos_from_expr e) "not recognised yet"; None
) l)) []
| e -> warn_with_pos (get_pos_in_tree e) "not recognised yet"; []