1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859openPpxlibopenStdLabelsopenMiscellany(** {1 Longident utility functions} *)(** Takes a [Location.t] value and marks it as a ghost location
- This is useful for new AST nodes (to indicate that the node
did not exist in the source file) *)letghostify(loc:Location.t):Location.t={locwithloc_ghost=true}(** Alias for [String.uncapitalize_ascii] *)letuncapitalize:string->string=String.uncapitalize_ascii(** Converts a [string] to a [Longident]
- Alias for [Longident.parse] *)letlident_of_string:string->Longident.t=Longident.parse(** Converts a string [x] at location [loc] to a [Longident] *)letlident_loc_of_string(x:string)~(loc:Location.t):Longident.tLocation.loc=with_loc(Longident.parsex)~loc(** Converts a [Longident] to a regular string *)letstring_of_lident(lident:Longident.t):string=letxs=Astlib.Longident.flattenlidentinmatchxswith|[]->""|[x]->x|_->String.concat~sep:"."xs(** Maps a [string -> string] function via structural recursion over a [Longident.t]
(prefixes in [Ldot]s are left unchanged) *)letrecmap_lident~(f:string->string)(l:Longident.t):Longident.t=matchlwith|Lidents->Lident(fs)|Ldot(prefix,s)->Ldot(prefix,fs)|Lapply(l1,l2)->Lapply(map_lident~fl1,map_lident~fl2)(** Uncapitalizes the final [Lident] in a [Longident.t]
(prefixes in [Ldot]s are left unchanged) *)letuncapitalize_lident(l:Longident.t):Longident.t=map_lident~f:uncapitalizel(** Capitalizes the final [Lident] in a [Longident.t]
(prefixes in [Ldot]s are left unchanged) *)letcapitalize_lident(l:Longident.t):Longident.t=map_lident~f:String.capitalize_asciil(** [add_lident_prefix p l] adds the prefix [p] to the identifier [l]
using dot notation, returning a new identifier [p.l] *)letadd_lident_prefix(prefix:string)(lident:Longident.t):Longident.t=Ldot(Lidentprefix,string_of_lident(uncapitalize_lidentlident))(** [add_lident_loc_prefix] is like [add_lident_prefix],
but attaches location information to the resultant identifier *)letadd_lident_loc_prefix(prefix:string)({txt;loc}:Longident.tLocation.loc):Longident.tLocation.loc=with_loc~loc@@add_lident_prefixprefixtxt