123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360openUtilsLibopenValueopenEnvironmentopenSvg_renderingmoduleCompl=CompletionmoduleAcgEnv=AcgData.Environment.EnvironmentmoduleAcgSig=AcgData.Signature.Data_SignaturemoduleAcgLex=AcgData.Acg_lexicon.Data_LexiconmoduleShowI=Show.Make(AcgData.Environment.Environment)(Show_text_dejavu)(Show_colors_solarized_dark)(Show_embellish_examples.Make(Show_text_dejavu))letrecresume_to_lazy_listlexstyresume=matchAcgLex.get_analysisresumelexwith|Some(t,w),new_resume->LazyList.Cons(RealTerm(s,t,ty,Somew),fun()->resume_to_lazy_listlexstynew_resume)|None,_->LazyList.Nilletfun_last_env=matchenv.last_valuewith|Somev->v|None->Errors.(ScriptErrors.emitScript_l.NoLastValue)letlast={name="last";help_text="This function returns the result of the last successful command. If there was no successful command in the current session, this function will throw an error.";args=[];f=Environment.Generation_ffun_last}letfun_limitargs_vl=letn=matchargswith[Environment.Int(n,_)]->n|_->assertfalseinletreclimittli=ifi=0thenLazyList.Nilelsematchtlwith|LazyList.Cons(v,tail)->LazyList.Cons(v,fun()->limit(tail())(i-1))|_->LazyList.Nilinlimitvlnletlimit={name="limit";help_text="This function truncate its input list to size [n], and outputs it with no other changes. If [n] is greater or equal to the size of its input list, it does nothing.";args=[("n",Environment.Int_s(Some1))];f=Environment.Computation_ffun_limit}letfun_loadargsenv=letpaths,loc=matchargswith|[Environment.StringList(paths,loc)]->paths,loc|_->assertfalseinList.fold_left(funenvpath->let(_,new_env)=Dump.load_env~with_magic:env.config.Config.with_magicpathenv.config.Config.dirsenv.acg_envlocin{envwithacg_env=new_env})envpathsletload={name="load";help_text="This function loads all files of the list [paths] in the environment. They can either be ACG data (usually [.acg] file) or compiled ACG data (usually [.acgo] file).";args=[("paths",Environment.StringList_s(None,Ci_Path))];f=Environment.Special_ffun_load}letfun_parseargsenvvl=letlex,ty,local_magic,alt_max=matchargswith|[Environment.Lex(lex,_);Environment.Type(ty,_);Environment.Bool(b,_);Environment.Int(alt_max,_)]->(lex,ty,b,alt_max)|_->assertfalseinletmagic=matchAcgLex.has_magiclex,local_magic,env.config.Config.with_magicwith|AcgLex.Available_wo_magic,true,false->let()=Logs.warn(funm->m"The@ lexicon@ %a@ was@ compiled@ by@ %a@ with@ Magic@ \
Set@ Rewriting@ disabled.@ Using@ Magic@ Set@ \
Rewritten@ program@ for@ parsing@ is@ therefore@ not@ \
available.@ Using@ standard@ parsing@ instead."Utils.lex_pp(fst(AcgLex.namelex))Utils.binary_pp"acgc")infalse|AcgLex.Available_wo_magic,true,true->let()=Logs.warn(funm->m"The@ lexicon@ %a@ was@ compiled@ by@ %a@ with@ Magic@ \
Set@ Rewriting@ disabled.@ Using@ Magic@ Set@ \
Rewritten@ program@ for@ parsing@ (default@ when@ \
running@ %a@ with@ the \"-m|--magic\"@ option) is@ \
therefore@ not@ available.@ Using@ standard@ parsing@ \
instead."Utils.lex_pp(fst(AcgLex.namelex))Utils.binary_pp"acgc"Utils.binary_pp"acg")infalse|AcgLex.Available_with_magic,false,true->let()=Logs.warn(funm->m"Using@ Magic@ Set@ Rewritten@ program@ for@ parsing@ \
is@ available@ for@ the@ lexicon@ %a@ but@ was@ disabled@ when@ \
calling@ the@ %a@ command.@ Using@ standard@ parsing@ \
instead."Utils.lex_pp(fst(AcgLex.namelex))Utils.fun_pp"parse")inlocal_magic|AcgLex.Available_with_magic,true,false->let()=Logs.warn(funm->m"Using@ Magic@ Set@ Rewritten@ program@ for@ parsing@ \
was@ not@ set@ by@ default@ on@ the@ %a@ command@ but@ \
is@ enabled@ for@ this@ %a@ command@ and@ available@ \
for@ the@ lexicon@ %a.@ Using@ magic@ set@ rewritten@ \
programs@ for@ parsing."Utils.binary_pp"acg"Utils.fun_pp"parse"Utils.lex_pp(fst(AcgLex.namelex)))inlocal_magic|_->local_magicinletfun_parse_auxvt=letabs,obj=AcgLex.get_siglexinlett,t_type=get_term_value_in_sigobjvtinletresume=AcgLex.parse~alt_max~magic(t,t_type)tylexinresume_to_lazy_listlexabstyresumeinmatchvlwith|LazyList.Cons(v,tl)->letres=fun_parse_auxvinLazyList.appendres(fun()->matchtl()with|LazyList.Cons_->(* Print warning *)LazyList.Nil|LazyList.Nil->LazyList.Nil)|LazyList.Nil->LazyList.Nilletparsemagic_def_val={name="parse";help_text="This function parses the first λ-term of its input list in the lexicon [lexicon], using type [type], and output the list of resulting λ-terms. The output list may be infinite or empty. Resulting λ-terms are presented according to increasing (depth, size) values (where depth represent the tree depth and size the overall number of nodes). In case of very ambiguous grammars, this can result in slow output. The optional [stack_limit] value sets the limit (10^stack_limit) beyond which sorting is not ensured, allowing for faster output.";args=[("lexicon",Environment.Lex_sNone);("type",Environment.Type_s(Arg_sig0,None));("magic",Environment.Bool_s(Somemagic_def_val));("stack_limit",Environment.Int_s(Some5))];f=Environment.Computation_ffun_parse}letfun_realizeargsenvvl=letlexlist,graph_file=matchargswith[Environment.LexList(lexlist,_);Environment.String(graph,_)]->lexlist,graph|_->assertfalseinletfun_realize_auxvti=letabs=matchlexlistwith|lex::_->fst(AcgLex.get_siglex)|_->assertfalseinlett,ty=get_term_value_in_sigabsvtinletfun_realize_aux2lex=letobj=snd(AcgLex.get_siglex)inletret_t,ret_ty=AcgLex.interpretttylexinRealTerm(obj,ret_t,ret_ty,None)inlet()=ifgraph_file<>""thenletd=ShowI.realize_diagramtlexlistenv.config.Config.rendering_configinletfile_name=matchiwith|-1->graph_file|i->Printf.sprintf"%s%i%s"(Filename.remove_extensiongraph_file)(i+1)(Filename.extensiongraph_file)inDiagram.to_svgfile_namedinLazyList.from_list(List.mapfun_realize_aux2lexlist)inmatchvlwith|LazyList.Cons(t,ll)->letres=match(ll())with|LazyList.Cons_->LazyList.join(LazyList.mapifun_realize_auxvl)|_->fun_realize_auxt(-1)inres|nil->nilletrealize={name="realize";help_text="This function realizes all the λ-terms of its input list all lexicons in the list [lexicons], and output the list of resulting λ-terms. If [svg] is not the empty string, it also saves a graph of the realizations in the file [svg].";args=[("lexicons",Environment.LexList_sNone);("svg",Environment.String_s(Some"",Ci_Path))];f=Environment.Computation_ffun_realize}letfun_checkargs_vl=letsigg=matchargswith[Environment.Sig(sigg,_)]->sigg|_->assertfalseinletfun_check_auxvt=lett,ty=get_term_value_in_sigsiggvtinRealTerm(sigg,t,ty,None)inLazyList.mapfun_check_auxvlletcheck={name="check";help_text="This function typechecks all the λ-terms of its input list in the signature [signature], and outputs them unchanged. So this function will do nothing if all the terms are correct, but will throw an error otherwise. Only terms typed by hand (using the term literal syntax) may be incorrect.";args=[("signature",Environment.Sig_sNone)];f=Environment.Computation_ffun_check}letfun_list_termsargs_=letsigg,ty,min_depth,max_depth,random=matchargswith[Environment.Sig(sigg,_);Environment.Type(ty,_);Environment.Int(min_depth,_);Environment.Int(max_depth,_);Environment.Bool(random,_)]->sigg,ty,min_depth,max_depth,random|_->assertfalseinletresult_list=AcgSig.gen_term_listsiggtymin_depthmax_depthrandomin(LazyList.map(funt->RealTerm(sigg,t,ty,None))result_list)letlist_terms={name="list-terms";help_text="This function computes all possible λ-terms of type [type] in the signature [signature], with a depth between [min_depth] and [max_depth], and outputs a list with all of these terms. This function is deterministic when [random] is false, otherwise the order of the generated terms will be random.";args=[("signature",Environment.Sig_sNone);("type",Environment.Type_s(Arg_sig0,None));("min_depth",Environment.Int_s(Some0));("max_depth",Environment.Int_s(Some10));("random",Environment.Bool_s(Somefalse))];f=Environment.Generation_ffun_list_terms}letfun_composeargsenv=letlex1,lex2,name=matchargswith[Environment.Lex(lex1,_);Environment.Lex(lex2,_);Environment.String(name,_)]->lex1,lex2,name|_->assertfalseinletnew_env={envwithacg_env=AcgEnv.insert~overwrite:true(AcgEnv.Lexicon(AcgLex.composelex1lex2(name,(Lexing.dummy_pos,Lexing.dummy_pos))))~to_be_dumped:trueenv.acg_env}innew_envletcompose={name="compose";help_text="This function creates a new lexicon named [name] by composing [lexicon1] with [lexicon2] and adds it to the current environment.";args=[("lexicon1",Environment.Lex_sNone);("lexicon2",Environment.Lex_sNone);("name",Environment.String_s(None,Ci_None))];f=Environment.Special_ffun_compose}letfun_idbargsenv=letlex=matchargswith[Environment.Lex(lex,_)]->lex|_->assertfalseinlet()=matchAcgLex.get_programlexwith|Someprog->Logs.app(funm->m"The datalog program (intensional database) corresponding to the \
lexicon \"%s\" is:@,\
@[<v> %a@]"(fst(AcgLex.namelex))(DatalogLib.Datalog_AbstractSyntax.AbstractSyntax.Program.pp~with_position:false~with_id:false)(DatalogLib__Datalog.Datalog.Program.to_abstractprog))|None->Logs.app(funm->m"Lexicon \"%s\" is not 2nd-order, hence it is not associated \
with an intensional database."(fst(AcgLex.namelex)))inenvletidb={name="idb";help_text="This function prints the datalog program correspoding to the lexicon [lexicon].";args=[("lexicon",Environment.Lex_sNone)];f=Environment.Special_ffun_idb}letfun_queryargs_vl=letlex,ty=matchargswith[Environment.Lex(lex,_);Environment.Type(ty,_)]->lex,ty|_->assertfalseinletfun_query_auxv=let_,obj=AcgLex.get_siglexinlett,_=get_term_value_in_sigobjvinLogs.app(funm->m"%a"(AcgLex.pp_querylex)(t,ty))inLazyList.iterfun_query_auxvlletquery={name="query";help_text="This function outputs the facts (extensional database) and the query associated to its input term list of distinguished type [type] with respect to the lexicon [lexicon].";args=[("lexicon",Environment.Lex_sNone);("type",Environment.Type_s(Environment.Arg_sig0,None))];f=Environment.Consumption_ffun_query}letfun_list_argsenv=let()=Environment.short_printenvinenvletlist_={name="list";help_text="This function lists the signatures and lexicons in the current environment. This function can only be used alone in a command.";args=[];f=Environment.Special_ffun_list}letfun_printargsenv=lete=matchargswith[Environment.Entry(e,_)]->e|_->assertfalseinlet()=matchewith|AcgEnv.Lexiconl->Logs.app(funm->m"%a"AcgLex.ppl)|AcgEnv.Signatures->Logs.app(funm->m"%a"AcgSig.pps)inenvletprint={name="print";help_text="This function prints the entry [entry].";args=[("entry",Environment.Entry_sNone)];f=Environment.Special_ffun_print}letfun_helpargsenv=letf=matchargswith[Environment.String(f,_)]->f|_->assertfalseinlet()=Environment.print_helpenvfinenvlethelp={name="help";help_text="Prints this help message: lists the functions in the current environment and their description. If parameter [fun] is not empty, lists all functions which name starts with its value.";args=[("fun",Environment.String_s(Some"",Ci_Fun))];f=Environment.Special_ffun_help}letdef_fun_listconfig_o=letparse_magic_def_val=matchconfig_owith|Someconfig->config.Config.with_magic|None->falsein[last;limit;load;parseparse_magic_def_val;realize;check;list_terms;compose;idb;query;list_;print;help]