123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145(* elpi: embedded lambda prolog interpreter *)(* license: GNU Lesser General Public License Version 2.1 or later *)(* ------------------------------------------------------------------------- *)openElpi_utilopenElpi_lexer_configexceptionParseError=Parser_config.ParseErrormoduletypeParser=sigvalprogram:file:string->Ast.Program.decllistvalgoal:loc:Util.Loc.t->text:string->Ast.Goal.tvalgoal_from:loc:Util.Loc.t->Lexing.lexbuf->Ast.Goal.tvalprogram_from:loc:Util.Loc.t->Lexing.lexbuf->Ast.Program.tendmoduletypeParser_w_Internals=sigincludeParsermoduleInternal:sigvalinfix_SYMB:(Lexing.lexbuf->Tokens.token)->Lexing.lexbuf->Ast.Func.tvalprefix_SYMB:(Lexing.lexbuf->Tokens.token)->Lexing.lexbuf->Ast.Func.tvalpostfix_SYMB:(Lexing.lexbuf->Tokens.token)->Lexing.lexbuf->Ast.Func.tendendmoduletypeConfig=sigvalversions:(int*int*int)Util.StrMap.tvalresolver:?cwd:string->unit:string->unit->stringendmoduleMake(C:Config)=structletparse_ref:(?cwd:string->string->Ast.Program.parser_outputlist)ref=ref(fun?cwd:__->assertfalse)moduleParseFile=structletparse_file?cwdfile=!parse_ref?cwdfileletclient_payload:Obj.toptionref=refNoneletset_current_clent_loc_pyloadx=client_payload:=Somexletget_current_client_loc_payload()=!client_payloadendmoduleGrammar=Grammar.Make(ParseFile)letmessage_of_states=tryError_messages.messageswithNot_found->"syntax error"letparsegrammarlexbuf=letbuffer,lexer=MenhirLib.ErrorReports.wrapLexer.(tokenC.versions)intrygrammarlexerlexbufwith|Ast.Term.NotInProlog(loc,message)->raise(Parser_config.ParseError(loc,message^"\n"))|Lexer.Error(loc,message)->letloc={Util.Loc.client_payload=None;source_name=loc.Lexing.pos_fname;line=loc.Lexing.pos_lnum;line_starts_at=loc.Lexing.pos_bol;source_start=loc.Lexing.pos_cnum;source_stop=loc.Lexing.pos_cnum;}inraise(Parser_config.ParseError(loc,message))|Grammar.Errorstateid->letmessage=message_of_statestateidinletloc=lexbuf.Lexing.lex_curr_pinletloc={Util.Loc.client_payload=None;source_name=loc.Lexing.pos_fname;line=loc.Lexing.pos_lnum;line_starts_at=loc.Lexing.pos_bol;source_start=loc.Lexing.pos_cnum;source_stop=loc.Lexing.pos_cnum;}inraise(Parser_config.ParseError(loc,message))letalready_parsed=Hashtbl.create11letcleanup_fnamefilename=Re.Str.replace_first(Re.Str.regexp"/_build/[^/]+")""filenamelet()=parse_ref:=(fun?cwdfilename->letfilename=C.resolver?cwd~unit:filename()inletdigest=Digest.filefilenameinletto_parse=ifFilename.extensionfilename=".mod"thenletsigf=Filename.chop_extensionfilename^".sig"inifSys.file_existssigfthen[sigf,Digest.filesigf;filename,digest]else[filename,digest]else[filename,digest]into_parse|>List.map(fun(filename,digest)->ifHashtbl.memalready_parseddigestthen{Ast.Program.file_name=filename;digest;ast=[]}elseletic=open_infilenameinletlexbuf=Lexing.from_channelicinletdest=cleanup_fnamefilenameinlexbuf.Lexing.lex_curr_p<-{lexbuf.lex_curr_pwithpos_fname=dest};Hashtbl.addalready_parseddigesttrue;letast=parseGrammar.programlexbufinclose_inic;{file_name=filename;digest;ast}))letto_lexing_loc{Util.Loc.source_name;line;line_starts_at;source_start;_}={Lexing.pos_fname=source_name;pos_lnum=line;pos_bol=line_starts_at;pos_cnum=source_start;}letlexing_set_positionlexbufloc=Option.iterParseFile.set_current_clent_loc_pyloadloc.Util.Loc.client_payload;letloc=to_lexing_loclocinletopenLexinginlexbuf.lex_abs_pos<-loc.pos_cnum;lexbuf.lex_start_p<-loc;lexbuf.lex_curr_p<-locletgoal_from~loclexbuf=lexing_set_positionlexbufloc;parseGrammar.goallexbufletgoal~loc~text=letlexbuf=Lexing.from_stringtextingoal_from~loclexbufletprogram_from~loclexbuf=Hashtbl.clearalready_parsed;lexing_set_positionlexbufloc;parseGrammar.programlexbufletprogram~file=Hashtbl.clearalready_parsed;List.(concat(map(fun{Ast.Program.ast=x}->x)@@!parse_reffile))moduleInternal=structletinfix_SYMB=Grammar.infix_SYMBletprefix_SYMB=Grammar.prefix_SYMBletpostfix_SYMB=Grammar.postfix_SYMBendend