12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364(* SPDX-License-Identifier: MIT *)(* Copyright (C) 2023-2024 formalsec *)(* Written by the Smtml programmers *)exceptionSyntax_errorofstringmoduleSmtml=structopenLexeropenLexingletpp_posfmtlexbuf=letpos=lexbuf.lex_curr_pinFmt.pffmt"%s:%d:%d"pos.pos_fnamepos.pos_lnum(pos.pos_cnum-pos.pos_bol+1)letparse_with_errorlexbuf=tryParser.scriptLexer.tokenlexbufwith|SyntaxErrormsg->raise(Syntax_error(Fmt.str"%a: %s"pp_poslexbufmsg))|Parser.Error->raise(Syntax_error(Fmt.str"%a: syntax error"pp_poslexbuf))letfrom_filefilename=letres=Bos.OS.File.with_icfilename(funchan()->letlexbuf=Lexing.from_channelchaninlexbuf.lex_curr_p<-{lexbuf.lex_curr_pwithpos_fname=Fpath.to_stringfilename};parse_with_errorlexbuf)()inmatchreswithError(`Msge)->Fmt.failwith"%s"e|Okv->vletfrom_stringcontents=parse_with_error(Lexing.from_stringcontents)endmoduleSmtlib=structletfrom_filefilename=trylet_,st=Smtlib.parse_all(`File(Fpath.to_stringfilename))inLazy.forcestwith|Dolmen.Std.Loc.Syntax_error(loc,`Regularmsg)->raise(Syntax_error(Fmt.str"%a: syntax error: %t"Dolmen.Std.Loc.print_compactlocmsg))|Dolmen.Std.Loc.Syntax_error(loc,`Advanced(x,_,_,_))->raise(Syntax_error(Fmt.str"%a: syntax error: %s"Dolmen.Std.Loc.print_compactlocx))endletfrom_filefilename=matchFpath.split_extfilenamewith|_,".smtml"->Smtml.from_filefilename|_,".smt2"->Smtlib.from_filefilename|fname,ext->((* FIXME: I don't like this *)matchFpath.to_stringfnamewith|"-"->Smtml.from_filefilename|_->Fmt.failwith"Unsupported script type with extension '%s'"ext)