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/
31 module LE = LexiconEngine
33 exception NoInclusionPerformed of string (* full path *)
35 type 'a localized_option =
39 type ast_statement = G.statement
41 type 'status statement =
42 ?never_include:bool ->
43 (* do not call LexiconEngine to do includes, always raise NoInclusionPerformed *)
44 include_paths:string list -> (#LE.status as 'status) ->
45 'status * ast_statement localized_option
47 type 'status parser_status = {
49 term : N.term Grammar.Entry.e;
50 statement : #LE.status as 'status statement Grammar.Entry.e;
53 let grafite_callback = ref (fun _ -> ())
54 let set_grafite_callback cb = grafite_callback := cb
56 let lexicon_callback = ref (fun _ -> ())
57 let set_lexicon_callback cb = lexicon_callback := cb
59 let initial_parser () =
60 let grammar = CicNotationParser.level2_ast_grammar () in
61 let term = CicNotationParser.term () in
62 let statement = Grammar.Entry.create grammar "statement" in
63 { grammar = grammar; term = term; statement = statement }
66 let grafite_parser = ref (initial_parser ())
68 let add_raw_attribute ~text t = N.AttributedTerm (`Raw text, t)
70 let default_associativity = Gramext.NonA
72 let mk_rec_corec ind_kind defs loc =
75 | (params,(N.Ident (name, None), ty),_,_) :: _ ->
76 let ty = match ty with Some ty -> ty | None -> N.Implicit `JustOne in
79 (fun var ty -> N.Binder (`Pi,var,ty)
85 let body = N.Ident (name,None) in
86 (loc, N.Theorem(`Definition, name, ty, Some (N.LetRec (ind_kind, defs, body)), `Regular))
88 let nmk_rec_corec ind_kind defs loc =
89 let loc,t = mk_rec_corec ind_kind defs loc in
93 let nnon_punct_of_punct = function
94 | G.Skip loc -> G.NSkip loc
95 | G.Unfocus loc -> G.NUnfocus loc
96 | G.Focus (loc,l) -> G.NFocus (loc,l)
99 type by_continuation =
101 | BYC_weproved of N.term * string option * N.term option
102 | BYC_letsuchthat of string * N.term * string * N.term
103 | BYC_wehaveand of string * N.term * string * N.term
105 let initialize_parser () =
106 (* {{{ parser initialization *)
107 let term = !grafite_parser.term in
108 let statement = !grafite_parser.statement in
109 let let_defs = CicNotationParser.let_defs () in
110 let protected_binder_vars = CicNotationParser.protected_binder_vars () in
112 GLOBAL: term statement;
113 constructor: [ [ name = IDENT; SYMBOL ":"; typ = term -> (name, typ) ] ];
114 tactic_term: [ [ t = term LEVEL "90" -> t ] ];
117 | id = IDENT -> Some id ]
119 ident_list0: [ [ LPAREN; idents = LIST0 new_name; RPAREN -> idents ] ];
120 ident_list1: [ [ LPAREN; idents = LIST1 IDENT; RPAREN -> idents ] ];
122 [ tactic_terms = LIST1 tactic_term SEP SYMBOL "," -> tactic_terms ]
125 [ IDENT "normalize" -> `Normalize
126 | IDENT "simplify" -> `Simpl
127 | IDENT "unfold"; t = OPT tactic_term -> `Unfold t
128 | IDENT "whd" -> `Whd ]
131 [ IDENT "normalize" ; delta = OPT [ IDENT "nodelta" -> () ] ->
132 let delta = match delta with None -> true | _ -> false in
134 (*| IDENT "unfold"; t = OPT tactic_term -> `Unfold t*)
135 | IDENT "whd" ; delta = OPT [ IDENT "nodelta" -> () ] ->
136 let delta = match delta with None -> true | _ -> false in
139 sequent_pattern_spec: [
143 path = OPT [SYMBOL ":" ; path = tactic_term -> path ] ->
144 (id,match path with Some p -> p | None -> N.UserInput) ];
145 goal_path = OPT [ SYMBOL <:unicode<vdash>>; term = tactic_term -> term ] ->
147 match goal_path, hyp_paths with
148 None, [] -> Some N.UserInput
150 | Some goal_path, _ -> Some goal_path
159 [ "match" ; wanted = tactic_term ;
160 sps = OPT [ "in"; sps = sequent_pattern_spec -> sps ] ->
162 | sps = sequent_pattern_spec ->
165 let wanted,hyp_paths,goal_path =
166 match wanted_and_sps with
167 wanted,None -> wanted, [], Some N.UserInput
168 | wanted,Some (hyp_paths,goal_path) -> wanted,hyp_paths,goal_path
170 wanted, hyp_paths, goal_path ] ->
172 None -> None,[],Some N.UserInput
175 inverter_param_list: [
176 [ params = tactic_term ->
177 let deannotate = function
178 | N.AttributedTerm (_,t) | t -> t
179 in match deannotate params with
180 | N.Implicit _ -> [false]
181 | N.UserInput -> [true]
183 List.map (fun x -> match deannotate x with
184 | N.Implicit _ -> false
185 | N.UserInput -> true
186 | _ -> raise (Invalid_argument "malformed target parameter list 1")) l
187 | _ -> raise (Invalid_argument ("malformed target parameter list 2\n" ^ NotationPp.pp_term params)) ]
190 [ SYMBOL ">" -> `LeftToRight
191 | SYMBOL "<" -> `RightToLeft ]
193 int: [ [ num = NUMBER -> int_of_string num ] ];
195 [ idents = OPT ident_list0 ->
196 match idents with None -> [] | Some idents -> idents
200 [ OPT [ IDENT "names" ];
201 num = OPT [ num = int -> num ];
202 idents = intros_names ->
206 using: [ [ using = OPT [ IDENT "using"; t = tactic_term -> t ] -> using ] ];
208 [ SYMBOL "@"; t = tactic_term -> G.NTactic(loc,[G.NApply (loc, t)])
209 | IDENT "apply"; t = tactic_term -> G.NTactic(loc,[G.NApply (loc, t)])
210 | IDENT "applyS"; t = tactic_term -> G.NTactic(loc,[G.NSmartApply(loc, t)])
214 [ id = IDENT ; SYMBOL ":" ; ty = tactic_term -> id,`Decl ty
215 | id = IDENT ; SYMBOL ":" ; ty = tactic_term ;
216 SYMBOL <:unicode<def>> ; bo = tactic_term ->
218 SYMBOL <:unicode<vdash>>;
219 concl = tactic_term -> (List.rev hyps,concl) ] ->
220 G.NTactic(loc,[G.NAssert (loc, seqs)])
221 (*| IDENT "auto"; params = auto_params ->
222 G.NTactic(loc,[G.NAuto (loc, params)])*)
223 | SYMBOL "/"; num = OPT NUMBER ;
224 just_and_params = auto_params; SYMBOL "/" ->
225 let just,params = just_and_params in
226 let depth = match num with Some n -> n | None -> "1" in
230 [G.NAuto(loc,(None,["depth",depth]@params))])
231 | Some (`Univ univ) ->
233 [G.NAuto(loc,(Some univ,["depth",depth]@params))])
236 [G.NAuto(loc,(Some [],["depth",depth]@params))])
239 G.NAutoInteractive (loc, (None,["depth",depth]@params))))
240 | IDENT "intros" -> G.NMacro (loc, G.NIntroGuess loc)
241 | IDENT "check"; t = term -> G.NMacro(loc,G.NCheck (loc,t))
242 | IDENT "screenshot"; fname = QSTRING ->
243 G.NMacro(loc,G.Screenshot (loc, fname))
244 | IDENT "cases"; what = tactic_term ; where = pattern_spec ->
245 G.NTactic(loc,[G.NCases (loc, what, where)])
246 | IDENT "change"; what = pattern_spec; "with"; with_what = tactic_term ->
247 G.NTactic(loc,[G.NChange (loc, what, with_what)])
248 | SYMBOL "@"; num = OPT NUMBER; l = LIST0 tactic_term ->
249 G.NTactic(loc,[G.NConstructor (loc, (match num with None -> None | Some x -> Some (int_of_string x)),l)])
250 | IDENT "cut"; t = tactic_term -> G.NTactic(loc,[G.NCut (loc, t)])
251 (* | IDENT "discriminate"; t = tactic_term -> G.NDiscriminate (loc, t)
252 | IDENT "subst"; t = tactic_term -> G.NSubst (loc, t) *)
253 | IDENT "destruct"; just = OPT [ dom = ident_list1 -> dom ];
254 exclude = OPT [ IDENT "skip"; skip = ident_list1 -> skip ]
255 -> let exclude' = match exclude with None -> [] | Some l -> l in
256 G.NTactic(loc,[G.NDestruct (loc,just,exclude')])
257 | IDENT "elim"; what = tactic_term ; where = pattern_spec ->
258 G.NTactic(loc,[G.NElim (loc, what, where)])
259 | IDENT "generalize"; p=pattern_spec ->
260 G.NTactic(loc,[G.NGeneralize (loc, p)])
261 | IDENT "inversion"; what = tactic_term ; where = pattern_spec ->
262 G.NTactic(loc,[G.NInversion (loc, what, where)])
263 | IDENT "lapply"; t = tactic_term -> G.NTactic(loc,[G.NLApply (loc, t)])
264 | IDENT "letin"; name = IDENT ; SYMBOL <:unicode<def>> ; t = tactic_term;
265 where = pattern_spec ->
266 G.NTactic(loc,[G.NLetIn (loc,where,t,name)])
267 | kind = nreduction_kind; p = pattern_spec ->
268 G.NTactic(loc,[G.NReduce (loc, kind, p)])
269 | dir = direction; what = tactic_term ; where = pattern_spec ->
270 G.NTactic(loc,[G.NRewrite (loc, dir, what, where)])
271 | IDENT "rewrite"; dir = direction; what = tactic_term ; where = pattern_spec ->
272 G.NTactic(loc,[G.NRewrite (loc, dir, what, where)])
273 | IDENT "try"; tac = SELF ->
274 let tac = match tac with G.NTactic(_,[t]) -> t | _ -> assert false in
275 G.NTactic(loc,[ G.NTry (loc,tac)])
276 | IDENT "repeat"; tac = SELF ->
277 let tac = match tac with G.NTactic(_,[t]) -> t | _ -> assert false in
278 G.NTactic(loc,[ G.NRepeat (loc,tac)])
279 | LPAREN; l = LIST1 SELF; RPAREN ->
282 (List.map (function G.NTactic(_,t) -> t | _ -> assert false) l) in
283 G.NTactic(loc,[G.NBlock (loc,l)])
284 | IDENT "assumption" -> G.NTactic(loc,[ G.NAssumption loc])
285 | SYMBOL "#"; ns=IDENT -> G.NTactic(loc,[ G.NIntros (loc,[ns])])
286 | SYMBOL "#"; SYMBOL "_" -> G.NTactic(loc,[ G.NIntro (loc,"_")])
287 | SYMBOL "*" -> G.NTactic(loc,[ G.NCase1 (loc,"_")])
288 | SYMBOL "*"; n=IDENT -> G.NTactic(loc,[ G.NCase1 (loc,n)])
293 | IDENT "fast_paramod"
307 i = auto_fixed_param -> i,""
308 | i = auto_fixed_param ; SYMBOL "="; v = [ v = int ->
309 string_of_int v | v = IDENT -> v ] -> i,v ];
310 just = OPT [ IDENT "by"; by =
311 [ univ = tactic_term_list1 -> `Univ univ
312 | SYMBOL "{"; SYMBOL "}" -> `EmptyUniv
313 | SYMBOL "_" -> `Trace ] -> by ] -> just,params
318 [ 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)
319 | WEPROVED; ty = tactic_term ; t1 = OPT [IDENT "that" ; IDENT "is" ; IDENT "equivalent" ; "to" ; t2 = tactic_term -> t2] ;
320 "done" -> BYC_weproved (ty,None,t1)
322 | "let" ; id1 = IDENT ; SYMBOL ":" ; t1 = tactic_term ;
323 IDENT "such" ; IDENT "that" ; t2=tactic_term ; LPAREN ;
324 id2 = IDENT ; RPAREN -> BYC_letsuchthat (id1,t1,id2,t2)
325 | WEHAVE; t1=tactic_term ; LPAREN ; id1=IDENT ; RPAREN ;"and" ; t2=tactic_term ; LPAREN ; id2=IDENT ; RPAREN ->
326 BYC_wehaveand (id1,t1,id2,t2)
329 rewriting_step_continuation : [
337 [ t1 = SELF; SYMBOL ";"; t2 = SELF ->
340 | G.Seq (_, l) -> l @ [ t2 ]
346 [ tac = SELF; SYMBOL ";";
347 SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
348 (G.Then (loc, tac, tacs))
351 [ IDENT "do"; count = int; tac = SELF ->
352 G.Do (loc, count, tac)
353 | IDENT "repeat"; tac = SELF -> G.Repeat (loc, tac)
357 SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
359 | IDENT "try"; tac = SELF -> G.Try (loc, tac)
361 SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
363 | IDENT "progress"; tac = SELF -> G.Progress (loc, tac)
364 | LPAREN; tac = SELF; RPAREN -> tac
365 | tac = tactic -> tac
369 npunctuation_tactical:
371 [ SYMBOL "[" -> G.NBranch loc
372 | SYMBOL "|" -> G.NShift loc
373 | i = LIST1 int SEP SYMBOL ","; SYMBOL ":" -> G.NPos (loc, i)
374 | SYMBOL "*"; SYMBOL ":" -> G.NWildcard loc
375 | name = IDENT; SYMBOL ":" -> G.NPosbyname (loc, name)
376 | SYMBOL "]" -> G.NMerge loc
377 | SYMBOL ";" -> G.NSemicolon loc
378 | SYMBOL "." -> G.NDot loc
381 nnon_punctuation_tactical:
383 [ IDENT "focus"; goals = LIST1 int -> G.NFocus (loc, goals)
384 | IDENT "unfocus" -> G.NUnfocus loc
385 | IDENT "skip" -> G.NSkip loc
389 [ [ IDENT "definition" ] -> `Definition
390 | [ IDENT "fact" ] -> `Fact
391 | [ IDENT "lemma" ] -> `Lemma
392 | [ IDENT "example" ] -> `Example
393 | [ IDENT "theorem" ] -> `Theorem
394 | [ IDENT "corollary" ] -> `Corollary
399 params = LIST0 protected_binder_vars;
400 SYMBOL ":"; fst_typ = term; SYMBOL <:unicode<def>>; OPT SYMBOL "|";
401 fst_constructors = LIST0 constructor SEP SYMBOL "|";
404 name = IDENT; SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>;
405 OPT SYMBOL "|"; constructors = LIST0 constructor SEP SYMBOL "|" ->
406 (name, true, typ, constructors) ] SEP "with" -> types
410 (fun (names, typ) acc ->
411 (List.map (fun name -> (name, typ)) names) @ acc)
414 let fst_ind_type = (fst_name, true, fst_typ, fst_constructors) in
415 let tl_ind_types = match tl with None -> [] | Some types -> types in
416 let ind_types = fst_ind_type :: tl_ind_types in
422 params = LIST0 protected_binder_vars;
423 SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>; SYMBOL "{" ;
427 SYMBOL ":" -> false,0
428 | SYMBOL ":"; SYMBOL ">" -> true,0
429 | SYMBOL ":"; arity = int ; SYMBOL ">" -> true,arity
432 let b,n = coercion in
434 ] SEP SYMBOL ";"; SYMBOL "}" ->
437 (fun (names, typ) acc ->
438 (List.map (fun name -> (name, typ)) names) @ acc)
441 (params,name,typ,fields)
445 [ IDENT "id"; id = QSTRING; SYMBOL "="; uri = QSTRING ->
446 let alpha = "[a-zA-Z]" in
447 let num = "[0-9]+" in
448 let ident_cont = "\\("^alpha^"\\|"^num^"\\|_\\|\\\\\\)" in
449 let decoration = "\\'" in
450 let ident = "\\("^alpha^ident_cont^"*"^decoration^"*\\|_"^ident_cont^"+"^decoration^"*\\)" in
451 let rex = Str.regexp ("^"^ident^"$") in
452 if Str.string_match rex id 0 then
453 if (try ignore (NReference.reference_of_string uri); true
454 with NReference.IllFormedReference _ -> false)
456 L.Ident_alias (id, uri)
459 (HExtlib.Localized (loc, CicNotationParser.Parse_error (Printf.sprintf "Not a valid uri: %s" uri)))
461 raise (HExtlib.Localized (loc, CicNotationParser.Parse_error (
462 Printf.sprintf "Not a valid identifier: %s" id)))
463 | IDENT "symbol"; symbol = QSTRING;
464 instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
465 SYMBOL "="; dsc = QSTRING ->
467 match instance with Some i -> i | None -> 0
469 L.Symbol_alias (symbol, instance, dsc)
471 instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
472 SYMBOL "="; dsc = QSTRING ->
474 match instance with Some i -> i | None -> 0
476 L.Number_alias (instance, dsc)
480 [ l = LIST0 [ SYMBOL <:unicode<eta>> (* η *); SYMBOL "." -> () ];
482 N.IdentArg (List.length l, id)
486 [ IDENT "left"; IDENT "associative" -> Gramext.LeftA
487 | IDENT "right"; IDENT "associative" -> Gramext.RightA
488 | IDENT "non"; IDENT "associative" -> Gramext.NonA
492 [ "with"; IDENT "precedence"; n = NUMBER -> int_of_string n ]
495 [ dir = OPT direction; s = QSTRING;
496 assoc = OPT associativity; prec = precedence;
499 [ blob = UNPARSED_AST ->
500 add_raw_attribute ~text:(Printf.sprintf "@{%s}" blob)
501 (CicNotationParser.parse_level2_ast
502 (Ulexing.from_utf8_string blob))
503 | blob = UNPARSED_META ->
504 add_raw_attribute ~text:(Printf.sprintf "${%s}" blob)
505 (CicNotationParser.parse_level2_meta
506 (Ulexing.from_utf8_string blob))
510 | None -> default_associativity
511 | Some assoc -> assoc
514 add_raw_attribute ~text:s
515 (CicNotationParser.parse_level1_pattern prec
516 (Ulexing.from_utf8_string s))
518 (dir, p1, assoc, prec, p2)
522 [ r = NREF -> N.NRefPattern (NReference.reference_of_string r)
523 | IMPLICIT -> N.ImplicitPattern
524 | id = IDENT -> N.VarPattern id
525 | LPAREN; terms = LIST1 SELF; RPAREN ->
529 | terms -> N.ApplPattern terms)
533 [ s = CSYMBOL; args = LIST0 argument; SYMBOL "="; t = level3_term ->
539 IDENT "include" ; path = QSTRING ->
540 loc,path,true,L.WithPreferences
541 | IDENT "include" ; IDENT "source" ; path = QSTRING ->
542 loc,path,false,L.WithPreferences
543 | IDENT "include'" ; path = QSTRING ->
544 loc,path,true,L.WithoutPreferences
547 grafite_ncommand: [ [
548 IDENT "qed" -> G.NQed loc
549 | nflavour = ntheorem_flavour; name = IDENT; SYMBOL ":"; typ = term;
550 body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
551 G.NObj (loc, N.Theorem (nflavour, name, typ, body,`Regular))
552 | nflavour = ntheorem_flavour; name = IDENT; SYMBOL <:unicode<def>> (* ≝ *);
554 G.NObj (loc, N.Theorem (nflavour, name, N.Implicit `JustOne, Some body,`Regular))
555 | IDENT "axiom"; name = IDENT; SYMBOL ":"; typ = term ->
556 G.NObj (loc, N.Theorem (`Axiom, name, typ, None, `Regular))
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 | NLETCOREC ; defs = let_defs ->
563 nmk_rec_corec `CoInductive defs loc
564 | NLETREC ; defs = let_defs ->
565 nmk_rec_corec `Inductive defs loc
566 | IDENT "inductive"; spec = inductive_spec ->
567 let (params, ind_types) = spec in
568 G.NObj (loc, N.Inductive (params, ind_types))
569 | IDENT "coinductive"; spec = inductive_spec ->
570 let (params, ind_types) = spec in
571 let ind_types = (* set inductive flags to false (coinductive) *)
572 List.map (fun (name, _, term, ctors) -> (name, false, term, ctors))
575 G.NObj (loc, N.Inductive (params, ind_types))
576 | IDENT "universe"; IDENT "constraint"; u1 = tactic_term;
577 SYMBOL <:unicode<lt>> ; u2 = tactic_term ->
579 | NotationPt.AttributedTerm (_, NotationPt.Sort (`NType i)) ->
580 NUri.uri_of_string ("cic:/matita/pts/Type"^i^".univ")
581 | _ -> raise (Failure "only a Type[…] sort can be constrained")
585 G.NUnivConstraint (loc,u1,u2)
586 | IDENT "unification"; IDENT "hint"; n = int; t = tactic_term ->
587 G.UnificationHint (loc, t, n)
588 | IDENT "coercion"; name = IDENT; SYMBOL ":"; ty = term;
589 SYMBOL <:unicode<def>>; t = term; "on";
590 id = [ IDENT | PIDENT ]; SYMBOL ":"; source = term;
591 "to"; target = term ->
592 G.NCoercion(loc,name,t,ty,(id,source),target)
593 | IDENT "record" ; (params,name,ty,fields) = record_spec ->
594 G.NObj (loc, N.Record (params,name,ty,fields))
595 | IDENT "copy" ; s = IDENT; IDENT "from"; u = URI; "with";
596 m = LIST0 [ u1 = URI; SYMBOL <:unicode<mapsto>>; u2 = URI -> u1,u2 ] ->
597 G.NCopy (loc,s,NUri.uri_of_string u,
598 List.map (fun a,b -> NUri.uri_of_string a, NUri.uri_of_string b) m)
602 IDENT "alias" ; spec = alias_spec ->
604 | IDENT "notation"; (dir, l1, assoc, prec, l2) = notation ->
605 L.Notation (loc, dir, l1, assoc, prec, l2)
606 | IDENT "interpretation"; id = QSTRING;
607 (symbol, args, l3) = interpretation ->
608 L.Interpretation (loc, id, (symbol, args), l3)
611 [ ncmd = grafite_ncommand; SYMBOL "." -> G.NCommand (loc, ncmd)
612 | punct = npunctuation_tactical -> G.NTactic (loc, [punct])
613 | tac = nnon_punctuation_tactical(*; punct = npunctuation_tactical*) ->
614 G.NTactic (loc, [tac])
615 | tac = ntactic (*; punct = npunctuation_tactical*) ->
618 | tac = nnon_punctuation_tactical;
619 punct = npunctuation_tactical ->
620 G.NTactic (loc, [tac; punct])
625 [ BEGINCOMMENT ; ex = executable ; ENDCOMMENT ->
633 fun ?(never_include=false) ~include_paths status ->
634 let stm = G.Executable (loc, ex) in
635 !grafite_callback stm;
638 fun ?(never_include=false) ~include_paths status ->
639 let stm = G.Comment (loc, com) in
640 !grafite_callback stm;
642 | (iloc,fname,normal,mode) = include_command ; SYMBOL "." ->
643 fun ?(never_include=false) ~include_paths status ->
644 let _root, buri, fullpath, _rrelpath =
645 Librarian.baseuri_of_script ~include_paths fname in
646 if never_include then raise (NoInclusionPerformed fullpath)
651 (loc, G.Command (loc, G.Include (iloc,fname))) in
652 !grafite_callback stm;
654 LE.eval_command status (L.Include (iloc,buri,mode,fullpath)) in
657 (loc,G.Command (loc,G.Include (iloc,buri)))
661 | scom = lexicon_command ; SYMBOL "." ->
662 fun ?(never_include=false) ~include_paths status ->
663 !lexicon_callback scom;
664 let status = LE.eval_command status scom in
666 | EOI -> raise End_of_file
673 let _ = initialize_parser () ;;
675 let exc_located_wrapper f =
679 | Stdpp.Exc_located (_, End_of_file) -> raise End_of_file
680 | Stdpp.Exc_located (floc, Stream.Error msg) ->
681 raise (HExtlib.Localized (floc,CicNotationParser.Parse_error msg))
682 | Stdpp.Exc_located (floc, HExtlib.Localized(_,exn)) ->
684 (HExtlib.Localized (floc,CicNotationParser.Parse_error (Printexc.to_string exn)))
685 | Stdpp.Exc_located (floc, exn) ->
687 (HExtlib.Localized (floc,CicNotationParser.Parse_error (Printexc.to_string exn)))
689 let parse_statement lexbuf =
691 (fun () -> (Grammar.Entry.parse (Obj.magic !grafite_parser.statement) (Obj.magic lexbuf)))
693 let statement () = Obj.magic !grafite_parser.statement
695 let history = ref [] ;;
699 history := !grafite_parser :: !history;
700 grafite_parser := initial_parser ();
709 grafite_parser := gp;
713 (* vim:set foldmethod=marker: *)