From 239f07fc8c33f6ebfcf5729b97f9db8b8b55e348 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 14 Oct 2004 04:58:40 +0000 Subject: - add char_quote (to help emacs caml mode) - change prototype of str_begins_with --- perl_checker.src/common.ml | 9 ++++++--- perl_checker.src/common.mli | 6 ++++-- perl_checker.src/info.ml | 4 ++-- perl_checker.src/parser_helper.ml | 4 ++-- perl_checker.src/tree.ml | 4 ++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/perl_checker.src/common.ml b/perl_checker.src/common.ml index c7fe403..8a0d27e 100644 --- a/perl_checker.src/common.ml +++ b/perl_checker.src/common.ml @@ -663,7 +663,7 @@ let rec graph_sort_by eq l = let int_sort l = sort (fun a b -> a - b) l -let str_begins_with s prefix = +let str_begins_with prefix s = String.sub s 0 (min (String.length s) (String.length prefix)) = prefix let rec strstr s subs = @@ -838,12 +838,12 @@ let to_CamelCase s_ = Some (s' ^ String.sub s offset (String.length s - offset)) let concat_symlink file link = - if str_begins_with link "..//" then (* ..//foo => /foo *) + if str_begins_with "..//" link then (* ..//foo => /foo *) skip_n_char 3 link else let file = if str_ends_with file "/" then chop file else file in (* s|/$|| *) let rec reduce file link = - if str_begins_with link "../" then + if str_begins_with "../" link then let file = String.sub file 0 (String.rindex file '/') in (* s|/[^/]+$|| *) reduce file (skip_n_char 3 link) else @@ -995,3 +995,6 @@ let stringSet_to_list = StringSet.elements let stringSet_add set e = StringSet.add e set let stringSet_difference = StringSet.diff let list_to_StringSet l = fold_left stringSet_add StringSet.empty l + +(* this character messes emacs caml mode *) +let char_quote = '"' diff --git a/perl_checker.src/common.mli b/perl_checker.src/common.mli index f0cd8f8..17b0ca5 100644 --- a/perl_checker.src/common.mli +++ b/perl_checker.src/common.mli @@ -2,7 +2,7 @@ exception Found exception Not_comparable exception GraphSort_circular_deps type ('a, 'b) either = Left of 'a | Right of 'b -and ('a, 'b) or_option = Or_some of 'a | Or_error of 'b +type ('a, 'b) or_option = Or_some of 'a | Or_error of 'b val internal_error : string -> 'a val id : 'a -> 'a val double : 'a -> 'a * 'a @@ -244,7 +244,7 @@ module OrderedString : sig type t = string val compare : 'a -> 'a -> int end module StringSet : sig type elt = OrderedString.t - and t = Set.Make(OrderedString).t + type t = Set.Make(OrderedString).t val empty : t val is_empty : t -> bool val mem : elt -> t -> bool @@ -268,8 +268,10 @@ module StringSet : val min_elt : t -> elt val max_elt : t -> elt val choose : t -> elt + val split : elt -> t -> t * bool * t end val stringSet_to_list : StringSet.t -> StringSet.elt list val stringSet_add : StringSet.t -> StringSet.elt -> StringSet.t val stringSet_difference : StringSet.t -> StringSet.t -> StringSet.t val list_to_StringSet : StringSet.elt list -> StringSet.t +val char_quote : char diff --git a/perl_checker.src/info.ml b/perl_checker.src/info.ml index d5a1ce8..ab76b9f 100644 --- a/perl_checker.src/info.ml +++ b/perl_checker.src/info.ml @@ -35,9 +35,9 @@ let absolute_file_to_file = let s3 = Filename.dirname s2 in (* allow up to ../../../xxx *) if String.length s3 < 4 then s2 else s3 in memoize (fun abs_file -> - if str_begins_with abs_file (short_cwd ^ "/") then + if str_begins_with (short_cwd ^ "/") abs_file then let rec to_file rel cwd = - if str_begins_with abs_file (cwd ^ "/") then + if str_begins_with (cwd ^ "/") abs_file then rel ^ skip_n_char_ (String.length cwd + 1) 0 abs_file else to_file ("../" ^ rel) (Filename.dirname cwd) diff --git a/perl_checker.src/parser_helper.ml b/perl_checker.src/parser_helper.ml index 230daf8..c317f98 100644 --- a/perl_checker.src/parser_helper.ml +++ b/perl_checker.src/parser_helper.ml @@ -728,8 +728,8 @@ let cook_call_op op para pos = | "or", [ List [ Deref(I_scalar, id) ]; List [ Call_op("=", [ Deref(I_scalar, id_); _], _) ] ] when is_same_fromparser id id_ -> warn_rule "\"$foo or $foo = ...\" can be written \"$foo ||= ...\"" - | "and", [ cond ; expr ] -> check_My_under_condition "replace \" and my $foo = ...\" with \"my $foo = && ...\"" expr - | "or", [ cond ; expr ] -> check_My_under_condition "replace \" or my $foo = ...\" with \"my $foo = ! && ...\"" expr + | "and", [ _cond ; expr ] -> check_My_under_condition "replace \" and my $foo = ...\" with \"my $foo = && ...\"" expr + | "or", [ _cond ; expr ] -> check_My_under_condition "replace \" or my $foo = ...\" with \"my $foo = ! && ...\"" expr | _ -> ()); diff --git a/perl_checker.src/tree.ml b/perl_checker.src/tree.ml index 3b0d4ea..2d630c1 100644 --- a/perl_checker.src/tree.ml +++ b/perl_checker.src/tree.ml @@ -245,7 +245,7 @@ let read_xs_extension_from_so global_vars_declared package pos = if !Flags.verbose then print_endline_flush (sprintf "using shared-object symbols from %s" so) ; fold_lines (fun () s -> let s = skip_n_char 11 s in - if str_begins_with s "XS_" then + if str_begins_with "XS_" s then let s = skip_n_char 3 s in let len = String.length s in let rec find_package_name accu i = @@ -396,7 +396,7 @@ let get_global_info_from_package from_basedir require_name build_time t = let required_packages = List.map (fun (s, (_, pos)) -> s, pos) uses in let required_packages = List.fold_left (fold_tree (fun l -> function - | Perl_checker_comment(s, pos) when str_begins_with s "require " -> + | Perl_checker_comment(s, pos) when str_begins_with "require " s -> Some((skip_n_char 8 s, pos) :: l) | Call(Deref(I_func, Ident (None, "require", pos)), [Ident _ as pkg]) -> let package = string_of_Ident pkg in -- cgit v1.2.1