123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144(*********************************************************************************)(* 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 *)(* *)(* *)(*********************************************************************************)openLangletlexemelb=Sedlexing.(Utf8.lexemelb,lexeme_lengthlb);;letsedlexeme=Sedlexing.Utf8.lexeme;;letdigit=[%sedlex.regexp?'0'..'9'|'_']lethex=[%sedlex.regexp?digit|'A'..'F'|'a'..'f']letinteger=[%sedlex.regexp?Plus(digit)]letdecimal=[%sedlex.regexp?Star('0'..'9'),'.',Plus('0'..'9')]letlf=[%sedlex.regexp?0x000A]letcr=[%sedlex.regexp?0x000D]letline_ending=[%sedlex.regexp?lf|(cr,Opt(lf))]letspace=[%sedlex.regexp?' ']lettab=[%sedlex.regexp?'\t']letspace_or_tab=[%sedlex.regexp?space|tab]letstar3_space=[%sedlex.regexp?Opt(space_or_tab),Opt(space_or_tab),Opt(space_or_tab)]letthematic_break=[%sedlex.regexp?star3_space,((('_',Star(space_or_tab)),('_',Star(space_or_tab)),('_',Star(space_or_tab)),Star('_',Star(space_or_tab)))|(('-',Star(space_or_tab)),('-',Star(space_or_tab)),('-',Star(space_or_tab)),Star('-',Star(space_or_tab)))|(('*',Star(space_or_tab)),('*',Star(space_or_tab)),('*',Star(space_or_tab)),Star('*',Star(space_or_tab)))),line_ending]lettitle=[%sedlex.regexp?star3_space,'#',Opt('#'),Opt('#'),Opt('#'),Opt('#'),Opt('#'),Plus(space_or_tab),Star(Compl(lf|cr|'#')),Opt(Plus(space_or_tab),Plus('#')),Opt(cr),lf]letno_lf_cr=[%sedlex.regexp?0x0000..0x0009|0x000B|0x000C|0x000E..0xffff]letsetext_begin=[%sedlex.regexp?Compl(lf|cr|'>'|'+'|'-'|space_or_tab)]letsetext_content=[%sedlex.regexp?Star(setext_begin|space_or_tab)]letsetext1=[%sedlex.regexp?star3_space,setext_begin,setext_content,line_ending,star3_space,Plus('='),Star(space_or_tab),line_ending]letsetext2=[%sedlex.regexp?star3_space,setext_begin,setext_content,line_ending,star3_space,Plus('-'),Star(space_or_tab),line_ending]letindent=[%sedlex.regexp?space_or_tab,space_or_tab,space_or_tab,Plus(space_or_tab)]letblank_line=[%sedlex.regexp?Star(space_or_tab),line_ending]letcode_line=[%sedlex.regexp?indent,Plus(no_lf_cr),line_ending]letcode_block=[%sedlex.regexp?Opt(blank_line),Plus(code_line),Opt(blank_line)]letlink_id=[%sedlex.regexp?'[',Plus(Compl(lf|cr|']')|"\\]"),']']letlink_url=[%sedlex.regexp?'(',Plus(Compl(lf|cr|')')|"\\)"),')']letstrong=[%sedlex.regexp?("**",Plus(Compl('*')),"**")|("__",Plus(Compl('_')),"__")]letemph=[%sedlex.regexp?('*',Plus(Compl('*')),'*')|('_',Plus(Compl('_')),'_')]letstrikethrough=[%sedlex.regexp?("~~",Plus(Compl('~')),"~~")]letrecfence_code_blocklexbufopeningblen=match%sedlexlexbufwith|line_ending,star3_space,(("``",Plus('`'))|("~~",Plus('~')))->letstr,n=lexemelexbufinletlen=len+ninBuffer.add_stringbstr;ifMisc.is_prefix~of_:opening(Misc.strip_stringstr)then[Symbol(1,(Buffer.contentsb,len))]elsefence_code_blocklexbufopeningblen|eof->[Symbol(1,(Buffer.contentsb,len))]|any->let(str,n)=lexemelexbufinBuffer.add_stringbstr;fence_code_blocklexbufopeningb(len+n)|_->failwith"Invalid state"andmainlexbuf=match%sedlexlexbufwith|eof->[]|thematic_break->[Symbol(4,lexemelexbuf)]|title->let(str,len)=lexemelexbufinletlevel=matchMisc.split_stringstr[' ';'\t']with|sharps::_->String.lengthsharps|[]->0in[Title(level,(str,len))]|setext1->[Title(1,lexemelexbuf)]|setext2->[Title(2,lexemelexbuf)]|code_block->[Symbol(1,lexemelexbuf)]|star3_space,(("``",Plus('`'))|("~~",Plus('~')))->let(opening,len)=lexemelexbufinletb=Buffer.create256inBuffer.add_stringbopening;fence_code_blocklexbufopeningblen|link_id->(letlink_id=lexemelexbufinmatch%sedlexlexbufwith|link_url->[Idlink_id;Constant(lexemelexbuf)]|_->Sedlexing.rollbacklexbuf;[Idlink_id])|strong->[Symbol(5,lexemelexbuf)]|emph->[Symbol(6,lexemelexbuf)]|strikethrough->[Lcomment(lexemelexbuf)]|any->[Text(lexemelexbuf)]|_->failwith"Invalid state"let()=Lang.register_lang"commonmark"main;;