1 (* Copyright (C) 2004, 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/
29 prerr_endline "<NEW_TEXTUAL_PARSER>";
31 prerr_endline "</NEW_TEXTUAL_PARSER>"
34 (** if set to true each number will have a different insance number and can
35 * thus be interpreted differently than others *)
36 let use_fresh_num_instances = false
38 (** does the lexer return COMMENT tokens? *)
39 let return_comments = false
43 open DisambiguateTypes
45 exception Parse_error of Token.flocation * string
47 let cic_lexer = CicTextualLexer2.cic_lexer ~comments:return_comments ()
49 let fresh_num_instance =
51 if use_fresh_num_instances then
52 (fun () -> incr n; !n)
56 let choice_of_uri suri =
57 let term = CicUtil.term_of_uri (UriManager.uri_of_string suri) in
58 (suri, (fun _ _ _ -> term))
60 let grammar = Grammar.gcreate cic_lexer
62 let term = Grammar.Entry.create grammar "term"
63 let term0 = Grammar.Entry.create grammar "term0"
64 let tactic = Grammar.Entry.create grammar "tactic"
65 let tactical = Grammar.Entry.create grammar "tactical"
66 let tactical0 = Grammar.Entry.create grammar "tactical0"
67 let command = Grammar.Entry.create grammar "command"
68 let alias_spec = Grammar.Entry.create grammar "alias_spec"
69 let macro = Grammar.Entry.create grammar "macro"
70 let script = Grammar.Entry.create grammar "script"
71 let statement = Grammar.Entry.create grammar "statement"
72 let statements = Grammar.Entry.create grammar "statements"
74 let return_term loc term = CicAst.AttributedTerm (`Loc loc, term)
77 let (x, y) = CicAst.loc_of_floc floc in
78 failwith (Printf.sprintf "Error at characters %d - %d: %s" x y msg)
80 let name_of_string = function
81 | "_" -> Cic.Anonymous
84 let string_of_name = function
85 | Cic.Anonymous -> "_"
88 let int_opt = function
90 | Some lexeme -> Some (int_of_string lexeme)
94 Pervasives.int_of_string s
96 failwith (sprintf "Lexer failure: string_of_int \"%s\" failed" s)
98 (** the uri of an inductive type (a ".ind" uri) is not meaningful without an
99 * xpointer. Still, it's likely that an user who wrote "cic:/blabla/foo.ind"
100 * actually meant "cic:/blabla/foo.ind#xpointer(1/1)", i.e. the first inductive
101 * type in a block of mutual inductive types.
103 * This function performs the expansion foo.ind -> foo#xpointer..., if needed
105 let ind_expansion uri =
106 let len = String.length uri in
107 if len >= 4 && String.sub uri (len - 4) 4 = ".ind" then
108 uri ^ "#xpointer(1/1)"
112 let mk_binder_ast binder typ vars body =
115 let name = name_of_string var in
116 CicAst.Binder (binder, (name, typ), body))
120 GLOBAL: term term0 statement statements;
125 with Failure _ -> raise (Parse_error (loc, "integer literal expected"))
129 [ s = SYMBOL "_" -> None
130 | t = term -> Some t ]
133 [ SYMBOL <:unicode<Pi>> (* Π *) -> `Pi
134 | SYMBOL <:unicode<exists>> (* ∃ *) -> `Exists
135 | SYMBOL <:unicode<forall>> (* ∀ *) -> `Forall ]
137 binder_high: [ [ SYMBOL <:unicode<lambda>> (* λ *) -> `Lambda ] ];
142 | "CProp" -> `CProp ]
145 [ PAREN "("; i = IDENT; SYMBOL ":"; typ = term; PAREN ")" ->
146 (Cic.Name i, Some typ)
147 | i = IDENT -> (Cic.Name i, None)
151 [ SYMBOL "\\subst"; (* to avoid catching frequent "a [1]" cases *)
154 i = IDENT; SYMBOL <:unicode<Assign>> (* ≔ *); t = term -> (i, t)
160 substituted_name: [ (* a subs.name is an explicit substitution subject *)
161 [ s = IDENT; subst = OPT subst -> CicAst.Ident (s, subst)
162 | s = URI; subst = OPT subst -> CicAst.Uri (ind_expansion s, subst)
165 name: [ (* as substituted_name with no explicit substitution *)
166 [ s = [ IDENT | SYMBOL ] -> s ]
169 [ n = name -> (n, [])
170 | PAREN "("; head = name; vars = LIST1 typed_name; PAREN ")" ->
175 [ PAREN "(" ; names = LIST1 IDENT SEP SYMBOL ",";
176 SYMBOL ":"; ty = term; PAREN ")" -> names,ty
177 | name = IDENT -> [name],CicAst.Implicit
183 args = LIST1 [arg = arg -> arg];
184 index_name = OPT [ "on"; idx = IDENT -> idx ];
185 ty = OPT [ SYMBOL ":" ; t = term -> t ];
186 SYMBOL <:unicode<def>> (* ≝ *);
188 let rec list_of_binder binder ty final_term = function
191 CicAst.Binder (binder, (Cic.Name name, Some ty),
192 list_of_binder binder ty final_term tl)
194 let rec binder_of_arg_list binder final_term = function
197 list_of_binder binder ty
198 (binder_of_arg_list binder final_term tl) l
200 let t1' = binder_of_arg_list `Lambda t1 args in
204 | Some ty -> Some (binder_of_arg_list `Pi ty args)
206 let rec get_position_of name n = function
212 (get_position_of name (n+1) tl)
214 let rec find_arg name n = function
215 | [] -> (fail loc (sprintf "Argument %s not found" name))
217 let (got,len) = get_position_of name 0 l in
219 | None -> (find_arg name (n+len) tl)
220 | Some where -> n + where)
223 (match index_name with
225 | (Some name) -> find_arg name 0 args)
227 ((Cic.Name name,ty'), t1', index)
230 constructor: [ [ name = IDENT; SYMBOL ":"; typ = term -> (name, typ) ] ];
232 [ vars = [ l = LIST1 IDENT SEP SYMBOL "," -> l | SYMBOL "_" -> ["_"]];
233 typ = OPT [ SYMBOL ":"; t = term -> t ] -> (vars, typ)
235 vars = [ l = LIST1 IDENT SEP SYMBOL "," -> l | SYMBOL "_" -> ["_"]];
236 typ = OPT [ SYMBOL ":"; t = term -> t ];
237 PAREN ")" -> (vars, typ)
240 term0: [ [ t = term; EOI -> return_term loc t ] ];
243 [ "let"; var = typed_name;
244 SYMBOL <:unicode<def>> (* ≝ *);
245 t1 = term; "in"; t2 = term ->
246 return_term loc (CicAst.LetIn (var, t1, t2))
247 | "let"; ind_kind = [ "corec" -> `CoInductive | "rec"-> `Inductive ];
248 defs = let_defs; "in"; body = term ->
249 return_term loc (CicAst.LetRec (ind_kind, defs, body))
253 b = binder_low; (vars, typ) = binder_vars; SYMBOL "."; body = term ->
254 let binder = mk_binder_ast b typ vars body in
255 return_term loc binder
256 | b = binder_high; (vars, typ) = binder_vars; SYMBOL "."; body = term ->
257 let binder = mk_binder_ast b typ vars body in
258 return_term loc binder
259 | t1 = term; SYMBOL <:unicode<to>> (* → *); t2 = term ->
260 return_term loc (CicAst.Binder (`Pi, (Cic.Anonymous, Some t1), t2))
262 | "logic_add" LEFTA [ (* nothing here by default *) ]
263 | "logic_mult" LEFTA [ (* nothing here by default *) ]
264 | "logic_inv" NONA [ (* nothing here by default *) ]
266 [ t1 = term; SYMBOL "="; t2 = term ->
267 return_term loc (CicAst.Appl [CicAst.Symbol ("eq", 0); t1; t2])
269 | "add" LEFTA [ (* nothing here by default *) ]
270 | "mult" LEFTA [ (* nothing here by default *) ]
271 | "power" LEFTA [ (* nothing here by default *) ]
272 | "inv" NONA [ (* nothing here by default *) ]
274 [ t1 = term; t2 = term ->
275 let rec aux = function
276 | CicAst.Appl (hd :: tl) -> aux hd @ tl
279 CicAst.Appl (aux t1 @ [t2])
282 [ sort = sort -> CicAst.Sort sort
283 | n = substituted_name -> return_term loc n
284 | i = NUM -> return_term loc (CicAst.Num (i, (fresh_num_instance ())))
285 | IMPLICIT -> return_term loc CicAst.Implicit
286 | PLACEHOLDER -> return_term loc CicAst.UserInput
289 PAREN "["; substs = LIST0 meta_subst SEP SYMBOL ";" ; PAREN "]" ->
294 int_of_string (String.sub m 1 (String.length m - 1))
295 with Failure "int_of_string" ->
296 fail loc ("Invalid meta variable number: " ^ m)
298 return_term loc (CicAst.Meta (index, substs))
299 | outtyp = OPT [ PAREN "["; typ = term; PAREN "]" -> typ ];
301 indty_ident = OPT ["in" ; id = IDENT -> id ];
305 lhs = pattern; SYMBOL <:unicode<Rightarrow>> (* ⇒ *); rhs = term
307 ((lhs: CicAst.case_pattern), rhs)
311 (CicAst.Case (t, indty_ident, outtyp, patterns))
312 | PAREN "("; t1 = term; SYMBOL ":"; t2 = term; PAREN ")" ->
313 return_term loc (CicAst.Appl [CicAst.Symbol ("cast", 0); t1; t2])
314 | PAREN "("; t = term; PAREN ")" -> return_term loc t
317 tactic_term: [ [ t = term -> t ] ];
319 [ PAREN "["; idents = LIST0 IDENT SEP SYMBOL ";"; PAREN "]" -> idents ]
322 [ tactic_terms = LIST1 tactic_term SEP SYMBOL "," -> tactic_terms ]
325 [ [ IDENT "reduce" ] -> `Reduce
326 | [ IDENT "simplify" ] -> `Simpl
327 | [ IDENT "whd" ] -> `Whd
328 | [ IDENT "normalize" ] -> `Normalize ]
330 sequent_pattern_spec : [
334 path = OPT [SYMBOL ":" ; path = term -> path ] ->
335 (id,match path with Some p -> p | None -> CicAst.UserInput) ]
337 goal_path = OPT [ SYMBOL <:unicode<vdash>>; term = term -> term ] ->
340 None -> CicAst.UserInput
341 | Some goal_path -> goal_path
350 [ "match" ; wanted = term ;
351 sps = OPT [ "in"; sps = sequent_pattern_spec -> sps ] ->
353 | sps = sequent_pattern_spec ->
356 let wanted,hyp_paths,goal_path =
357 match wanted_and_sps with
358 wanted,None -> wanted, [], CicAst.UserInput
359 | wanted,Some (hyp_paths,goal_path) -> wanted,hyp_paths,goal_path
361 wanted, hyp_paths, goal_path ] ->
363 None -> None,[],CicAst.UserInput
367 [ SYMBOL ">" -> `LeftToRight
368 | SYMBOL "<" -> `RightToLeft ]
371 [ IDENT "absurd"; t = tactic_term ->
372 TacticAst.Absurd (loc, t)
373 | IDENT "apply"; t = tactic_term ->
374 TacticAst.Apply (loc, t)
375 | IDENT "assumption" ->
376 TacticAst.Assumption loc
378 depth = OPT [ IDENT "depth"; SYMBOL "="; i = NUM -> int_of_string i ];
379 width = OPT [ IDENT "width"; SYMBOL "="; i = NUM -> int_of_string i ] ->
380 TacticAst.Auto (loc,depth,width)
381 | IDENT "clear"; id = IDENT ->
382 TacticAst.Clear (loc,id)
383 | IDENT "clearbody"; id = IDENT ->
384 TacticAst.ClearBody (loc,id)
385 | IDENT "change"; what = pattern_spec; "with"; t = tactic_term ->
386 TacticAst.Change (loc, what, t)
387 | IDENT "compare"; t = tactic_term ->
388 TacticAst.Compare (loc,t)
389 | IDENT "constructor"; n = NUM ->
390 TacticAst.Constructor (loc,int_of_string n)
391 | IDENT "contradiction" ->
392 TacticAst.Contradiction loc
393 | IDENT "cut"; t = tactic_term; ident = OPT [ "as"; id = IDENT -> id] ->
394 TacticAst.Cut (loc, ident, t)
395 | IDENT "decide"; IDENT "equality" ->
396 TacticAst.DecideEquality loc
397 | IDENT "decompose"; where = tactic_term ->
398 TacticAst.Decompose (loc, where)
399 | IDENT "discriminate"; t = tactic_term ->
400 TacticAst.Discriminate (loc, t)
401 | IDENT "elim"; t1 = tactic_term;
402 using = OPT [ "using"; using = tactic_term -> using ] ->
403 TacticAst.Elim (loc, t1, using)
404 | IDENT "elimType"; t = tactic_term ->
405 TacticAst.ElimType (loc, t)
406 | IDENT "exact"; t = tactic_term ->
407 TacticAst.Exact (loc, t)
410 | IDENT "fail" -> TacticAst.Fail loc
411 | IDENT "fold"; kind = reduction_kind; t = tactic_term; p = pattern_spec ->
416 (loc,"the pattern cannot specify the term to replace, only its paths in the hypotheses and in the conclusion"))
418 TacticAst.Fold (loc, kind, t, p)
420 TacticAst.Fourier loc
421 | IDENT "fwd"; hyp = IDENT; idents = OPT ident_list0 ->
422 let idents = match idents with None -> [] | Some idents -> idents in
423 TacticAst.FwdSimpl (loc, hyp, idents)
424 | IDENT "generalize"; p=pattern_spec; id = OPT ["as" ; id = IDENT -> id] ->
425 TacticAst.Generalize (loc,p,id)
426 | IDENT "goal"; n = NUM ->
427 TacticAst.Goal (loc, int_of_string n)
428 | IDENT "id" -> TacticAst.IdTac loc
429 | IDENT "injection"; t = tactic_term ->
430 TacticAst.Injection (loc, t)
431 | IDENT "intro"; ident = OPT IDENT ->
432 let idents = match ident with None -> [] | Some id -> [id] in
433 TacticAst.Intros (loc, Some 1, idents)
434 | IDENT "intros"; num = OPT [num = int -> num]; idents = OPT ident_list0 ->
435 let idents = match idents with None -> [] | Some idents -> idents in
436 TacticAst.Intros (loc, num, idents)
438 depth = OPT [ IDENT "depth"; SYMBOL "="; i = NUM -> int_of_string i ];
440 to_what = OPT [ "to" ; t = tactic_term_list1 -> t ];
441 ident = OPT [ "using" ; ident = IDENT -> ident ] ->
442 let to_what = match to_what with None -> [] | Some to_what -> to_what in
443 TacticAst.LApply (loc, depth, to_what, what, ident)
444 | IDENT "left" -> TacticAst.Left loc
445 | IDENT "letin"; where = IDENT ; SYMBOL <:unicode<def>> ; t = tactic_term ->
446 TacticAst.LetIn (loc, t, where)
447 | kind = reduction_kind; p = pattern_spec ->
448 TacticAst.Reduce (loc, kind, p)
449 | IDENT "reflexivity" ->
450 TacticAst.Reflexivity loc
451 | IDENT "replace"; p = pattern_spec; "with"; t = tactic_term ->
452 TacticAst.Replace (loc, p, t)
453 | IDENT "rewrite" ; d = direction; t = tactic_term ; p = pattern_spec ->
458 (loc,"the pattern cannot specify the term to rewrite, only its paths in the hypotheses and in the conclusion"))
460 TacticAst.Rewrite (loc, d, t, p)
467 | IDENT "symmetry" ->
468 TacticAst.Symmetry loc
469 | IDENT "transitivity"; t = tactic_term ->
470 TacticAst.Transitivity (loc, t)
475 [ tacticals = LIST1 NEXT SEP SYMBOL ";" ->
476 TacticAst.Seq (loc, tacticals)
480 PAREN "["; tacs = LIST0 tactical SEP SYMBOL "|"; PAREN "]" ->
481 (TacticAst.Then (loc, tac, tacs))
484 [ [ IDENT "do" ]; count = int; tac = tactical ->
485 TacticAst.Do (loc, count, tac)
486 | [ IDENT "repeat" ]; tac = tactical ->
487 TacticAst.Repeat (loc, tac)
491 PAREN "["; tacs = LIST0 tactical SEP SYMBOL ";"; PAREN "]" ->
492 TacticAst.Tries (loc, tacs)
493 | IDENT "try"; tac = NEXT ->
494 TacticAst.Try (loc, tac)
495 | PAREN "("; tac = tactical; PAREN ")" -> tac
496 | tac = tactic -> TacticAst.Tactic (loc, tac)
500 [ [ IDENT "definition" ] -> `Definition
501 | [ IDENT "fact" ] -> `Fact
502 | [ IDENT "lemma" ] -> `Lemma
503 | [ IDENT "remark" ] -> `Remark
504 | [ IDENT "theorem" ] -> `Theorem
508 fst_name = IDENT; params = LIST0 [ arg=arg -> arg ];
509 SYMBOL ":"; fst_typ = term; SYMBOL <:unicode<def>>; OPT SYMBOL "|";
510 fst_constructors = LIST0 constructor SEP SYMBOL "|";
513 name = IDENT; SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>;
514 OPT SYMBOL "|"; constructors = LIST0 constructor SEP SYMBOL "|" ->
515 (name, true, typ, constructors) ] SEP "with" -> types
519 (fun (names, typ) acc ->
520 (List.map (fun name -> (name, typ)) names) @ acc)
523 let fst_ind_type = (fst_name, true, fst_typ, fst_constructors) in
524 let tl_ind_types = match tl with None -> [] | Some types -> types in
525 let ind_types = fst_ind_type :: tl_ind_types in
530 name = IDENT; params = LIST0 [ arg = arg -> arg ] ;
531 SYMBOL ":"; typ = term; SYMBOL <:unicode<def>>; PAREN "{" ;
533 name = IDENT ; SYMBOL ":" ; ty = term -> (name,ty)
534 ] SEP SYMBOL ";"; PAREN "}" ->
537 (fun (names, typ) acc ->
538 (List.map (fun name -> (name, typ)) names) @ acc)
541 (params,name,typ,fields)
545 [ [ IDENT "quit" ] -> TacticAst.Quit loc
546 (* | [ IDENT "abort" ] -> TacticAst.Abort loc *)
547 | [ IDENT "print" ]; name = QSTRING -> TacticAst.Print (loc, name)
548 (* | [ IDENT "undo" ]; steps = OPT NUM ->
549 TacticAst.Undo (loc, int_opt steps)
550 | [ IDENT "redo" ]; steps = OPT NUM ->
551 TacticAst.Redo (loc, int_opt steps) *)
552 | [ IDENT "check" ]; t = term ->
553 TacticAst.Check (loc, t)
554 | [ IDENT "hint" ] -> TacticAst.Hint loc
555 | [ IDENT "whelp"; "match" ] ; t = term ->
556 TacticAst.WMatch (loc,t)
557 | [ IDENT "whelp"; IDENT "instance" ] ; t = term ->
558 TacticAst.WInstance (loc,t)
559 | [ IDENT "whelp"; IDENT "locate" ] ; id = IDENT ->
560 TacticAst.WLocate (loc,id)
561 | [ IDENT "whelp"; IDENT "elim" ] ; t = term ->
562 TacticAst.WElim (loc, t)
563 | [ IDENT "whelp"; IDENT "hint" ] ; t = term ->
564 TacticAst.WHint (loc,t)
565 | [ IDENT "print" ]; name = QSTRING -> TacticAst.Print (loc, name)
570 [ IDENT "id"; id = QSTRING; SYMBOL "="; uri = QSTRING ->
571 let alpha = "[a-zA-Z]" in
572 let num = "[0-9]+" in
573 let ident_cont = "\\("^alpha^"\\|"^num^"\\|_\\|\\\\\\)" in
574 let ident = "\\("^alpha^ident_cont^"*\\|_"^ident_cont^"+\\)" in
575 let rex = Str.regexp ("^"^ident^"$") in
576 if Str.string_match rex id 0 then
578 ("^\\(cic:/\\|theory:/\\)"^ident^
579 "\\(/"^ident^"+\\)*\\(\\."^ident^"\\)+"^
580 "\\(#xpointer("^ num^"\\(/"^num^"\\)+)\\)?$")
582 if Str.string_match rex uri 0 then
583 TacticAst.Ident_alias (id, uri)
585 raise (Parse_error (loc,sprintf "Not a valid uri: %s" uri))
587 raise (Parse_error (loc,sprintf "Not a valid identifier: %s" id))
588 | IDENT "symbol"; symbol = QSTRING;
589 instance = OPT [ PAREN "("; IDENT "instance"; n = NUM; PAREN ")" -> n ];
590 SYMBOL "="; dsc = QSTRING ->
592 match instance with Some i -> int_of_string i | None -> 0
594 TacticAst.Symbol_alias (symbol, instance, dsc)
596 instance = OPT [ PAREN "("; IDENT "instance"; n = NUM; PAREN ")" -> n ];
597 SYMBOL "="; dsc = QSTRING ->
599 match instance with Some i -> int_of_string i | None -> 0
601 TacticAst.Number_alias (instance, dsc)
606 [ IDENT "set" ]; n = QSTRING; v = QSTRING ->
607 TacticAst.Set (loc, n, v)
608 | [ IDENT "drop" ] -> TacticAst.Drop loc
609 | [ IDENT "qed" ] -> TacticAst.Qed loc
610 | flavour = theorem_flavour; name = IDENT; SYMBOL ":"; typ = term;
611 body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
612 TacticAst.Obj (loc,TacticAst.Theorem (flavour, name, typ, body))
613 | flavour = theorem_flavour; name = IDENT;
614 body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
615 TacticAst.Obj (loc,TacticAst.Theorem (flavour, name, CicAst.Implicit, body))
616 | "let"; ind_kind = [ "corec" -> `CoInductive | "rec"-> `Inductive ];
620 | ((Cic.Name name,Some ty),_,_) :: _ -> name,ty
621 | ((Cic.Name name,None),_,_) :: _ -> name,CicAst.Implicit
624 let body = CicAst.Ident (name,None) in
625 TacticAst.Obj (loc,TacticAst.Theorem(`Definition, name, ty,
626 Some (CicAst.LetRec (ind_kind, defs, body))))
628 | [ IDENT "inductive" ]; spec = inductive_spec ->
629 let (params, ind_types) = spec in
630 TacticAst.Obj (loc,TacticAst.Inductive (params, ind_types))
631 | [ IDENT "coinductive" ]; spec = inductive_spec ->
632 let (params, ind_types) = spec in
633 let ind_types = (* set inductive flags to false (coinductive) *)
634 List.map (fun (name, _, term, ctors) -> (name, false, term, ctors))
637 TacticAst.Obj (loc,TacticAst.Inductive (params, ind_types))
638 | [ IDENT "coercion" ] ; name = IDENT ->
639 TacticAst.Coercion (loc, CicAst.Ident (name,Some []))
640 | [ IDENT "coercion" ] ; name = URI ->
641 TacticAst.Coercion (loc, CicAst.Uri (name,Some []))
642 | [ IDENT "alias" ]; spec = alias_spec ->
643 TacticAst.Alias (loc, spec)
644 | [ IDENT "record" ]; (params,name,ty,fields) = record_spec ->
645 TacticAst.Obj (loc,TacticAst.Record (params,name,ty,fields))
649 [ cmd = command; SYMBOL "." -> TacticAst.Command (loc, cmd)
650 | tac = tactical; SYMBOL "." -> TacticAst.Tactical (loc, tac)
651 | mac = macro; SYMBOL "." -> TacticAst.Macro (loc, mac)
656 [ BEGINCOMMENT ; ex = executable ; ENDCOMMENT ->
657 TacticAst.Code (loc, ex)
659 TacticAst.Note (loc, str)
664 [ ex = executable -> TacticAst.Executable (loc,ex)
665 | com = comment -> TacticAst.Comment (loc, com)
669 [ l = LIST0 statement ; EOI -> l
674 let exc_located_wrapper f =
678 | Stdpp.Exc_located (floc, Stream.Error msg) ->
679 raise (Parse_error (floc, msg))
680 | Stdpp.Exc_located (floc, exn) ->
681 raise (Parse_error (floc, (Printexc.to_string exn)))
683 let parse_term stream =
684 exc_located_wrapper (fun () -> (Grammar.Entry.parse term0 stream))
685 let parse_statement stream =
686 exc_located_wrapper (fun () -> (Grammar.Entry.parse statement stream))
687 let parse_statements stream =
688 exc_located_wrapper (fun () -> (Grammar.Entry.parse statements stream))
693 (** {2 Interface for gTopLevel} *)
695 module EnvironmentP3 =
701 let aliases_grammar = Grammar.gcreate cic_lexer
702 let aliases = Grammar.Entry.create aliases_grammar "aliases"
707 (fun domain_item (dsc, _) acc ->
709 match domain_item with
711 TacticAstPp.pp_alias (TacticAst.Ident_alias (id, dsc)) ^ "."
712 | Symbol (symb, i) ->
713 TacticAstPp.pp_alias (TacticAst.Symbol_alias (symb, i, dsc))
716 TacticAstPp.pp_alias (TacticAst.Number_alias (i, dsc)) ^ "."
721 String.concat "\n" (List.sort compare aliases)
725 aliases: [ (* build an environment from an aliases list *)
726 [ aliases = LIST0 alias; EOI ->
728 (fun env (domain_item, codomain_item) ->
729 Environment.add domain_item codomain_item env)
730 Environment.empty aliases
733 alias: [ (* return a pair <domain_item, codomain_item> from an alias *)
736 [ IDENT "id"; id = IDENT; SYMBOL "="; suri = URI ->
737 (Id id, choice_of_uri suri)
738 | IDENT "symbol"; symbol = QSTRING;
739 PAREN "("; IDENT "instance"; instance = NUM; PAREN ")";
740 SYMBOL "="; dsc = QSTRING ->
741 (Symbol (symbol, int_of_string instance),
742 DisambiguateChoices.lookup_symbol_by_dsc symbol dsc)
744 PAREN "("; IDENT "instance"; instance = NUM; PAREN ")";
745 SYMBOL "="; dsc = QSTRING ->
746 (Num (int_of_string instance),
747 DisambiguateChoices.lookup_num_by_dsc dsc)
757 (fun () -> Grammar.Entry.parse aliases (Stream.of_string s))
760 (* vim:set encoding=utf8: *)