12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697(************************************************************************)(* * 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) *)(************************************************************************)openUtilopenExtendopenPcoqopenGenargopenVernacexpr(** Grammar extensions declared at ML level *)type'sgrammar_prod_item=|GramTerminalofstring|GramNonTerminal:('araw_abstract_argument_type*('s,_,'a)Symbol.t)Loc.located->'sgrammar_prod_itemtype'aty_arg=('a->raw_generic_argument)type('self,'tr,_,'r)ty_rule=|TyStop:('self,Gramlib.Grammar.norec,'r,'r)ty_rule|TyNext:('self,_,'a,'r)ty_rule*('self,_,'b)Symbol.t*'bty_argoption->('self,Gramlib.Grammar.mayrec,'b->'a,'r)ty_ruletype('self,'r)any_ty_rule=|AnyTyRule:('self,_,'act,Loc.t->'r)ty_rule->('self,'r)any_ty_ruleletrecty_rule_of_gram=function|[]->AnyTyRuleTyStop|GramTerminals::rem->letAnyTyRulerem=ty_rule_of_gramreminlettok=Pcoq.Symbol.token(CLexer.terminals)inletr=TyNext(rem,tok,None)inAnyTyRuler|GramNonTerminal(_,(t,tok))::rem->letAnyTyRulerem=ty_rule_of_gramreminletinj=Some(funobj->Genarg.in_gentobj)inletr=TyNext(rem,tok,inj)inAnyTyRulerletrecty_erase:typestrar.(s,tr,a,r)ty_rule->(s,tr,a,r)Pcoq.Rule.t=function|TyStop->Pcoq.Rule.stop|TyNext(rem,tok,_)->Pcoq.Rule.next(ty_eraserem)toktype'rgen_eval=Loc.t->raw_generic_argumentlist->'rletrecty_eval:typestra.(s,tr,a,Loc.t->s)ty_rule->sgen_eval->a=function|TyStop->funfloc->floc[]|TyNext(rem,tok,None)->funf_->ty_evalremf|TyNext(rem,tok,Someinj)->funfx->letflocargs=floc(injx::args)inty_evalremfletmake_rulefprod=letAnyTyRulety_rule=ty_rule_of_gram(List.revprod)inletsymb=ty_erasety_ruleinletflocl=floc(List.revl)inletact=ty_evalty_rulefinPcoq.Production.makesymbactletrecproj_symbol:typeabc.(a,b,c)ty_user_symbol->(a,b,c)genarg_type=function|TUentrya->ExtraArga|TUentryl(a,l)->ExtraArga|TUopt(o)->OptArg(proj_symbolo)|TUlist1l->ListArg(proj_symboll)|TUlist1sep(l,_)->ListArg(proj_symboll)|TUlist0l->ListArg(proj_symboll)|TUlist0sep(l,_)->ListArg(proj_symboll)(** Vernac grammar extensions *)letvernac_exts=ref[]letget_extend_vernac_rule(s,i)=tryletfind((name,j),_)=String.equalnames&&Int.equalijinlet(_,rules)=List.findfind!vernac_extsinruleswith|Failure_->raiseNot_foundletextend_vernac_command_grammarsntgl=letnt=Option.defaultPvernac.Vernac_.commandntinvernac_exts:=(s,gl)::!vernac_exts;letmkactlocl=VernacExtend(s,l)inletrules=[make_rulemkactgl]inifPcoq.Entry.is_emptyntthen(* Small hack to tolerate empty entries in VERNAC { ... } EXTEND *)grammar_extendnt(Pcoq.Fresh(Gramlib.Gramext.First,[None,None,rules]))elsegrammar_extendnt(Pcoq.Reuse(None,rules))