123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)openStmmoduleUtil:sigvalsimple_goal:Evd.evar_map->Evar.t->Evar.tlist->boolvalis_focused_goal_simple:doc:Stm.doc->Stateid.t->[`SimpleofEvar.tlist|`Not]type'auntil=[`Stop|`Foundofstatic_block_declaration|`Contof'a]valcrawl:document_view->?init:document_nodeoption->('a->document_node->'auntil)->'a->static_block_declarationoptionvalunit_val:Stm.DynBlockData.tvalof_bullet_val:Proof_bullet.t->Stm.DynBlockData.tvalto_bullet_val:Stm.DynBlockData.t->Proof_bullet.tvalof_vernac_control_val:Vernacexpr.vernac_control->Stm.DynBlockData.tvalto_vernac_control_val:Stm.DynBlockData.t->Vernacexpr.vernac_controlend=structletunit_tag=DynBlockData.create"unit"letunit_val=DynBlockData.Easy.inj()unit_tagletof_bullet_val,to_bullet_val=DynBlockData.Easy.make_dyn"bullet"letof_vernac_control_val,to_vernac_control_val=DynBlockData.Easy.make_dyn"vernac_control"letsimple_goalsigmaggs=letopenEvarinletopenEvdinletopenEvarutilinlet()=assert(not@@Evd.is_definedsigmag)inletevi=Evd.find_undefinedsigmaginSet.is_empty(evars_of_termsigma(Evd.evar_conclevi))&&Set.is_empty(evars_of_filtered_evar_infosigma(nf_evar_infosigmaevi))&¬(List.exists(Proofview.depends_onsigmag)gs)letis_focused_goal_simple~docid=matchstate_of_id~docidwith|Expired|Error_|ValidNone->`Not|Valid(Some{interp={Vernacstate.Interp.lemmas}})->Option.cata(Vernacstate.LemmaStack.with_top~f:(funproof->letproof=Declare.Proof.getproofinletProof.{goals=focused;stack=r1;sigma}=Proof.dataproofinletrest=List.(flatten(map(fun(x,y)->x@y)r1))@(Evd.shelfsigma)@(Evar.Set.elements@@Evd.given_upsigma)inifList.for_all(funx->simple_goalsigmaxrest)focusedthen`Simplefocusedelse`Not))`Notlemmastype'auntil=[`Stop|`Foundofstatic_block_declaration|`Contof'a]letcrawl{entry_point;prev_node}?(init=Someentry_point)facc=letreccrawlnodeacc=matchnodewith|None->None|Somenode->matchfaccnodewith|`Stop->None|`Foundx->Somex|`Contacc->crawl(prev_nodenode)accincrawlinitaccendincludeUtil(* ****************** - foo - bar - baz *********************************** *)letstatic_bullet({entry_point;prev_node}asview)=letopenVernacexprinassert(not(Vernacprop.has_query_controlentry_point.ast));matchentry_point.ast.CAst.v.exprwith|VernacSynPure(VernacBulletb)->letbase=entry_point.indentationinletlast_tac=prev_nodeentry_pointincrawlview~init:last_tac(funprevnode->ifnode.indentation<basethen`Stopelseifnode.indentation>basethen`ContnodeelseifVernacprop.has_query_controlnode.astthen`Stopelsematchnode.ast.CAst.v.exprwith|VernacSynPure(VernacBulletb')whenb=b'->`Found{block_stop=entry_point.id;block_start=prev.id;dynamic_switch=node.id;carry_on_data=of_bullet_valb}|_->`Stop)entry_point|_->assertfalseletdynamic_bulletdoc{dynamic_switch=id;carry_on_data=b}=matchis_focused_goal_simple~docidwith|`Simplefocused->ValidBlock{base_state=id;goals_to_admit=focused;recovery_command=Some(CAst.makeVernacexpr.{control=[];attrs=[];expr=VernacSynPure(VernacBullet(to_bullet_valb))})}|`Not->Leakslet()=register_proof_block_delimiter"bullet"static_bulletdynamic_bullet(* ******************** { block } ***************************************** *)letstatic_curly_brace({entry_point;prev_node}asview)=letopenVernacexprinassert(entry_point.ast.CAst.v.expr=VernacSynPureVernacEndSubproof);crawlview(fun(nesting,prev)node->ifVernacprop.has_query_controlnode.astthen`Cont(nesting,node)elsematchnode.ast.CAst.v.exprwith|VernacSynPure(VernacSubproof_)whennesting=0->`Found{block_stop=entry_point.id;block_start=prev.id;dynamic_switch=node.id;carry_on_data=unit_val}|VernacSynPure(VernacSubproof_)->`Cont(nesting-1,node)|VernacSynPureVernacEndSubproof->`Cont(nesting+1,node)|_->`Cont(nesting,node))(-1,entry_point)letdynamic_curly_bracedoc{dynamic_switch=id}=matchis_focused_goal_simple~docidwith|`Simplefocused->ValidBlock{base_state=id;goals_to_admit=focused;recovery_command=Some(CAst.makeVernacexpr.{control=[];attrs=[];expr=VernacSynPureVernacEndSubproof})}|`Not->Leakslet()=register_proof_block_delimiter"curly"static_curly_bracedynamic_curly_brace(* ***************** par: ************************************************* *)letstatic_par{entry_point;prev_node}=matchprev_nodeentry_pointwith|None->None|Some{id=pid}->Some{block_stop=entry_point.id;block_start=pid;dynamic_switch=pid;carry_on_data=unit_val}letdynamic_pardoc{dynamic_switch=id}=matchis_focused_goal_simple~docidwith|`Simplefocused->ValidBlock{base_state=id;goals_to_admit=focused;recovery_command=None;}|`Not->Leakslet()=register_proof_block_delimiter"par"static_pardynamic_par(* ***************** simple indentation *********************************** *)letstatic_indent({entry_point;prev_node}asview)=Printf.eprintf"@%d\n"(Stateid.to_intentry_point.id);matchprev_nodeentry_pointwith|None->None|Somelast_tac->iflast_tac.indentation<=entry_point.indentationthenNoneelsecrawlview~init:(Somelast_tac)(funprevnode->ifnode.indentation>=last_tac.indentationthen`Contnodeelse`Found{block_stop=entry_point.id;block_start=node.id;dynamic_switch=node.id;carry_on_data=of_vernac_control_valentry_point.ast})last_tacletdynamic_indentdoc{dynamic_switch=id;carry_on_data=e}=Printf.eprintf"%s\n"(Stateid.to_stringid);matchis_focused_goal_simple~docidwith|`Simple[]->Leaks|`Simplefocused->letbut_last=List.tl(List.revfocused)inValidBlock{base_state=id;goals_to_admit=but_last;recovery_command=Some(to_vernac_control_vale);}|`Not->Leakslet()=register_proof_block_delimiter"indent"static_indentdynamic_indent