12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455openParser.MenhirInterpreteropenCoremoduleS=MenhirLib.Generaltypeerror_or_template=ErrorofSedlexing.lexbuf|TemplateofTemplate.tletpp_posout(pos_start,pos_end)=Ppxlib.(Format.fprintfout"from line %d:%d to line %d:%d in file %s"pos_start.pos_lnum(pos_start.pos_cnum-pos_start.pos_bol)pos_end.pos_lnum(pos_end.pos_cnum-pos_end.pos_bol)pos_start.pos_fname)lethandle_syntax_errorlexbuf=letmessage="Syntax error"inFormat.fprintfFormat.err_formatter"%s %a\n%!"messagepp_pos(Sedlexing.lexing_positionslexbuf)letrecloopnext_tokenlexbuf(checkpoint:Template.tcheckpoint)=matchcheckpointwith|InputNeeded_env->lettoken=next_token()inletcheckpoint=offercheckpointtokeninloopnext_tokenlexbufcheckpoint|Shifting_|AboutToReduce_->letcheckpoint=resumecheckpointinloopnext_tokenlexbufcheckpoint|HandlingError_->Errorlexbuf|Acceptedtemplate->Templatetemplate|Rejected->(* Cannot happen as we stop at syntax error immediatly *)assertfalseletof_lexing_bufferlexbuf=letlexer=Lexer.lexerlexbufinlooplexerlexbuf(Parser.Incremental.template(fst@@Sedlexing.lexing_positionslexbuf))letof_ustring?(filename="")ustring=of_lexing_buffer(letbuffer=Sedlexing.from_uchar_arrayustringinSedlexing.set_filenamebufferfilename;buffer)letof_string?(filename="")string=of_ustring~filename(Ustring.of_stringstring)letof_filenamefilename=letgen=Gen.of_array(Ustring.of_string@@In_channel.read_allfilename)inletbuffer=Sedlexing.from_gengeninSedlexing.set_filenamebufferfilename;of_lexing_bufferbuffer