Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file type_with_layout.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111(** Type of annotated S-expressions *)moduleList=structletmapt~f=List.rev(List.rev_mapft)endmoduleMake(Pos:sigtypetvalsexp_of_t:t->Type.tend)=structmoduleT=struct(** In [Atom (_, s, opt)], [s] is the unescaped string, that is the argument of
[Type.Atom]. When [opt] is defined, it is the source syntax of [s], that is a
string that can be printed as is if one wants to parse and print preserving
syntax. This is usually set for quoted atoms (to preserve the fact that were
quoted), but it can be useful to do the reverse: set it for atoms that can be
parsed unquoted but would be printed with quotes, to preserve the lack of quotes.
For instance:
Atom (_, "a", None) should be printed {|a|}
Atom (_, "a b", None) should be printed {|"a b"|}
Atom (_, "a", Some "\"a\"") should be printed {|"a"|}
Atom (_, "a b", Some "a b") should be printed {|a b|} or may raise, as it is
an error to constructed such an atom (doesn't parse back) *)typet=|AtomofPos.t*string*stringoption|ListofPos.t*t_or_commentlist*Pos.t(* positions of left and right parens *)andt_or_comment=|Sexpoft|Commentofcommentandcomment=|Plain_commentofPos.t*string|Sexp_commentofPos.t*commentlist*tendincludeTmoduletypeS=sigincludemoduletypeofTvalsexp_of_t:t->Type.tvalsexp_of_comment:comment->Type.tvalsexp_of_t_or_comment:t_or_comment->Type.tendmoduleTo_sexp:sigvalof_t:t->Type.tvalof_comment:comment->Type.tvalof_t_or_comment:t_or_comment->Type.tend=struct(* maybe we can actually use conv here, instead of inlining it *)letof_pos=Pos.sexp_of_tletof_stringx=Type.Atomxletof_listof_axs=Type.List(List.map~f:of_axs)letof_optionof_a=function|Somex->Type.List[of_ax]|None->Type.List[];;letrecof_t=function|Atom(v1,v2,v3)->Type.List[Type.Atom"Atom";of_posv1;of_stringv2;of_optionof_stringv3]|List(v1,v2,v3)->Type.List[Type.Atom"List";of_posv1;of_listof_t_or_commentv2;of_posv3]andof_t_or_comment=function|Sexpt->Type.List[Type.Atom"Sexp";of_tt]|Commentc->Type.List[Type.Atom"Comment";of_commentc]andof_comment=function|Plain_comment(v1,v2)->Type.List[Type.Atom"Plain_comment";of_posv1;of_stringv2]|Sexp_comment(v1,v2,v3)->Type.List[Type.Atom"Sexp_comment";of_posv1;of_listof_commentv2;of_tv3];;endletsexp_of_t=To_sexp.of_tletsexp_of_comment=To_sexp.of_commentletsexp_of_t_or_comment=To_sexp.of_t_or_commentendincludeMake(Src_pos.Relative)moduleParsed=Make(Src_pos.Absolute)letrelativize=letrel~outer_pp=Src_pos.Absolute.diffpouter_pinletrecaux_t~outer_p=function|Parsed.Atom(pos,s,sopt)->Atom(relpos~outer_p,s,sopt)|Parsed.List(start_pos,tocs,end_pos)->List(relstart_pos~outer_p,List.maptocs~f:(funtoc->aux_toc~outer_p:start_postoc),relend_pos~outer_p)andaux_toc~outer_p=function|Parsed.Sexpt->Sexp(aux_tt~outer_p)|Parsed.Commentc->Comment(aux_cc~outer_p)andaux_c~outer_p=function|Parsed.Plain_comment(pos,txt)->Plain_comment(relpos~outer_p,txt)|Parsed.Sexp_comment(pos,cs,t)->Sexp_comment(relpos~outer_p,List.mapcs~f:(func->aux_c~outer_pc),aux_tt~outer_p)infuntoc->aux_toctoc~outer_p:Src_pos.Absolute.origin;;