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 * N.term option
85 | BYC_letsuchthat of string * N.term * string * N.term
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;
97 constructor: [ [ name = IDENT; SYMBOL ":"; typ = term -> (name, typ) ] ];
98 tactic_term: [ [ t = term LEVEL "90" -> t ] ];
99 ident_list1: [ [ LPAREN; idents = LIST1 IDENT; RPAREN -> idents ] ];
101 [ IDENT "normalize" ; delta = OPT [ IDENT "nodelta" -> () ] ->
102 let delta = match delta with None -> true | _ -> false in
104 | IDENT "whd" ; delta = OPT [ IDENT "nodelta" -> () ] ->
105 let delta = match delta with None -> true | _ -> false in
108 sequent_pattern_spec: [
112 path = OPT [SYMBOL ":" ; path = tactic_term -> path ] ->
113 (id,match path with Some p -> p | None -> N.UserInput) ];
114 goal_path = OPT [ SYMBOL <:unicode<vdash>>; term = tactic_term -> term ] ->
116 match goal_path, hyp_paths with
117 None, [] -> Some N.UserInput
119 | Some goal_path, _ -> Some goal_path
128 [ "match" ; wanted = tactic_term ;
129 sps = OPT [ "in"; sps = sequent_pattern_spec -> sps ] ->
131 | sps = sequent_pattern_spec ->
135 let wanted,hyp_paths,goal_path =
136 match wanted_and_sps with
137 wanted,None -> wanted, [], Some N.UserInput
138 | wanted,Some (hyp_paths,goal_path) -> wanted,hyp_paths,goal_path
140 wanted, hyp_paths, goal_path ] ->
142 None -> None,[],Some N.UserInput
145 inverter_param_list: [
146 [ params = tactic_term ->
147 let deannotate = function
148 | N.AttributedTerm (_,t) | t -> t
149 in match deannotate params with
150 | N.Implicit _ -> [false]
151 | N.UserInput -> [true]
153 List.map (fun x -> match deannotate x with
154 | N.Implicit _ -> false
155 | N.UserInput -> true
156 | _ -> raise (Invalid_argument "malformed target parameter list 1")) l
158 (*CSC: new NCicPp.status is the best I can do here without changing the
160 raise (Invalid_argument ("malformed target parameter list 2\n" ^ NotationPp.pp_term (new NCicPp.status) params)) ]
163 [ SYMBOL ">" -> `LeftToRight
164 | SYMBOL "<" -> `RightToLeft ]
166 int: [ [ num = NUMBER -> int_of_string num ] ];
168 [ SYMBOL "@"; t = tactic_term -> G.NTactic(loc,[G.NApply (loc, t)])
169 | IDENT "applyS"; t = tactic_term -> G.NTactic(loc,[G.NSmartApply(loc, t)])
173 [ id = IDENT ; SYMBOL ":" ; ty = tactic_term -> id,`Decl ty
174 | id = IDENT ; SYMBOL ":" ; ty = tactic_term ;
175 SYMBOL <:unicode<def>> ; bo = tactic_term ->
177 SYMBOL <:unicode<vdash>>;
178 concl = tactic_term -> (List.rev hyps,concl) ] ->
179 G.NTactic(loc,[G.NAssert (loc, seqs)])
180 | SYMBOL "/"; num = OPT NUMBER ;
181 just_and_params = auto_params; SYMBOL "/" ->
182 let just,params = just_and_params in
183 let depth = match num with Some n -> n | None -> "1" in
187 [G.NAuto(loc,(None,["depth",depth]@params))])
188 | Some (`Univ univ) ->
190 [G.NAuto(loc,(Some univ,["depth",depth]@params))])
193 G.NAutoInteractive (loc, (None,["depth",depth]@params))))
194 | SYMBOL "#"; SYMBOL "#" -> G.NMacro (loc, G.NIntroGuess loc)
195 | IDENT "check"; t = tactic_term -> G.NMacro(loc,G.NCheck (loc,t))
196 | IDENT "screenshot"; fname = QSTRING ->
197 G.NMacro(loc,G.Screenshot (loc, fname))
198 | IDENT "cases"; what = tactic_term ; where = pattern_spec ->
199 G.NTactic(loc,[G.NCases (loc, what, where)])
200 | IDENT "change"; "with"; with_what = tactic_term; what = pattern_spec ->
201 G.NTactic(loc,[G.NChange (loc, what, with_what)])
202 | SYMBOL "-"; id = IDENT ->
203 G.NTactic(loc,[G.NClear (loc, [id])])
204 | PLACEHOLDER; num = OPT NUMBER;
205 l = OPT [ SYMBOL "{"; l = LIST1 tactic_term; SYMBOL "}" -> l ] ->
206 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)])
207 | IDENT "cut"; t = tactic_term -> G.NTactic(loc,[G.NCut (loc, t)])
208 | IDENT "destruct"; just = OPT [ dom = ident_list1 -> dom ];
209 exclude = OPT [ IDENT "skip"; skip = ident_list1 -> skip ]
210 -> let exclude' = match exclude with None -> [] | Some l -> l in
211 G.NTactic(loc,[G.NDestruct (loc,just,exclude')])
212 | IDENT "elim"; what = tactic_term ; where = pattern_spec ->
213 G.NTactic(loc,[G.NElim (loc, what, where)])
214 | IDENT "generalize"; p=pattern_spec ->
215 G.NTactic(loc,[G.NGeneralize (loc, p)])
216 | IDENT "inversion"; what = tactic_term ; where = pattern_spec ->
217 G.NTactic(loc,[G.NInversion (loc, what, where)])
218 | IDENT "lapply"; t = tactic_term -> G.NTactic(loc,[G.NLApply (loc, t)])
219 | IDENT "letin"; name = IDENT ; SYMBOL <:unicode<def>> ; t = tactic_term;
220 where = pattern_spec ->
221 G.NTactic(loc,[G.NLetIn (loc,where,t,name)])
222 | kind = nreduction_kind; p = pattern_spec ->
223 G.NTactic(loc,[G.NReduce (loc, kind, p)])
224 | dir = direction; what = tactic_term ; where = pattern_spec ->
225 G.NTactic(loc,[G.NRewrite (loc, dir, what, where)])
226 | IDENT "try"; tac = SELF ->
227 let tac = match tac with G.NTactic(_,[t]) -> t | _ -> assert false in
228 G.NTactic(loc,[ G.NTry (loc,tac)])
229 | IDENT "repeat"; tac = SELF ->
230 let tac = match tac with G.NTactic(_,[t]) -> t | _ -> assert false in
231 G.NTactic(loc,[ G.NRepeat (loc,tac)])
232 | LPAREN; l = LIST1 SELF; RPAREN ->
235 (List.map (function G.NTactic(_,t) -> t | _ -> assert false) l) in
236 G.NTactic(loc,[G.NBlock (loc,l)])
237 | IDENT "assumption" -> G.NTactic(loc,[ G.NAssumption loc])
238 | SYMBOL "#"; ns=IDENT -> G.NTactic(loc,[ G.NIntros (loc,[ns])])
239 | SYMBOL "#"; SYMBOL "_" -> G.NTactic(loc,[ G.NIntro (loc,"_")])
240 | SYMBOL "*" -> G.NTactic(loc,[ G.NCase1 (loc,"_")])
241 | SYMBOL "*"; "as"; n=IDENT -> G.NTactic(loc,[ G.NCase1 (loc,n)])
242 | IDENT "assume"; id = IDENT; SYMBOL ":"; t = tactic_term -> G.NTactic (loc,[G.Assume (loc,id,t)])
247 | IDENT "fast_paramod"
252 (* | IDENT "timeout" *)
258 i = auto_fixed_param -> i,""
259 | i = auto_fixed_param ; SYMBOL "="; v = [ v = int ->
260 string_of_int v | v = IDENT -> v ] -> i,v ];
261 just = OPT [ IDENT "by"; by =
262 [ univ = LIST0 tactic_term SEP SYMBOL "," -> `Univ univ
263 | SYMBOL "_" -> `Trace ] -> by ] -> just,params
269 [ WEPROVED; ty = tactic_term ; LPAREN ; id = IDENT ; RPAREN ; t1 = OPT [IDENT "that" ; IDENT "is" ; IDENT "equivalent" ; "to" ; t2 = tactic_term -> t2] -> BYC_weproved (ty,Some id,t1)
270 | WEPROVED; ty = tactic_term ; t1 = OPT [IDENT "that" ; IDENT "is" ; IDENT "equivalent" ; "to" ; t2 = tactic_term -> t2] ;
271 "done" -> BYC_weproved (ty,None,t1)
273 | "let" ; id1 = IDENT ; SYMBOL ":" ; t1 = tactic_term ;
274 IDENT "such" ; IDENT "that" ; t2=tactic_term ; LPAREN ;
275 id2 = IDENT ; RPAREN -> BYC_letsuchthat (id1,t1,id2,t2)
276 | WEHAVE; t1=tactic_term ; LPAREN ; id1=IDENT ; RPAREN ;"and" ; t2=tactic_term ; LPAREN ; id2=IDENT ; RPAREN ->
277 BYC_wehaveand (id1,t1,id2,t2)
282 rewriting_step_continuation : [
291 [ t1 = SELF; SYMBOL ";"; t2 = SELF ->
294 | G.Seq (_, l) -> l @ [ t2 ]
300 [ tac = SELF; SYMBOL ";";
301 SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
302 (G.Then (loc, tac, tacs))
305 [ IDENT "do"; count = int; tac = SELF ->
306 G.Do (loc, count, tac)
307 | IDENT "repeat"; tac = SELF -> G.Repeat (loc, tac)
311 SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
313 | IDENT "try"; tac = SELF -> G.Try (loc, tac)
315 SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
317 | IDENT "progress"; tac = SELF -> G.Progress (loc, tac)
318 | LPAREN; tac = SELF; RPAREN -> tac
319 | tac = tactic -> tac
323 npunctuation_tactical:
325 [ SYMBOL "[" -> G.NBranch loc
326 | SYMBOL "|" -> G.NShift loc
327 | i = LIST1 int SEP SYMBOL ","; SYMBOL ":" -> G.NPos (loc, i)
328 | SYMBOL "*"; SYMBOL ":" -> G.NWildcard loc
329 | name = IDENT; SYMBOL ":" -> G.NPosbyname (loc, name)
330 | SYMBOL "]" -> G.NMerge loc
331 | SYMBOL ";" -> G.NSemicolon loc
332 | SYMBOL "." -> G.NDot loc
335 nnon_punctuation_tactical:
337 [ IDENT "focus"; goals = LIST1 int -> G.NFocus (loc, goals)
338 | IDENT "unfocus" -> G.NUnfocus loc
339 | IDENT "skip" -> G.NSkip loc
343 [ [ IDENT "definition" ] -> `Definition
344 | [ IDENT "fact" ] -> `Fact
345 | [ IDENT "lemma" ] -> `Lemma
346 | [ IDENT "example" ] -> `Example
347 | [ IDENT "theorem" ] -> `Theorem
348 | [ IDENT "corollary" ] -> `Corollary
353 params = LIST0 protected_binder_vars;
354 SYMBOL ":"; fst_typ = term; SYMBOL <:unicode<def>>; OPT SYMBOL "|";
355 fst_constructors = LIST0 constructor SEP SYMBOL "|";
358 name = IDENT; SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>;
359 OPT SYMBOL "|"; constructors = LIST0 constructor SEP SYMBOL "|" ->
360 (name, true, typ, constructors) ] SEP "with" -> types
364 (fun (names, typ) acc ->
365 (List.map (fun name -> (name, typ)) names) @ acc)
368 let fst_ind_type = (fst_name, true, fst_typ, fst_constructors) in
369 let tl_ind_types = match tl with None -> [] | Some types -> types in
370 let ind_types = fst_ind_type :: tl_ind_types in
376 params = LIST0 protected_binder_vars;
377 SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>; SYMBOL "{" ;
381 SYMBOL ":" -> false,0
382 | SYMBOL ":"; SYMBOL ">" -> true,0
383 | SYMBOL ":"; arity = int ; SYMBOL ">" -> true,arity
386 let b,n = coercion in
388 ] SEP SYMBOL ";"; SYMBOL "}" ->
391 (fun (names, typ) acc ->
392 (List.map (fun name -> (name, typ)) names) @ acc)
395 (params,name,typ,fields)
399 [ IDENT "id"; id = QSTRING; SYMBOL "="; uri = QSTRING ->
400 let alpha = "[a-zA-Z]" in
401 let num = "[0-9]+" in
402 let ident_cont = "\\("^alpha^"\\|"^num^"\\|_\\|\\\\\\)" in
403 let decoration = "\\'" in
404 let ident = "\\("^alpha^ident_cont^"*"^decoration^"*\\|_"^ident_cont^"+"^decoration^"*\\)" in
405 let rex = Str.regexp ("^"^ident^"$") in
406 if Str.string_match rex id 0 then
407 if (try ignore (NReference.reference_of_string uri); true
408 with NReference.IllFormedReference _ -> false)
410 G.Ident_alias (id, uri)
413 (HExtlib.Localized (loc, CicNotationParser.Parse_error (Printf.sprintf "Not a valid uri: %s" uri)))
415 raise (HExtlib.Localized (loc, CicNotationParser.Parse_error (
416 Printf.sprintf "Not a valid identifier: %s" id)))
417 | IDENT "symbol"; symbol = QSTRING;
418 instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
419 SYMBOL "="; dsc = QSTRING ->
421 match instance with Some i -> i | None -> 0
423 G.Symbol_alias (symbol, instance, dsc)
425 instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
426 SYMBOL "="; dsc = QSTRING ->
428 match instance with Some i -> i | None -> 0
430 G.Number_alias (instance, dsc)
434 [ l = LIST0 [ SYMBOL <:unicode<eta>> (* η *); SYMBOL "." -> () ];
436 N.IdentArg (List.length l, id)
440 [ IDENT "left"; IDENT "associative" -> Gramext.LeftA
441 | IDENT "right"; IDENT "associative" -> Gramext.RightA
442 | IDENT "non"; IDENT "associative" -> Gramext.NonA
446 [ "with"; IDENT "precedence"; n = NUMBER -> int_of_string n ]
449 [ dir = OPT direction; s = QSTRING;
450 assoc = OPT associativity; prec = precedence;
453 [ blob = UNPARSED_AST ->
454 add_raw_attribute ~text:(Printf.sprintf "@{%s}" blob)
455 (CicNotationParser.parse_level2_ast lstatus
456 (Ulexing.from_utf8_string blob))
457 | blob = UNPARSED_META ->
458 add_raw_attribute ~text:(Printf.sprintf "${%s}" blob)
459 (CicNotationParser.parse_level2_meta lstatus
460 (Ulexing.from_utf8_string blob))
464 | None -> default_associativity
465 | Some assoc -> assoc
468 add_raw_attribute ~text:s
469 (CicNotationParser.parse_level1_pattern lstatus prec
470 (Ulexing.from_utf8_string s))
472 (dir, p1, assoc, prec, p2)
476 [ r = NREF -> N.NRefPattern (NReference.reference_of_string r)
477 | IMPLICIT -> N.ImplicitPattern
478 | id = IDENT -> N.VarPattern id
479 | LPAREN; terms = LIST1 SELF; RPAREN ->
483 | terms -> N.ApplPattern terms)
487 [ s = CSYMBOL; args = LIST0 argument; SYMBOL "="; t = level3_term ->
493 IDENT "include" ; path = QSTRING ->
494 loc,path,G.WithPreferences
495 | IDENT "include" ; IDENT "alias"; path = QSTRING ->
496 loc,path,G.OnlyPreferences
497 | IDENT "include'" ; path = QSTRING ->
498 loc,path,G.WithoutPreferences
501 index: [[ b = OPT SYMBOL "-" -> match b with None -> true | _ -> false ]];
504 src = OPT [ IDENT "implied" ] ->
505 match src with None -> `Provided | _ -> `Implied
508 grafite_ncommand: [ [
509 lc = lexicon_command -> lc
510 | IDENT "qed" ; i = index -> G.NQed (loc,i)
511 | IDENT "defined" ; i = index -> G.NQed (loc,i) (* FG: presentational qed for definitions *)
512 | src = source; nflavour = ntheorem_flavour; name = IDENT;
513 params = LIST0 protected_binder_vars; SYMBOL ":"; typ = term; (* FG: params added *)
514 body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
515 let typ = shift_params `Forall params typ in
516 let body = match body with
517 | Some bo -> Some (shift_params `Lambda params bo)
520 let attrs = src, nflavour, `Regular in
521 G.NObj (loc, N.Theorem (name, typ, body, attrs),true)
522 | src = source; nflavour = ntheorem_flavour; name = IDENT;
523 params = LIST0 protected_binder_vars; SYMBOL <:unicode<def>> (* ≝ *); (* FG: params added *)
525 let body = shift_params `Lambda params body in
526 let attrs = src, nflavour, `Regular in
528 N.Theorem(name, N.Implicit `JustOne, Some body, attrs),
530 | src = source; IDENT "axiom"; i = index; name = IDENT;
531 params = LIST0 protected_binder_vars; SYMBOL ":"; typ = term -> (* FG: params added *)
532 let typ = shift_params `Forall params typ in
533 let attrs = src, `Axiom, `Regular in
534 G.NObj (loc, N.Theorem (name, typ, None, attrs),i)
535 | src = source; IDENT "inductive"; spec = inductive_spec ->
536 let (params, ind_types) = spec in
537 G.NObj (loc, N.Inductive (params, ind_types, src),true)
538 | src = source; IDENT "coinductive"; spec = inductive_spec ->
539 let (params, ind_types) = spec in
540 let ind_types = (* set inductive flags to false (coinductive) *)
541 List.map (fun (name, _, term, ctors) -> (name, false, term, ctors))
544 G.NObj (loc, N.Inductive (params, ind_types, src),true)
545 | src = source; IDENT "record" ; (params,name,ty,fields) = record_spec ->
546 G.NObj (loc, N.Record (params,name,ty,fields,src),true)
547 (* FG: new syntax for inductive/coinductive definitions and statements *)
548 | src = source; IDENT "rec"; nflavour = ntheorem_flavour; defs = let_defs ->
549 nmk_rec_corec src nflavour `Inductive defs loc true
550 | src = source; IDENT "corec"; nflavour = ntheorem_flavour; defs = let_codefs ->
551 nmk_rec_corec src nflavour `CoInductive defs loc true
553 | LETCOREC ; defs = let_codefs ->
554 nmk_rec_corec `Provided `Definition `CoInductive defs loc true
555 | LETREC ; defs = let_defs ->
556 nmk_rec_corec `Provided `Definition `Inductive defs loc true
557 | IDENT "discriminator" ; indty = tactic_term -> G.NDiscriminator (loc,indty)
558 | IDENT "inverter"; name = IDENT; IDENT "for" ; indty = tactic_term ;
559 paramspec = OPT inverter_param_list ;
560 outsort = OPT [ SYMBOL ":" ; outsort = term -> outsort ] ->
561 G.NInverter (loc,name,indty,paramspec,outsort)
562 | IDENT "universe"; cyclic = OPT [ IDENT "cyclic" -> () ] ; IDENT "constraint"; u1 = tactic_term;
563 SYMBOL <:unicode<lt>> ; u2 = tactic_term ->
564 let acyclic = match cyclic with None -> true | Some () -> false in
566 | NotationPt.AttributedTerm (_, NotationPt.Sort (`NType i)) ->
567 NUri.uri_of_string ("cic:/matita/pts/Type"^i^".univ")
568 | _ -> raise (Failure "only a Type[…] sort can be constrained")
572 G.NUnivConstraint (loc,acyclic,u1,u2)
573 | IDENT "unification"; IDENT "hint"; n = int; t = tactic_term ->
574 G.UnificationHint (loc, t, n)
575 | IDENT "coercion"; name = IDENT;
576 compose = OPT [ IDENT "nocomposites" -> () ];
577 spec = OPT [ SYMBOL ":"; ty = term;
578 SYMBOL <:unicode<def>>; t = term; "on";
579 id = [ IDENT | PIDENT ]; SYMBOL ":"; source = term;
580 "to"; target = term -> t,ty,(id,source),target ] ->
581 let compose = compose = None in
582 G.NCoercion(loc,name,compose,spec)
583 | IDENT "copy" ; s = IDENT; IDENT "from"; u = URI; "with";
584 m = LIST0 [ u1 = URI; SYMBOL <:unicode<mapsto>>; u2 = URI -> u1,u2 ] ->
585 G.NCopy (loc,s,NUri.uri_of_string u,
586 List.map (fun a,b -> NUri.uri_of_string a, NUri.uri_of_string b) m)
590 IDENT "alias" ; spec = alias_spec ->
592 | IDENT "notation"; (dir, l1, assoc, prec, l2) = notation ->
593 G.Notation (loc, dir, l1, assoc, prec, l2)
594 | IDENT "interpretation"; id = QSTRING;
595 (symbol, args, l3) = interpretation ->
596 G.Interpretation (loc, id, (symbol, args), l3)
599 [ ncmd = grafite_ncommand; SYMBOL "." -> G.NCommand (loc, ncmd)
600 | punct = npunctuation_tactical -> G.NTactic (loc, [punct])
601 | tac = nnon_punctuation_tactical(*; punct = npunctuation_tactical*) ->
602 G.NTactic (loc, [tac])
603 | tac = ntactic (*; punct = npunctuation_tactical*) ->
606 | tac = nnon_punctuation_tactical;
607 punct = npunctuation_tactical ->
608 G.NTactic (loc, [tac; punct])
613 [ BEGINCOMMENT ; ex = executable ; ENDCOMMENT ->
620 [ ex = executable -> G.Executable (loc, ex)
621 | com = comment -> G.Comment (loc, com)
622 | (iloc,fname,mode) = include_command ; SYMBOL "." ->
623 G.Executable (loc,G.NCommand (loc,G.Include (iloc,mode,fname)))
624 | EOI -> raise End_of_file
632 type db = GrafiteAst.statement Grammar.Entry.e ;;
634 class type g_status =
636 inherit CicNotationParser.g_status
640 class virtual status =
642 inherit CicNotationParser.status ~keywords:[]
643 val mutable db = None (* mutable only to initialize it :-( *)
644 method parser_db = match db with None -> assert false | Some x -> x
645 method set_parser_db v = {< db = Some v >}
646 method set_parser_status
647 : 'status. #g_status as 'status -> 'self
648 = fun o -> {< db = Some o#parser_db >}#set_notation_parser_status o
650 let grammar = CicNotationParser.level2_ast_grammar self in
651 db <- Some (mk_parser (Grammar.Entry.create grammar "statement") self)
654 let extend status l1 action =
655 let status = CicNotationParser.extend status l1 action in
656 let grammar = CicNotationParser.level2_ast_grammar status in
658 (mk_parser (Grammar.Entry.create grammar "statement") status)
662 let parse_statement status =
663 parse_statement status#parser_db
665 (* vim:set foldmethod=marker: *)