123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296# 11 "plugins/ssrrewrite/ssrrewrite.mlg"openConstrexpropenProcq.ConstropenLtac_pluginopenSsreflect_plugin.SsrtacticalsopenSsreflect_plugin.SsrequalityopenSsreflect_plugin.SsrparseropenSsreflect_plugin.Ssrtacsletwarn_deprecated_rewrite=CWarnings.create~name:"rewrite-rw"~category:Deprecation.Version.v9_3~quickfix:(fun~loc()->[Quickfix.make~loc(Pp.str"rw")])(fun()->Pp.str"The ssreflect 'rewrite' tactic has been renamed 'rw' (available from Rocq 9.3).")letwarn_deprecated_rewrite?loc()=(* 7 = length "rewrite" *)letloc=Option.map(funl->Loc.subl07)locinwarn_deprecated_rewrite?loc()# 25 "plugins/ssrrewrite/ssrrewrite.ml"let(wit_ssrrewriteargs,ssrrewriteargs)=Tacentries.argument_extend~plugin:"rocq-runtime.plugins.ssreflect_rewrite"~name:"ssrrewriteargs"~ignore_kw:true{Tacentries.arg_parsing=Vernacextend.Arg_rules[];Tacentries.arg_tag=Some(Geninterp.Val.List(Geninterp.val_tag(Genarg.topwitwit_ssrrwarg)));Tacentries.arg_intern=Tacentries.ArgInternWit(Genarg.ListArg(wit_ssrrwarg));Tacentries.arg_subst=Tacentries.ArgSubstWit(Genarg.ListArg(wit_ssrrwarg));Tacentries.arg_interp=Tacentries.ArgInterpWit(Genarg.ListArg(wit_ssrrwarg));Tacentries.arg_printer=((funenvsigma-># 42 "plugins/ssrrewrite/ssrrewrite.mlg"pr_ssrrwargs# 40 "plugins/ssrrewrite/ssrrewrite.ml"),(funenvsigma-># 42 "plugins/ssrrewrite/ssrrewrite.mlg"pr_ssrrwargs# 44 "plugins/ssrrewrite/ssrrewrite.ml"),(funenvsigma-># 42 "plugins/ssrrewrite/ssrrewrite.mlg"pr_ssrrwargs# 49 "plugins/ssrrewrite/ssrrewrite.ml"));}let_=(wit_ssrrewriteargs,ssrrewriteargs)# 45 "plugins/ssrrewrite/ssrrewrite.mlg"letssr_rewrite_syntax=Summary.ref~name:"SSR:rewrite"truelet()=Goptions.(declare_bool_option{optstage=Summary.Stage.Synterp;optkey=["SsrRewrite"];optread=(fun_->!ssr_rewrite_syntax);optdepr=None;optwrite=(funb->ssr_rewrite_syntax:=b)})letlbrace=Char.chr123(** Workaround to a limitation of coqpp *)lettest_ssr_rewrite_syntax=lettestkwstatestrm=ifnot!ssr_rewrite_syntaxthenError()elseifPptactic.ssr_rewrite_loaded()thenOk()elsematchLStream.peek_nthkwstate0strmwith|Some(Tok.KEYWORDkey)whenList.memkey.[0][lbrace;'[';'/']->Ok()|_->Error()inProcq.Entry.(of_parser"test_ssr_rewrite_syntax"{parser_fun=test})# 81 "plugins/ssrrewrite/ssrrewrite.ml"let_=let()=Egramml.grammar_extend~plugin_uid:("rocq-runtime.plugins.ssreflect_rewrite","ssrrewrite.mlg:0")~ignore_kw:truessrrewriteargs(Procq.Reuse(None,[Procq.Production.make(Procq.Rule.next(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.ntermtest_ssr_rewrite_syntax)))((Procq.Symbol.ntermssrrwargs)))(funa_loc-># 73 "plugins/ssrrewrite/ssrrewrite.mlg"a# 94 "plugins/ssrrewrite/ssrrewrite.ml")]))in()let()=Tacentries.tactic_extend"rocq-runtime.plugins.ssreflect_rewrite""ssrrewrite"~level:0~warn:(warn_deprecated_rewrite)[(Tacentries.TyML(Tacentries.TyIdent("rewrite",Tacentries.TyArg(Extend.TUentry(Genarg.get_arg_tagwit_ssrrewriteargs),Tacentries.TyArg(Extend.TUentry(Genarg.get_arg_tagwit_ssrclauses),Tacentries.TyNil))),(funargsclausesist-># 80 "plugins/ssrrewrite/ssrrewrite.mlg"tclCLAUSES(ssrrewritetacistargs)clauses# 107 "plugins/ssrrewrite/ssrrewrite.ml")))]# 83 "plugins/ssrrewrite/ssrrewrite.mlg"(* global syntactic changes and vernacular commands *)(** Alternative notations for "match" and anonymous arguments. *)(* ************)(* Syntax: *)(* if <term> is <pattern> then ... else ... *)(* if <term> is <pattern> [in ..] return ... then ... else ... *)(* The scope of a top-level 'as' in the pattern extends over the *)(* 'return' type (dependent if/let). *)(* in b (*^--ALTERNATIVE INNER LET--------^ *) *)(* Caveat : There is no pretty-printing support, since this would *)(* require a modification to the Rocq kernel (adding a new match *)(* display style -- why aren't these strings?); also, the v8.1 *)(* pretty-printer only allows extension hooks for printing *)(* integer or string literals. *)(* Also note that in the v8 grammar "is" needs to be a keyword; *)(* as this can't be done from an ML extension file, the new *)(* syntax will only work when ssreflect.v is imported. *)letno_ct=None,Noneandno_rt=Noneletaliasvar=function|[[{CAst.v=CPatAlias(_,na);loc}]]->Somena|_->Noneletmk_cnotypemp=aliasvarmp,Noneletmk_ctypempt=aliasvarmp,Sometletmk_rtypet=Sometletmk_dthen?loc(mp,ct,rt)c=(CAst.make?loc(mp,c)),ct,rtletmk_patc(na,t)=(c,na,t)# 145 "plugins/ssrrewrite/ssrrewrite.ml"let_=letssr_rtype=Procq.Entry.make"ssr_rtype"andssr_mpat=Procq.Entry.make"ssr_mpat"andssr_dpat=Procq.Entry.make"ssr_dpat"andssr_dthen=Procq.Entry.make"ssr_dthen"andssr_elsepat=Procq.Entry.make"ssr_elsepat"andssr_else=Procq.Entry.make"ssr_else"inlet()=assert(Procq.Entry.is_emptyssr_rtype)inlet()=Egramml.grammar_extend~plugin_uid:("rocq-runtime.plugins.ssreflect_rewrite","ssrrewrite.mlg:1")~ignore_kw:truessr_rtype(Procq.Fresh(Gramlib.Gramext.First,[(None,None,[Procq.Production.make(Procq.Rule.next(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.token(Tok.PKEYWORD("return")))))((Procq.Symbol.ntermlterm("100"))))(funt_loc-># 119 "plugins/ssrrewrite/ssrrewrite.mlg"mk_rtypet# 169 "plugins/ssrrewrite/ssrrewrite.ml")])]))inlet()=assert(Procq.Entry.is_emptyssr_mpat)inlet()=Egramml.grammar_extend~plugin_uid:("rocq-runtime.plugins.ssreflect_rewrite","ssrrewrite.mlg:2")~ignore_kw:truessr_mpat(Procq.Fresh(Gramlib.Gramext.First,[(None,None,[Procq.Production.make(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.ntermpattern)))(funploc-># 120 "plugins/ssrrewrite/ssrrewrite.mlg"[[p]]# 183 "plugins/ssrrewrite/ssrrewrite.ml")])]))inlet()=assert(Procq.Entry.is_emptyssr_dpat)inlet()=Egramml.grammar_extend~plugin_uid:("rocq-runtime.plugins.ssreflect_rewrite","ssrrewrite.mlg:3")~ignore_kw:truessr_dpat(Procq.Fresh(Gramlib.Gramext.First,[(None,None,[Procq.Production.make(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.ntermssr_mpat)))(funmploc-># 124 "plugins/ssrrewrite/ssrrewrite.mlg"mp,no_ct,no_rt# 197 "plugins/ssrrewrite/ssrrewrite.ml");Procq.Production.make(Procq.Rule.next(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.ntermssr_mpat)))((Procq.Symbol.ntermssr_rtype)))(funrtmploc-># 123 "plugins/ssrrewrite/ssrrewrite.mlg"mp,mk_cnotypemp,rt# 207 "plugins/ssrrewrite/ssrrewrite.ml");Procq.Production.make(Procq.Rule.next(Procq.Rule.next(Procq.Rule.next(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.ntermssr_mpat)))((Procq.Symbol.token(Tok.PKEYWORD("in")))))((Procq.Symbol.ntermpattern)))((Procq.Symbol.ntermssr_rtype)))(funrtt_mploc-># 122 "plugins/ssrrewrite/ssrrewrite.mlg"mp,mk_ctypempt,rt# 221 "plugins/ssrrewrite/ssrrewrite.ml")])]))inlet()=assert(Procq.Entry.is_emptyssr_dthen)inlet()=Egramml.grammar_extend~plugin_uid:("rocq-runtime.plugins.ssreflect_rewrite","ssrrewrite.mlg:4")~ignore_kw:truessr_dthen(Procq.Fresh(Gramlib.Gramext.First,[(None,None,[Procq.Production.make(Procq.Rule.next(Procq.Rule.next(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.ntermssr_dpat)))((Procq.Symbol.token(Tok.PKEYWORD("then")))))((Procq.Symbol.ntermlconstr)))(func_dploc-># 126 "plugins/ssrrewrite/ssrrewrite.mlg"mk_dthen~locdpc# 239 "plugins/ssrrewrite/ssrrewrite.ml")])]))inlet()=assert(Procq.Entry.is_emptyssr_elsepat)inlet()=Egramml.grammar_extend~plugin_uid:("rocq-runtime.plugins.ssreflect_rewrite","ssrrewrite.mlg:5")~ignore_kw:truessr_elsepat(Procq.Fresh(Gramlib.Gramext.First,[(None,None,[Procq.Production.make(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.token(Tok.PKEYWORD("else")))))(fun_loc-># 127 "plugins/ssrrewrite/ssrrewrite.mlg"[[CAst.make~loc@@CPatAtomNone]]# 253 "plugins/ssrrewrite/ssrrewrite.ml")])]))inlet()=assert(Procq.Entry.is_emptyssr_else)inlet()=Egramml.grammar_extend~plugin_uid:("rocq-runtime.plugins.ssreflect_rewrite","ssrrewrite.mlg:6")~ignore_kw:truessr_else(Procq.Fresh(Gramlib.Gramext.First,[(None,None,[Procq.Production.make(Procq.Rule.next(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.ntermssr_elsepat)))((Procq.Symbol.ntermlconstr)))(funcmploc-># 128 "plugins/ssrrewrite/ssrrewrite.mlg"CAst.make~loc(mp,c)# 269 "plugins/ssrrewrite/ssrrewrite.ml")])]))inlet()=Egramml.grammar_extend~plugin_uid:("rocq-runtime.plugins.ssreflect_rewrite","ssrrewrite.mlg:7")~ignore_kw:trueterm(Procq.Reuse(Some("10"),[Procq.Production.make(Procq.Rule.next(Procq.Rule.next(Procq.Rule.next(Procq.Rule.next(Procq.Rule.next(Procq.Rule.stop)((Procq.Symbol.token(Tok.PKEYWORD("if")))))((Procq.Symbol.ntermlterm("200"))))((Procq.Symbol.token(Tok.PKEYWORD("isn't")))))((Procq.Symbol.ntermssr_dthen)))((Procq.Symbol.ntermssr_else)))(funb2db1_c_loc-># 131 "plugins/ssrrewrite/ssrrewrite.mlg"letb1,ct,rt=db1inletb1,b2=letopenCAstinlet{loc=l1;v=(p1,r1)},{loc=l2;v=(p2,r2)}=b1,b2in(make?loc:l1(p1,r2),make?loc:l2(p2,r1))inCAst.make~loc@@CCases(MatchStyle,rt,[mk_patcct],[b1;b2])# 294 "plugins/ssrrewrite/ssrrewrite.ml")]))in()