@ -13,9 +13,14 @@ type keyword = Doc_url | Message | Mode | Name | Report_when | Severity | Sugges
type formula_id = Formula_id of string [ @@ deriving compare ]
(* * a regexp and its cached compiled version *)
type cached_regexp = { string : string ; regexp : Str . regexp Lazy . t }
let compare_cached_regexp { string = s1 } { string = s2 } = String . compare s1 s2
type alexp =
| Const of string
| Regexp of string
| Regexp of cached_regexp
| Var of string
| FId of formula_id
[ @@ deriving compare ]
@ -28,9 +33,9 @@ let formula_id_to_string fid =
match fid
with Formula_id s -> s
let alexp_to_string e =
match e
with Const s | Regexp s | Var s | FId Formula_id s -> s
let alexp_to_string = function
| Const string | Regexp { string } | Var string | FId Formula_id string
-> string
let keyword_to_string k =
match k with
@ -63,23 +68,21 @@ let is_doc_url_keyword k = match k with Doc_url -> true | _ -> false
let is_name_keyword k = match k with Name -> true | _ -> false
(* true if and only if a substring of container matches the regular
expression defined by contained
* )
let str_match_regex container re =
let rexp = Str . regexp re in
try Str . search_forward rexp container 0 > = 0
(* * true if and only if a substring of container matches the regular expression *)
let str_match_forward container regexp =
try Str . search_forward regexp container 0 > = 0
with Not_found -> false
let compare_str_with_alexp s ae =
match ae with
| Const s' | Var s'
-> String . equal s s'
| Regexp re
-> str_match_ regex s re
| Regexp { re gexp}
-> str_match_ forward s ( Lazy . force regexp )
| _
-> L . ( debug Linters Medium )
" [WARNING]: ALVAR expression '%s' is not a constant/var or regexp@ \n " ( alexp_to_string ae ) ;
" [WARNING]: ALVAR expression '%s' is not a constant, variable, or regexp@ \n "
( alexp_to_string ae ) ;
false
module FormulaIdMap = Caml . Map . Make ( struct