@@ -122,7 +122,7 @@ let sigref loc = Libnames.qualid_of_string ~loc "Corelib.Init.Specif.sig"
122122}
123123
124124GRAMMAR EXTEND Gram
125- GLOBAL: binder_constr lconstr constr term
125+ GLOBAL: lconstr constr term
126126 universe_name sort sort_quality_or_set sort_quality_var
127127 global constr_pattern cpattern Constr.ident
128128 closed_binder open_binders binder binders binders_fixannot
@@ -215,7 +215,40 @@ GRAMMAR EXTEND Gram
215215 { let { CAst.loc = locid; v = id } = lid in
216216 let args = List.map (fun x -> CAst.make @@ CRef (qualid_of_ident ?loc:x.CAst.loc x.CAst.v, None), None) args in
217217 CAst.make ~loc @@ CApp(CAst.make ?loc:locid @@ CPatVar id,args) }
218- | c = binder_constr -> { c } ]
218+ | "forall"; bl = open_binders; ","; c = term LEVEL "200" ->
219+ { mkProdCN ~loc bl c }
220+ | "fun"; bl = open_binders; "=>"; c = term LEVEL "200" ->
221+ { mkLambdaCN ~loc bl c }
222+ | "let"; id=name; bl = binders; ty = let_type_cstr; ":=";
223+ c1 = term LEVEL "200"; "in"; c2 = term LEVEL "200" ->
224+ { let ty,c1 = match ty, c1 with
225+ | (_,None), { CAst.v = CCast(c, Some DEFAULTcast, t) } -> (Loc.tag ?loc:(constr_loc t) @@ Some t), c (* Tolerance, see G_vernac.def_body *)
226+ | _, _ -> ty, c1 in
227+ CAst.make ~loc @@ CLetIn(id,mkLambdaCN ?loc:(constr_loc c1) bl c1,
228+ Option.map (mkProdCN ?loc:(fst ty) bl) (snd ty), c2) }
229+ | "let"; "fix"; fx = fix_decl; "in"; c = term LEVEL "200" ->
230+ { let {CAst.loc=locf;CAst.v=({CAst.loc=li;CAst.v=id} as lid,_,_,_,_,_ as dcl)} = fx in
231+ let fix = CAst.make ?loc:locf @@ CFix (lid,[dcl]) in
232+ CAst.make ~loc @@ CLetIn( CAst.make ?loc:li @@ Name id,fix,None,c) }
233+ | "let"; "cofix"; fx = cofix_body; "in"; c = term LEVEL "200" ->
234+ { let {CAst.loc=locf;CAst.v=({CAst.loc=li;CAst.v=id} as lid,_,_,_,_ as dcl)} = fx in
235+ let cofix = CAst.make ?loc:locf @@ CCoFix (lid,[dcl]) in
236+ CAst.make ~loc @@ CLetIn( CAst.make ?loc:li @@ Name id,cofix,None,c) }
237+ | "let"; lb = ["("; l=LIST0 name SEP ","; ")" -> { l } | "()" -> { [] } ];
238+ po = as_return_type; ":="; c1 = term LEVEL "200"; "in";
239+ c2 = term LEVEL "200" ->
240+ { CAst.make ~loc @@ CLetTuple (lb,po,c1,c2) }
241+ | "let"; "'"; p = pattern LEVEL "200"; t = OPT [ "in"; t = pattern LEVEL "200" -> { t } ];
242+ ":="; c1 = term LEVEL "200"; rt = OPT case_type;
243+ "in"; c2 = term LEVEL "200" ->
244+ { CAst.make ~loc @@
245+ CCases (LetPatternStyle, rt, [c1, aliasvar p, t], [CAst.make ~loc ([[p]], c2)]) }
246+ | "if"; c = term LEVEL "200"; po = as_return_type;
247+ "then"; b1 = term LEVEL "200";
248+ "else"; b2 = term LEVEL "200" ->
249+ { CAst.make ~loc @@ CIf (c, po, b1, b2) }
250+ | "fix"; c = fix_decls -> { let (id,dcls) = c in CAst.make ~loc @@ CFix (id,dcls) }
251+ | "cofix"; c = cofix_decls -> { let (id,dcls) = c in CAst.make ~loc @@ CCoFix (id,dcls) } ]
219252 | "9"
220253 [ ".."; c = term LEVEL "0"; ".." ->
221254 { CAst.make ~loc @@ CAppExpl ((qualid_of_ident ~loc ldots_var, None),[c]) } ]
@@ -270,42 +303,6 @@ GRAMMAR EXTEND Gram
270303 [ [ id = global; bl = binders; ":="; c = lconstr ->
271304 { (id, mkLambdaCN ~loc bl c) } ] ]
272305 ;
273- binder_constr:
274- [ [ "forall"; bl = open_binders; ","; c = term LEVEL "200" ->
275- { mkProdCN ~loc bl c }
276- | "fun"; bl = open_binders; "=>"; c = term LEVEL "200" ->
277- { mkLambdaCN ~loc bl c }
278- | "let"; id=name; bl = binders; ty = let_type_cstr; ":=";
279- c1 = term LEVEL "200"; "in"; c2 = term LEVEL "200" ->
280- { let ty,c1 = match ty, c1 with
281- | (_,None), { CAst.v = CCast(c, Some DEFAULTcast, t) } -> (Loc.tag ?loc:(constr_loc t) @@ Some t), c (* Tolerance, see G_vernac.def_body *)
282- | _, _ -> ty, c1 in
283- CAst.make ~loc @@ CLetIn(id,mkLambdaCN ?loc:(constr_loc c1) bl c1,
284- Option.map (mkProdCN ?loc:(fst ty) bl) (snd ty), c2) }
285- | "let"; "fix"; fx = fix_decl; "in"; c = term LEVEL "200" ->
286- { let {CAst.loc=locf;CAst.v=({CAst.loc=li;CAst.v=id} as lid,_,_,_,_,_ as dcl)} = fx in
287- let fix = CAst.make ?loc:locf @@ CFix (lid,[dcl]) in
288- CAst.make ~loc @@ CLetIn( CAst.make ?loc:li @@ Name id,fix,None,c) }
289- | "let"; "cofix"; fx = cofix_body; "in"; c = term LEVEL "200" ->
290- { let {CAst.loc=locf;CAst.v=({CAst.loc=li;CAst.v=id} as lid,_,_,_,_ as dcl)} = fx in
291- let cofix = CAst.make ?loc:locf @@ CCoFix (lid,[dcl]) in
292- CAst.make ~loc @@ CLetIn( CAst.make ?loc:li @@ Name id,cofix,None,c) }
293- | "let"; lb = ["("; l=LIST0 name SEP ","; ")" -> { l } | "()" -> { [] } ];
294- po = as_return_type; ":="; c1 = term LEVEL "200"; "in";
295- c2 = term LEVEL "200" ->
296- { CAst.make ~loc @@ CLetTuple (lb,po,c1,c2) }
297- | "let"; "'"; p = pattern LEVEL "200"; t = OPT [ "in"; t = pattern LEVEL "200" -> { t } ];
298- ":="; c1 = term LEVEL "200"; rt = OPT case_type;
299- "in"; c2 = term LEVEL "200" ->
300- { CAst.make ~loc @@
301- CCases (LetPatternStyle, rt, [c1, aliasvar p, t], [CAst.make ~loc ([[p]], c2)]) }
302- | "if"; c = term LEVEL "200"; po = as_return_type;
303- "then"; b1 = term LEVEL "200";
304- "else"; b2 = term LEVEL "200" ->
305- { CAst.make ~loc @@ CIf (c, po, b1, b2) }
306- | "fix"; c = fix_decls -> { let (id,dcls) = c in CAst.make ~loc @@ CFix (id,dcls) }
307- | "cofix"; c = cofix_decls -> { let (id,dcls) = c in CAst.make ~loc @@ CCoFix (id,dcls) } ] ]
308- ;
309306 arg:
310307 [ [ test_lpar_id_coloneq; "("; id = identref; ":="; c = lconstr; ")" -> { (c,Some (CAst.make ?loc:id.CAst.loc @@ ExplByName id.CAst.v)) }
311308 | test_lpar_nat_coloneq; "("; n = natural; ":="; c = lconstr; ")" -> { (c,Some (CAst.make ~loc @@ ExplByPos n)) }
0 commit comments