Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file texttag.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333(*********************************************************************************)(* OCaml-Stk *)(* *)(* Copyright (C) 2023-2024 INRIA All rights reserved. *)(* Author: Maxence Guesdon, INRIA Saclay *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU General Public License as *)(* published by the Free Software Foundation, version 3 of the License. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public *)(* License along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* As a special exception, you have permission to link this program *)(* with the OCaml compiler and distribute executables, as long as you *)(* follow the requirements of the GNU GPL in regard to all of the *)(* software in the executable aside from the OCaml compiler. *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)moduleT=structmoduleId=Misc.Id()typet=Id.ttypetag={id:Id.t;name:string;}lettags=ref[||]lettags_by_name=refSmap.emptyletcreatename=matchSmap.find_optname!tags_by_namewith|None->lett={name;id=Id.gen()}inletid_n=Id.to_intt.idin(matchid_nwith|0->(* first id *)tags:=Array.make1t;|nwhenn>0->lettags2=Array.make(id_n+1)tinArray.blit!tags0tags20(Array.length!tags);tags:=tags2|_->assertfalse);tags_by_name:=Smap.addt.namet!tags_by_name;t.id|Somet->Log.warn(funm->m"Tag %S already exists"t.name);t.idletcompare=Id.compareletequalt1t2=comparet1t2=0letgetid=letid_n=Id.to_intidintrySome(Array.get!tagsid_n)with_->Log.err(funm->m"Invalid tag id %a"Id.ppid);Noneletnameid=matchgetidwith|None->""|Somet->t.nameletppppfid=matchgetidwith|None->()|Somet->Format.fprintfppf"{id=%a; name=%S}"Id.ppt.idt.namelettablename=lett=refMisc.IMap.emptyinletgetn=matchMisc.IMap.find_optn!twith|None->lettag=create(Printf.sprintf"%s%d"namen)int:=Misc.IMap.addntag!t;tag|Sometag->taginletelements()=Misc.IMap.bindings!tin(get,elements)letget_or_createstr=matchSmap.find_optstr!tags_by_namewith|None->createstr|Somet->t.idlettags()=List.map(funt->t.id)(Array.to_list!tags)endtypetag=T.tmoduleTMap=Map.Make(T)moduleTSet=Misc.Idset(T.Id)(*module Mem = Misc.Memoizer(struct
type t = TSet.t
let compare = TSet.compare
let dup x = x
end)
*)letpp_listppfl=List.iter(funt->Format.fprintfppf"%a\n"T.ppt)lletpp_setppfset=pp_listppf(TSet.to_listset)lettag_debug=T.create"debug"lettag_info=T.create"info"lettag_warning=T.create"warning"lettag_error=T.create"error"lettag_app=T.create"app"letlog_tags=[tag_debug;tag_info;tag_warning;tag_error;tag_app]moduleLang=structletbcomment=T.create"bcomment"letconstant=T.create"constant"letdirective=T.create"directive"letescape=T.create"escape"letid=T.create"id"letkeyword=T.table"keyword"letkeyword0=fstkeyword0letkeyword1=fstkeyword1letkeyword2=fstkeyword2letkeyword3=fstkeyword3letkeyword4=fstkeyword4letlcomment=T.create"lcomment"letnumeric=T.create"numeric"letstring=T.create"string"letsymbol=T.table"symbol"letsymbol0=fstsymbol0letsymbol1=fstsymbol1lettitle=T.table"title"lettitle0=fsttitle0lettitle1=fsttitle1lettitle2=fsttitle2lettitle3=fsttitle3lettitle4=fsttitle4lettitle5=fsttitle5lettitle6=fsttitle6lettag_of_token=function|Higlo.Lang.Bcomment(_,size)->Somebcomment,size|Constant(_,size)->Someconstant,size|Directive(_,size)->Somedirective,size|Escape(_,size)->Someescape,size|Id(_,size)->Someid,size|Keyword(n,(_,size))->Some(fstkeywordn),size|Lcomment(_,size)->Somelcomment,size|Numeric(_,size)->Somenumeric,size|String(_,size)->Somestring,size|Symbol(n,(_,size))->Some(fstsymboln),size|Text(_,size)->None,size|Title(n,(_,size))->Some(fsttitlen),sizelettags=[bcomment;constant;directive;escape;id;keyword0;keyword1;keyword2;keyword3;keyword4;lcomment;numeric;string;symbol0;symbol1;title0;title1;title2;title3;title4;title5;title6]endmoduleTheme=structmoduleId=Misc.Id()typet={id:Id.t;mutabletags:Props.tTMap.t}letequalt1t2=Id.equalt1.idt2.idlettags_props_differt1t2=TMap.compareProps.comparet1.tagst2.tags<>0letppppft=Format.fprintfppf"@[Tagtheme %a {@."Id.ppt.id;Format.pp_open_boxppf2;TMap.iter(funtprops->Format.fprintfppf"%a -> %a@."T.pptProps.ppprops)t.tags;Format.pp_close_boxppf();Format.fprintfppf"@]}"letset_tagttagprops=t.tags<-TMap.addtagpropst.tagsletopt_propsttag=TMap.find_opttagt.tagslettag_propsttag=matchopt_propsttagwith|None->letp=Props.empty()inset_tagttagp;p|Somep->pletset_tag_propt(tag:T.t)pv=letprops=matchopt_propsttagwith|None->letp=Props.empty()int.tags<-TMap.addtagpt.tags;p|Somep->pinProps.setpropspvletmerge_tag_props=letfttagacc=matchopt_propsttagwith|None->acc|Somep->Props.mergeaccpinfunttagsprops->List.fold_right(ft)(TSet.to_listtags)propsletmerge_tags=letmergekv1v2=matchv1,v2with|None,_->v2|Some_,None->v1|_,Some_->v2infuntags1tags2->TMap.mergemergetags1tags2letcreate?(tags=TMap.empty)()={id=Id.gen();tags}lettags_propst=List.fold_left(funacctag->letp=tag_propsttagin(tag,p)::acc)[](T.tags())(*
let p = Props.empty () in
let tags = TMap.empty in
(* set general theme properties *)
Props.set_from_json ~vars:Theme.(variables (snd (current_theme()))) p json;
let p, tags =
match json with
| `Assoc l ->
(match List.assoc_opt "inherits" l with
| None -> (p, tags)
| Some (`String s) -> apply_inherits (p, tags) s
| Some (`List l) ->
List.fold_left (fun (p, tags) -> function
| `String s -> apply_inherits (p, tags) s
| json -> invalid_json json "string"; (p, tags))
(p, tags) l
| Some json -> invalid_json json "string or string list"; (p, tags)
)
| _ -> (p, tags)
in
let t = get_or_create ~tags ~props:p name in
( (* set tag properties *)
match json with
| `Assoc l ->
(match List.assoc_opt "tags" l with
| None -> ()
| Some (`Assoc l) ->
List.iter
(fun (tag_name, json) ->
let tag = T.get_or_create tag_name in
let p = tag_props t tag in
Props.set_from_json
~vars:Theme.(variables (snd (current_theme()))) p json
)
l
| Some json ->
invalid_json json "object";
()
)
| _ -> ()
);
t
let to_json t =
let tags = TMap.fold
(fun tag props acc ->
(T.name tag, Props.to_json props) :: acc)
t.tags []
in
match Props.to_json t.props with
| `Assoc l -> `Assoc (("tags", `Assoc tags) :: l)
| _ -> Log.err (fun m -> m "invalid json for props"); assert false
let themes_of_json = function
| `Assoc l ->
List.map
(fun (name, json) -> from_json name json)
l
| json -> Ocf.invalid_value json
let default = get_or_create "default"
*)letinit()=()letprop=Props.string_prop~after:[Resize]~default:"default"~inherited:true"tagtheme"letcss_prop=Theme.string_proppropend(*
| Bcomment (_,size) -> Printf.sprintf "Bcomment(%S)" s
| Constant (_,size) -> Printf.sprintf "Constant(%S)" s
| Directive (_,size) -> Printf.sprintf "Directive(%S)" s
| Escape (_,size) -> Printf.sprintf "Escape(%S)" s
| Id (_,size) -> Printf.sprintf "Id(%S)" s
| Keyword (n, (s, _)) -> Printf.sprintf "Keyword(%d, %S)" n s
| Lcomment (_,size) -> Printf.sprintf "Lcomment(%S)" s
| Numeric (_,size) -> Printf.sprintf "Numeric(%S)" s
| String (_,size) -> Printf.sprintf "String(%S)" s
| Symbol (n, (s, _)) -> Printf.sprintf "Symbol(%d, %S)" n s
| Text (_,size) -> Printf.sprintf "Text(%S)" s
*)