1 (* Copyright (C) 2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 (* $Id: grafiteParser.ml 13176 2016-04-18 15:29:33Z fguidi $ *)
31 let exc_located_wrapper f =
35 | Ploc.Exc (_, End_of_file) -> raise End_of_file
36 | Ploc.Exc (floc, Stream.Error msg) ->
37 raise (HExtlib.Localized (floc,CicNotationParser.Parse_error msg))
38 | Ploc.Exc (floc, HExtlib.Localized(_,exn)) ->
39 raise (HExtlib.Localized
40 (floc,CicNotationParser.Parse_error (Printexc.to_string exn)))
41 | Ploc.Exc (floc, exn) ->
42 raise (HExtlib.Localized
43 (floc,CicNotationParser.Parse_error (Printexc.to_string exn)))
45 type parsable = Grammar.parsable * Ulexing.lexbuf
47 let parsable_statement status buf =
48 let grammar = CicNotationParser.level2_ast_grammar status in
49 Grammar.parsable grammar (Obj.magic buf), buf
51 let parse_statement grafite_parser parsable =
53 (fun () -> (Grammar.Entry.parse_parsable grafite_parser (fst parsable)))
55 let strm_of_parsable (_,buf) = buf
57 let add_raw_attribute ~text t = N.AttributedTerm (`Raw text, t)
59 let default_associativity = Gramext.NonA
61 let mk_rec_corec src flavour ind_kind defs loc =
62 let attrs = src, flavour, `Regular in
63 (loc, N.LetRec (ind_kind, defs, attrs))
65 let nmk_rec_corec src flavour ind_kind defs loc index =
66 let loc,t = mk_rec_corec src flavour ind_kind defs loc in
69 let shift_vars binder (vars, ty) bo =
70 let map var bo = N.Binder (binder, (var, ty), bo) in
71 List.fold_right map vars bo
73 let shift_params binder params bo =
74 List.fold_right (shift_vars binder) params bo
76 let nnon_punct_of_punct = function
77 | G.Skip loc -> G.NSkip loc
78 | G.Unfocus loc -> G.NUnfocus loc
79 | G.Focus (loc,l) -> G.NFocus (loc,l)
82 type by_continuation =
84 | BYC_weproved of N.term * string option
85 | BYC_letsuchthat of string * N.term * N.term * string
86 | BYC_wehaveand of string * N.term * string * N.term
88 let mk_parser statement lstatus =
89 (* let grammar = CicNotationParser.level2_ast_grammar lstatus in *)
90 let term = CicNotationParser.term lstatus in
91 let let_defs = CicNotationParser.let_defs lstatus in
92 let let_codefs = CicNotationParser.let_codefs lstatus in
93 let protected_binder_vars = CicNotationParser.protected_binder_vars lstatus in
94 (* {{{ parser initialization *)
96 GLOBAL: term statement;
98 [ name = IDENT; params = LIST0 protected_binder_vars; SYMBOL ":"; typ = term -> (* FG: params added *)
99 (name, shift_params `Forall params typ)
102 tactic_term: [ [ t = term LEVEL "90" -> t ] ];
103 ident_list1: [ [ LPAREN; idents = LIST1 IDENT; RPAREN -> idents ] ];
105 [ IDENT "normalize" ; delta = OPT [ IDENT "nodelta" -> () ] ->
106 let delta = match delta with None -> true | _ -> false in
108 | IDENT "whd" ; delta = OPT [ IDENT "nodelta" -> () ] ->
109 let delta = match delta with None -> true | _ -> false in
112 sequent_pattern_spec: [
116 path = OPT [SYMBOL ":" ; path = tactic_term -> path ] ->
117 (id,match path with Some p -> p | None -> N.UserInput) ];
118 goal_path = OPT [ SYMBOL <:unicode<vdash>>; term = tactic_term -> term ] ->
120 match goal_path, hyp_paths with
121 None, [] -> Some N.UserInput
123 | Some goal_path, _ -> Some goal_path
132 [ "match" ; wanted = tactic_term ;
133 sps = OPT [ "in"; sps = sequent_pattern_spec -> sps ] ->
135 | sps = sequent_pattern_spec ->
139 let wanted,hyp_paths,goal_path =
140 match wanted_and_sps with
141 wanted,None -> wanted, [], Some N.UserInput
142 | wanted,Some (hyp_paths,goal_path) -> wanted,hyp_paths,goal_path
144 wanted, hyp_paths, goal_path ] ->
146 None -> None,[],Some N.UserInput
149 inverter_param_list: [
150 [ params = tactic_term ->
151 let deannotate = function
152 | N.AttributedTerm (_,t) | t -> t
153 in match deannotate params with
154 | N.Implicit _ -> [false]
155 | N.UserInput -> [true]
157 List.map (fun x -> match deannotate x with
158 | N.Implicit _ -> false
159 | N.UserInput -> true
160 | _ -> raise (Invalid_argument "malformed target parameter list 1")) l
162 (*CSC: new NCicPp.status is the best I can do here without changing the
164 raise (Invalid_argument ("malformed target parameter list 2\n" ^ NotationPp.pp_term (new NCicPp.status) params)) ]
167 [ SYMBOL ">" -> `LeftToRight
168 | SYMBOL "<" -> `RightToLeft ]
170 int: [ [ num = NUMBER -> int_of_string num ] ];
172 [ SYMBOL "@"; t = tactic_term -> G.NTactic(loc,[G.NApply (loc, t)])
173 | IDENT "applyS"; t = tactic_term -> G.NTactic(loc,[G.NSmartApply(loc, t)])
177 [ id = IDENT ; SYMBOL ":" ; ty = tactic_term -> id,`Decl ty
178 | id = IDENT ; SYMBOL ":" ; ty = tactic_term ;
179 SYMBOL <:unicode<def>> ; bo = tactic_term ->
181 SYMBOL <:unicode<vdash>>;
182 concl = tactic_term -> (List.rev hyps,concl) ] ->
183 G.NTactic(loc,[G.NAssert (loc, seqs)])
184 | SYMBOL "/"; num = OPT NUMBER ;
185 just_and_params = auto_params; SYMBOL "/" ->
186 let just,params = just_and_params in
187 let depth = match num with Some n -> n | None -> "1" in
191 [G.NAuto(loc,(None,["depth",depth]@params))])
192 | Some (`Univ univ) ->
194 [G.NAuto(loc,(Some univ,["depth",depth]@params))])
197 G.NAutoInteractive (loc, (None,["depth",depth]@params))))
198 | SYMBOL "#"; SYMBOL "#" -> G.NMacro (loc, G.NIntroGuess loc)
199 | IDENT "check"; t = tactic_term -> G.NMacro(loc,G.NCheck (loc,t))
200 | IDENT "screenshot"; fname = QSTRING ->
201 G.NMacro(loc,G.Screenshot (loc, fname))
202 | IDENT "cases"; what = tactic_term ; where = pattern_spec ->
203 G.NTactic(loc,[G.NCases (loc, what, where)])
204 | IDENT "change"; "with"; with_what = tactic_term; what = pattern_spec ->
205 G.NTactic(loc,[G.NChange (loc, what, with_what)])
206 | SYMBOL "-"; id = IDENT ->
207 G.NTactic(loc,[G.NClear (loc, [id])])
208 | PLACEHOLDER; num = OPT NUMBER;
209 l = OPT [ SYMBOL "{"; l = LIST1 tactic_term; SYMBOL "}" -> l ] ->
210 G.NTactic(loc,[G.NConstructor (loc, (match num with None -> None | Some x -> Some (int_of_string x)),match l with None -> [] | Some l -> l)])
211 | IDENT "cut"; t = tactic_term -> G.NTactic(loc,[G.NCut (loc, t)])
212 | IDENT "destruct"; just = OPT [ dom = ident_list1 -> dom ];
213 exclude = OPT [ IDENT "skip"; skip = ident_list1 -> skip ]
214 -> let exclude' = match exclude with None -> [] | Some l -> l in
215 G.NTactic(loc,[G.NDestruct (loc,just,exclude')])
216 | IDENT "elim"; what = tactic_term ; where = pattern_spec ->
217 G.NTactic(loc,[G.NElim (loc, what, where)])
218 | IDENT "generalize"; p=pattern_spec ->
219 G.NTactic(loc,[G.NGeneralize (loc, p)])
220 | IDENT "inversion"; what = tactic_term ; where = pattern_spec ->
221 G.NTactic(loc,[G.NInversion (loc, what, where)])
222 | IDENT "lapply"; t = tactic_term -> G.NTactic(loc,[G.NLApply (loc, t)])
223 | IDENT "letin"; name = IDENT ; SYMBOL <:unicode<def>> ; t = tactic_term;
224 where = pattern_spec ->
225 G.NTactic(loc,[G.NLetIn (loc,where,t,name)])
226 | kind = nreduction_kind; p = pattern_spec ->
227 G.NTactic(loc,[G.NReduce (loc, kind, p)])
228 | dir = direction; what = tactic_term ; where = pattern_spec ->
229 G.NTactic(loc,[G.NRewrite (loc, dir, what, where)])
230 | IDENT "try"; tac = SELF ->
231 let tac = match tac with G.NTactic(_,[t]) -> t | _ -> assert false in
232 G.NTactic(loc,[ G.NTry (loc,tac)])
233 | IDENT "repeat"; tac = SELF ->
234 let tac = match tac with G.NTactic(_,[t]) -> t | _ -> assert false in
235 G.NTactic(loc,[ G.NRepeat (loc,tac)])
236 | LPAREN; l = LIST1 SELF; RPAREN ->
239 (List.map (function G.NTactic(_,t) -> t | _ -> assert false) l) in
240 G.NTactic(loc,[G.NBlock (loc,l)])
241 | IDENT "assumption" -> G.NTactic(loc,[ G.NAssumption loc])
242 | SYMBOL "#"; ns=IDENT -> G.NTactic(loc,[ G.NIntros (loc,[ns])])
243 | SYMBOL "#"; SYMBOL "_" -> G.NTactic(loc,[ G.NIntro (loc,"_")])
244 | SYMBOL "*" -> G.NTactic(loc,[ G.NCase1 (loc,"_")])
245 | SYMBOL "*"; "as"; n=IDENT -> G.NTactic(loc,[ G.NCase1 (loc,n)])
246 | IDENT "assume" ; id = IDENT; SYMBOL ":"; t = tactic_term -> G.NTactic (loc,[G.Assume (loc,id,t)])
247 | IDENT "suppose" ; t = tactic_term ; LPAREN ; id = IDENT ; RPAREN -> G.NTactic (loc,[G.Suppose (loc,t,id)])
248 | "let"; name = IDENT ; SYMBOL <:unicode<def>> ; t = tactic_term ->
249 G.NTactic(loc,[G.NLetIn (loc,(None,[],Some N.UserInput),t,name)])
251 [ IDENT "using"; t=tactic_term -> `Term t
252 | params = auto_params ->
253 let just,params = params in
256 | None -> (None,params)
257 | Some (`Univ univ) -> (Some univ,params)
258 (* `Trace behaves exaclty like None for the moment being *)
259 | Some (`Trace) -> (None,params)
262 cont=by_continuation -> G.NTactic (loc,[
264 BYC_done -> G.Bydone (loc, just)
265 | BYC_weproved (ty,id) ->
266 G.By_just_we_proved(loc, just, ty, id)
267 | BYC_letsuchthat (id1,t1,t2,id2) ->
268 G.ExistsElim (loc, just, id1, t1, t2, id2)
269 | BYC_wehaveand (id1,t1,id2,t2) ->
270 G.AndElim (loc, just, t1, id1, t2, id2))
272 | IDENT "we" ; IDENT "need" ; "to" ; IDENT "prove" ; t = tactic_term ; id = OPT [ LPAREN ; id = IDENT ; RPAREN -> id ] ->
273 G.NTactic (loc,[G.We_need_to_prove (loc, t, id)])
274 | IDENT "that" ; IDENT "is" ; IDENT "equivalent" ; "to" ; t = tactic_term -> G.NTactic(loc,[G.BetaRewritingStep (loc,t)])
275 | IDENT "the" ; IDENT "thesis" ; IDENT "becomes" ; t1=tactic_term -> G.NTactic (loc,[G.Thesisbecomes(loc,t1)])
276 | IDENT "we" ; IDENT "proceed" ; IDENT "by" ; IDENT "cases" ; "on" ; t=tactic_term ; "to" ; IDENT "prove" ; t1=tactic_term ->
277 G.NTactic (loc,[G.We_proceed_by_cases_on (loc, t, t1)])
278 | IDENT "we" ; IDENT "proceed" ; IDENT "by" ; IDENT "induction" ; "on" ; t=tactic_term ; "to" ; IDENT "prove" ; t1=tactic_term ->
279 G.NTactic (loc,[G.We_proceed_by_induction_on (loc, t, t1)])
280 | IDENT "by" ; IDENT "induction" ; IDENT "hypothesis" ; IDENT "we" ; IDENT "know" ; t=tactic_term ; LPAREN ; id = IDENT ; RPAREN ->
281 G.NTactic (loc,[G.Byinduction(loc, t, id)])
282 | IDENT "case" ; id = IDENT ; params=LIST0[LPAREN ; i=IDENT ;
283 SYMBOL":" ; t=tactic_term ; RPAREN -> i,t] ->
284 G.NTactic (loc,[G.Case(loc,id,params)])
285 | IDENT "print_stack" -> G.NTactic (loc,[G.PrintStack loc])
286 (* DO NOT FACTORIZE with the two following, camlp5 sucks*)
289 termine = tactic_term;
293 [ IDENT "using"; t=tactic_term -> `Term t
294 | IDENT "using"; IDENT "once"; term=tactic_term -> `SolveWith term
295 | IDENT "proof" -> `Proof
296 | params = auto_params -> `Auto
298 let just,params = params in
300 | None -> (None,params)
301 | Some (`Univ univ) -> (Some univ,params)
302 (* `Trace behaves exaclty like None for the moment being *)
303 | Some (`Trace) -> (None,params)
306 cont = rewriting_step_continuation ->
307 G.NTactic (loc,[G.RewritingStep(loc, Some (None,termine), t1, t2, cont)])
308 | IDENT "obtain" ; name = IDENT;
309 termine = tactic_term;
313 [ IDENT "using"; t=tactic_term -> `Term t
314 | IDENT "using"; IDENT "once"; term=tactic_term -> `SolveWith term
315 | IDENT "proof" -> `Proof
316 | params = auto_params -> `Auto
318 let just,params = params in
320 | None -> (None,params)
321 | Some (`Univ univ) -> (Some univ,params)
322 (* `Trace behaves exaclty like None for the moment being *)
323 | Some (`Trace) -> (None,params)
326 cont = rewriting_step_continuation ->
327 G.NTactic(loc,[G.RewritingStep(loc, Some (Some name,termine), t1, t2, cont)])
329 | IDENT "obtain" ; name = IDENT;
330 termine = tactic_term ->
331 G.NTactic(loc,[G.Obtain(loc, name, termine)])
332 | IDENT "conclude" ; termine = tactic_term ->
333 G.NTactic(loc,[G.Conclude(loc, termine)])
337 [ IDENT "using"; t=tactic_term -> `Term t
338 | IDENT "using"; IDENT "once"; term=tactic_term -> `SolveWith term
339 | IDENT "proof" -> `Proof
340 | params = auto_params -> `Auto
342 let just,params = params in
344 | None -> (None,params)
345 | Some (`Univ univ) -> (Some univ,params)
346 (* `Trace behaves exaclty like None for the moment being *)
347 | Some (`Trace) -> (None,params)
350 cont = rewriting_step_continuation ->
351 G.NTactic(loc,[G.RewritingStep(loc, t1, t2, cont)])
356 | IDENT "fast_paramod"
361 (* | IDENT "timeout" *)
367 i = auto_fixed_param -> i,""
368 | i = auto_fixed_param ; SYMBOL "="; v = [ v = int ->
369 string_of_int v | v = IDENT -> v ] -> i,v ];
370 just = OPT [ IDENT "by"; by =
371 [ univ = LIST0 tactic_term SEP SYMBOL "," -> `Univ univ
372 | SYMBOL "_" -> `Trace ] -> by ] -> just,params
377 [ WEPROVED; ty = tactic_term ; id = OPT [ LPAREN ; id = IDENT ; RPAREN -> id] -> BYC_weproved (ty,id)
379 | "let" ; id1 = IDENT ; SYMBOL ":" ; t1 = tactic_term ;
380 IDENT "such" ; IDENT "that" ; t2=tactic_term ; LPAREN ;
381 id2 = IDENT ; RPAREN -> BYC_letsuchthat (id1,t1,t2,id2)
382 | WEHAVE; t1=tactic_term ; LPAREN ; id1=IDENT ; RPAREN ;"and" ; t2=tactic_term ; LPAREN ; id2=IDENT ; RPAREN ->
383 BYC_wehaveand (id1,t1,id2,t2)
387 rewriting_step_continuation : [
396 [ t1 = SELF; SYMBOL ";"; t2 = SELF ->
399 | G.Seq (_, l) -> l @ [ t2 ]
405 [ tac = SELF; SYMBOL ";";
406 SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
407 (G.Then (loc, tac, tacs))
410 [ IDENT "do"; count = int; tac = SELF ->
411 G.Do (loc, count, tac)
412 | IDENT "repeat"; tac = SELF -> G.Repeat (loc, tac)
416 SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
418 | IDENT "try"; tac = SELF -> G.Try (loc, tac)
420 SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
422 | IDENT "progress"; tac = SELF -> G.Progress (loc, tac)
423 | LPAREN; tac = SELF; RPAREN -> tac
424 | tac = tactic -> tac
428 npunctuation_tactical:
430 [ SYMBOL "[" -> G.NBranch loc
431 | SYMBOL "|" -> G.NShift loc
432 | i = LIST1 int SEP SYMBOL ","; SYMBOL ":" -> G.NPos (loc, i)
433 | SYMBOL "*"; SYMBOL ":" -> G.NWildcard loc
434 | name = IDENT; SYMBOL ":" -> G.NPosbyname (loc, name)
435 | SYMBOL "]" -> G.NMerge loc
436 | SYMBOL ";" -> G.NSemicolon loc
437 | SYMBOL "." -> G.NDot loc
440 nnon_punctuation_tactical:
442 [ IDENT "focus"; goals = LIST1 int -> G.NFocus (loc, goals)
443 | IDENT "unfocus" -> G.NUnfocus loc
444 | IDENT "skip" -> G.NSkip loc
448 [ [ IDENT "definition" ] -> `Definition
449 | [ IDENT "fact" ] -> `Fact
450 | [ IDENT "lemma" ] -> `Lemma
451 | [ IDENT "example" ] -> `Example
452 | [ IDENT "theorem" ] -> `Theorem
453 | [ IDENT "corollary" ] -> `Corollary
458 params = LIST0 protected_binder_vars;
459 SYMBOL ":"; fst_typ = term; SYMBOL <:unicode<def>>; OPT SYMBOL "|";
460 fst_constructors = LIST0 constructor SEP SYMBOL "|";
463 name = IDENT; SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>;
464 OPT SYMBOL "|"; constructors = LIST0 constructor SEP SYMBOL "|" ->
465 (name, true, typ, constructors) ] SEP "with" -> types
469 (fun (names, typ) acc ->
470 (List.map (fun name -> (name, typ)) names) @ acc)
473 let fst_ind_type = (fst_name, true, fst_typ, fst_constructors) in
474 let tl_ind_types = match tl with None -> [] | Some types -> types in
475 let ind_types = fst_ind_type :: tl_ind_types in
481 params = LIST0 protected_binder_vars;
482 SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>; SYMBOL "{" ;
485 params = LIST0 protected_binder_vars; (* FG: params added *)
487 SYMBOL ":" -> false,0
488 | SYMBOL ":"; SYMBOL ">" -> true,0
489 | SYMBOL ":"; arity = int ; SYMBOL ">" -> true,arity
492 let b,n = coercion in
493 (name, shift_params `Forall params ty, b, n)
494 ] SEP SYMBOL ";"; SYMBOL "}" ->
497 (fun (names, typ) acc ->
498 (List.map (fun name -> (name, typ)) names) @ acc)
501 (params,name,typ,fields)
505 [ IDENT "id"; id = QSTRING; SYMBOL "="; uri = QSTRING ->
506 let alpha = "[a-zA-Z]" in
507 let num = "[0-9]+" in
508 let ident_cont = "\\("^alpha^"\\|"^num^"\\|_\\|\\\\\\)" in
509 let decoration = "\\'" in
510 let ident = "\\("^alpha^ident_cont^"*"^decoration^"*\\|_"^ident_cont^"+"^decoration^"*\\)" in
511 let rex = Str.regexp ("^"^ident^"$") in
512 if Str.string_match rex id 0 then
513 if (try ignore (NReference.reference_of_string uri); true
514 with NReference.IllFormedReference _ -> false)
516 G.Ident_alias (id, uri)
519 (HExtlib.Localized (loc, CicNotationParser.Parse_error (Printf.sprintf "Not a valid uri: %s" uri)))
521 raise (HExtlib.Localized (loc, CicNotationParser.Parse_error (
522 Printf.sprintf "Not a valid identifier: %s" id)))
523 | IDENT "symbol"; symbol = QSTRING;
524 instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
525 SYMBOL "="; dsc = QSTRING ->
527 match instance with Some i -> i | None -> 0
529 G.Symbol_alias (symbol, instance, dsc)
531 instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
532 SYMBOL "="; dsc = QSTRING ->
534 match instance with Some i -> i | None -> 0
536 G.Number_alias (instance, dsc)
540 [ l = LIST0 [ SYMBOL <:unicode<eta>> (* η *); SYMBOL "." -> () ];
542 N.IdentArg (List.length l, id)
546 [ IDENT "left"; IDENT "associative" -> Gramext.LeftA
547 | IDENT "right"; IDENT "associative" -> Gramext.RightA
548 | IDENT "non"; IDENT "associative" -> Gramext.NonA
552 [ "with"; IDENT "precedence"; n = NUMBER -> int_of_string n ]
555 [ dir = OPT direction; s = QSTRING;
556 assoc = OPT associativity; prec = precedence;
559 [ blob = UNPARSED_AST ->
560 add_raw_attribute ~text:(Printf.sprintf "@{%s}" blob)
561 (CicNotationParser.parse_level2_ast lstatus
562 (Ulexing.from_utf8_string blob))
563 | blob = UNPARSED_META ->
564 add_raw_attribute ~text:(Printf.sprintf "${%s}" blob)
565 (CicNotationParser.parse_level2_meta lstatus
566 (Ulexing.from_utf8_string blob))
570 | None -> default_associativity
571 | Some assoc -> assoc
574 add_raw_attribute ~text:s
575 (CicNotationParser.parse_level1_pattern lstatus prec
576 (Ulexing.from_utf8_string s))
578 (dir, p1, assoc, prec, p2)
582 [ r = NREF -> N.NRefPattern (NReference.reference_of_string r)
583 | IMPLICIT -> N.ImplicitPattern
584 | id = IDENT -> N.VarPattern id
585 | LPAREN; terms = LIST1 SELF; RPAREN ->
589 | terms -> N.ApplPattern terms)
593 [ s = CSYMBOL; args = LIST0 argument; SYMBOL "="; t = level3_term ->
599 IDENT "include" ; path = QSTRING ->
600 loc,path,G.WithPreferences
601 | IDENT "include" ; IDENT "alias"; path = QSTRING ->
602 loc,path,G.OnlyPreferences
603 | IDENT "include'" ; path = QSTRING ->
604 loc,path,G.WithoutPreferences
607 index: [[ b = OPT SYMBOL "-" -> match b with None -> true | _ -> false ]];
610 src = OPT [ IDENT "implied" ] ->
611 match src with None -> `Provided | _ -> `Implied
614 grafite_ncommand: [ [
615 lc = lexicon_command -> lc
616 | IDENT "qed" ; i = index -> G.NQed (loc,i)
617 | IDENT "defined" ; i = index -> G.NQed (loc,i) (* FG: presentational qed for definitions *)
618 | src = source; nflavour = ntheorem_flavour; name = IDENT;
619 params = LIST0 protected_binder_vars; SYMBOL ":"; typ = term; (* FG: params added *)
620 body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
621 let typ = shift_params `Forall params typ in
622 let body = match body with
623 | Some bo -> Some (shift_params `Lambda params bo)
626 let attrs = src, nflavour, `Regular in
627 G.NObj (loc, N.Theorem (name, typ, body, attrs),true)
628 | src = source; nflavour = ntheorem_flavour; name = IDENT;
629 params = LIST0 protected_binder_vars; SYMBOL <:unicode<def>> (* ≝ *); (* FG: params added *)
631 let body = shift_params `Lambda params body in
632 let attrs = src, nflavour, `Regular in
634 N.Theorem(name, N.Implicit `JustOne, Some body, attrs),
636 | src = source; IDENT "axiom"; i = index; name = IDENT;
637 params = LIST0 protected_binder_vars; SYMBOL ":"; typ = term -> (* FG: params added *)
638 let typ = shift_params `Forall params typ in
639 let attrs = src, `Axiom, `Regular in
640 G.NObj (loc, N.Theorem (name, typ, None, attrs),i)
641 | src = source; IDENT "inductive"; spec = inductive_spec ->
642 let (params, ind_types) = spec in
643 G.NObj (loc, N.Inductive (params, ind_types, src),true)
644 | src = source; IDENT "coinductive"; spec = inductive_spec ->
645 let (params, ind_types) = spec in
646 let ind_types = (* set inductive flags to false (coinductive) *)
647 List.map (fun (name, _, term, ctors) -> (name, false, term, ctors))
650 G.NObj (loc, N.Inductive (params, ind_types, src),true)
651 | src = source; IDENT "record" ; (params,name,ty,fields) = record_spec ->
652 G.NObj (loc, N.Record (params,name,ty,fields,src),true)
653 (* FG: new syntax for inductive/coinductive definitions and statements *)
654 | src = source; IDENT "rec"; nflavour = ntheorem_flavour; defs = let_defs ->
655 nmk_rec_corec src nflavour `Inductive defs loc true
656 | src = source; IDENT "corec"; nflavour = ntheorem_flavour; defs = let_codefs ->
657 nmk_rec_corec src nflavour `CoInductive defs loc true
659 | LETCOREC ; defs = let_codefs ->
660 nmk_rec_corec `Provided `Definition `CoInductive defs loc true
661 | LETREC ; defs = let_defs ->
662 nmk_rec_corec `Provided `Definition `Inductive defs loc true
663 | IDENT "discriminator" ; indty = tactic_term -> G.NDiscriminator (loc,indty)
664 | IDENT "inverter"; name = IDENT; IDENT "for" ; indty = tactic_term ;
665 paramspec = OPT inverter_param_list ;
666 outsort = OPT [ SYMBOL ":" ; outsort = term -> outsort ] ->
667 G.NInverter (loc,name,indty,paramspec,outsort)
668 | IDENT "universe"; cyclic = OPT [ IDENT "cyclic" -> () ] ; IDENT "constraint"; u1 = tactic_term;
669 SYMBOL <:unicode<lt>> ; u2 = tactic_term ->
670 let acyclic = match cyclic with None -> true | Some () -> false in
672 | NotationPt.AttributedTerm (_, NotationPt.Sort (`NType i)) ->
673 NUri.uri_of_string ("cic:/matita/pts/Type"^i^".univ")
674 | _ -> raise (Failure "only a Type[…] sort can be constrained")
678 G.NUnivConstraint (loc,acyclic,u1,u2)
679 | IDENT "unification"; IDENT "hint"; n = int; t = tactic_term ->
680 G.UnificationHint (loc, t, n)
681 | IDENT "coercion"; name = IDENT;
682 compose = OPT [ IDENT "nocomposites" -> () ];
683 spec = OPT [ SYMBOL ":"; ty = term;
684 SYMBOL <:unicode<def>>; t = term; "on";
685 id = [ IDENT | PIDENT ]; SYMBOL ":"; source = term;
686 "to"; target = term -> t,ty,(id,source),target ] ->
687 let compose = compose = None in
688 G.NCoercion(loc,name,compose,spec)
689 | IDENT "copy" ; s = IDENT; IDENT "from"; u = URI; "with";
690 m = LIST0 [ u1 = URI; SYMBOL <:unicode<mapsto>>; u2 = URI -> u1,u2 ] ->
691 G.NCopy (loc,s,NUri.uri_of_string u,
692 List.map (fun a,b -> NUri.uri_of_string a, NUri.uri_of_string b) m)
696 IDENT "alias" ; spec = alias_spec ->
698 | IDENT "notation"; (dir, l1, assoc, prec, l2) = notation ->
699 G.Notation (loc, dir, l1, assoc, prec, l2)
700 | IDENT "interpretation"; id = QSTRING;
701 (symbol, args, l3) = interpretation ->
702 G.Interpretation (loc, id, (symbol, args), l3)
705 [ ncmd = grafite_ncommand; SYMBOL "." -> G.NCommand (loc, ncmd)
706 | punct = npunctuation_tactical -> G.NTactic (loc, [punct])
707 | tac = nnon_punctuation_tactical(*; punct = npunctuation_tactical*) ->
708 G.NTactic (loc, [tac])
709 | tac = ntactic (*; punct = npunctuation_tactical*) ->
712 | tac = nnon_punctuation_tactical;
713 punct = npunctuation_tactical ->
714 G.NTactic (loc, [tac; punct])
719 [ BEGINCOMMENT ; ex = executable ; ENDCOMMENT ->
726 [ ex = executable -> G.Executable (loc, ex)
727 | com = comment -> G.Comment (loc, com)
728 | (iloc,fname,mode) = include_command ; SYMBOL "." ->
729 G.Executable (loc,G.NCommand (loc,G.Include (iloc,mode,fname)))
730 | EOI -> raise End_of_file
738 type db = GrafiteAst.statement Grammar.Entry.e ;;
740 class type g_status =
742 inherit CicNotationParser.g_status
746 class virtual status =
748 inherit CicNotationParser.status ~keywords:[]
749 val mutable db = None (* mutable only to initialize it :-( *)
750 method parser_db = match db with None -> assert false | Some x -> x
751 method set_parser_db v = {< db = Some v >}
752 method set_parser_status
753 : 'status. #g_status as 'status -> 'self
754 = fun o -> {< db = Some o#parser_db >}#set_notation_parser_status o
756 let grammar = CicNotationParser.level2_ast_grammar self in
757 db <- Some (mk_parser (Grammar.Entry.create grammar "statement") self)
760 let extend status l1 action =
761 let status = CicNotationParser.extend status l1 action in
762 let grammar = CicNotationParser.level2_ast_grammar status in
764 (mk_parser (Grammar.Entry.create grammar "statement") status)
768 let parse_statement status =
769 parse_statement status#parser_db
771 (* vim:set foldmethod=marker: *)