@ -8,30 +8,42 @@
* /
open ! IStd ;
/* internally it uses reversed list to store qualified name, for example: ["get", "shared_ptr<int>", "std"] */
type t = list string [ @@ deriving compare ] ;
let equal = [ % compare . equal : t ] ;
let empty = [] ;
let append_qualifier quals qual :: qual = > List . append quals [ qual ] ;
let append_qualifier quals qual :: qual = > List . cons qual quals ;
let to_list quals = > quals ;
let extract_last =
fun
| [ last , ... rest ] = > Some ( last , rest )
| [] = > None ;
let of_list quals = > quals ;
let to_list = List . rev ;
let to_rev_list = ident ;
let of_list = List . rev ;
let of_rev_list = ident ;
let cpp_separator = " :: " ;
/* This is simplistic and will give the wrong answer in some cases, eg
" foo<bar::baz<goo>>::someMethod " will get parsed as [ " foo<bar " , " baz<goo>> " ,
" someMethod " ] . Avoid using it if possible * /
let of_qual_string = {
let of_qual_string str = > {
let class_sep_regex = Str . regexp_string cpp_separator ;
/* wait until here to define the function so that [class_sep_regex] is only computed once */
Str . split class_sep_regex
Str . split class_sep_regex str | > List . rev
} ;
let to_qual_string = String . concat sep :: cpp_separator ;
let to_separated_string quals sep :: sep = > List . rev quals | > String . concat sep :: sep ;
let to_qual_string = to_separated_string sep :: cpp_separator ;
let pp fmt quals = > Format . fprintf fmt " %s " ( to_qual_string quals ) ;
@ -39,7 +51,7 @@ let module Match = {
type quals_matcher = Str . regexp ;
let matching_separator = " # " ;
let regexp_string_of_qualifiers quals = >
Str . quote ( String . concat sep :: matching_separator quals ) ^ " $ " ;
Str . quote ( to_separated_string sep :: matching_separator quals ) ^ " $ " ;
let qualifiers_list_matcher quals_list = >
(
if ( List . is_empty quals_list ) {
@ -66,6 +78,6 @@ let module Match = {
let no_template_name s = > List . hd_exn ( String . split on :: '<' s ) ;
List . map f :: no_template_name quals
} ;
Str . string_match matcher ( String . concat sep :: matching_separator normalized_qualifiers ) 0
Str . string_match matcher ( to_separated_string sep :: matching_separator normalized_qualifiers ) 0
} ;
} ;