123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149(*********************************************************************************)(* Higlo *)(* *)(* Copyright (C) 2014-2021 Institut National de Recherche en Informatique *)(* et en Automatique. All rights reserved. *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU Lesser General Public License version *)(* 3 as published by the Free Software Foundation. *)(* *)(* 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 Library General Public License for more details. *)(* *)(* You should have received a copy of the GNU Lesser 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 *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(* *)(*********************************************************************************)(** *)openLangtypeclasses={bcomment:string;constant:string;directive:string;escape:string;id:string;keyword:int->string;lcomment:string;numeric:string;string:string;symbol:int->string;text:string;title:int->string;}letdefault_classes={bcomment="comment";constant="constant";directive="directive";escape="escape";id="id";keyword=(function0->"kw"|n->Printf.sprintf"kw%d"n);lcomment="comment";numeric="numeric";string="string";symbol=(function0->"sym"|n->Printf.sprintf"sym%d"n);text="text";title=(function0->"title"|n->Printf.sprintf"title%d"n);};;lettoken_tonode=fun?(classes=default_classes)->function|Bcomment(s,_)->nodeclasses.bcomments|Constant(s,_)->nodeclasses.constants|Directive(s,_)->nodeclasses.directives|Escape(s,_)->nodeclasses.escapes|Id(s,_)->nodeclasses.ids|Keyword(n,(s,_))->node(classes.keywordn)s|Lcomment(s,_)->nodeclasses.lcomments|Numeric(s,_)->nodeclasses.numerics|String(s,_)->nodeclasses.strings|Symbol(n,(s,_))->node(classes.symboln)s|Text(s,_)->nodeclasses.texts|Title(n,(s,_))->node(classes.titlen)slettoken_to_xml=letmoduleX=Xtmpl.Xmlinletnodeclcdata=letatts=X.atts_one("","class")(cl,None)inX.node("","span")~atts[X.cdatacdata]intoken_tonode;;lettoken_to_xml_rewrite=letmoduleX=Xtmpl.Rewriteinletnodeclcdata=letatts=X.atts_one("","class")[X.cdatacl]inX.node("","span")~atts[X.cdatacdata]intoken_tonode;;letto_xml?classes~langs=List.map(token_to_xml?classes)(parse~langs);;letto_xml_rewrite?classes~langs=List.map(token_to_xml_rewrite?classes)(parse~langs);;typeprinter=Lang.tokenlist->unitmoduleSMap=Map.Make(String);;letprinters=refSMap.empty;;letget_printername=trySMap.findname!printerswithNot_found->failwith(Printf.sprintf"Unknown printer %S"name);;letregister_printernamef=printers:=SMap.addnamef!printers;;letxml_printertokens=letxmls=List.maptoken_to_xmltokensinprint_string(Xtmpl.Xml.to_stringxmls);;lethtml_printertokens=print_string"<html>
<head>
<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"/>
<link href=\"style.css\" rel=\"stylesheet\" type=\"text/css\"/>
</head>
<body><pre>";xml_printertokens;print_string"</pre></body></html>";;lettoken_printer?(with_len=false)tokens=letf=ifwith_lenthenLang.string_of_token_with_lengthelseLang.string_of_tokeninList.iter(funt->print_string(ft))tokens;;let()=List.iter(fun(name,f)->register_printernamef)["xml",xml_printer;"html",html_printer;"tokens",token_printer~with_len:false;"tokens-length",token_printer~with_len:true;];;