module Ast = CicNotationPt
+type statement =
+ (CicNotationPt.term, CicNotationPt.term, GrafiteAst.reduction,
+ GrafiteAst.obj, string)
+ GrafiteAst.statement
+
let grammar = CicNotationParser.level2_ast_grammar
let term = CicNotationParser.term
]
];
constructor: [ [ name = IDENT; SYMBOL ":"; typ = term -> (name, typ) ] ];
- tactic_term: [ [ t = term -> t ] ];
- ident_list0: [
- [ SYMBOL "["; idents = LIST0 IDENT SEP SYMBOL ";"; SYMBOL "]" -> idents ]
- ];
+ tactic_term: [ [ t = term LEVEL "90N" -> t ] ];
+ ident_list0: [ [ LPAREN; idents = LIST0 IDENT; RPAREN -> idents ] ];
tactic_term_list1: [
[ tactic_terms = LIST1 tactic_term SEP SYMBOL "," -> tactic_terms ]
];
[ hyp_paths =
LIST0
[ id = IDENT ;
- path = OPT [SYMBOL ":" ; path = term -> path ] ->
- (id,match path with Some p -> p | None -> Ast.UserInput) ]
- SEP SYMBOL ";";
- goal_path = OPT [ SYMBOL <:unicode<vdash>>; term = term -> term ] ->
+ path = OPT [SYMBOL ":" ; path = tactic_term -> path ] ->
+ (id,match path with Some p -> p | None -> Ast.UserInput) ];
+ goal_path = OPT [ SYMBOL <:unicode<vdash>>; term = tactic_term -> term ] ->
let goal_path =
match goal_path, hyp_paths with
None, [] -> Ast.UserInput
[ res = OPT [
"in";
wanted_and_sps =
- [ "match" ; wanted = term ;
+ [ "match" ; wanted = tactic_term ;
sps = OPT [ "in"; sps = sequent_pattern_spec -> sps ] ->
Some wanted,sps
| sps = sequent_pattern_spec ->
| SYMBOL "<" -> `RightToLeft ]
];
int: [ [ num = NUMBER -> int_of_string num ] ];
+ intros_spec: [
+ [ num = OPT [ num = int -> num ]; idents = OPT ident_list0 ->
+ let idents = match idents with None -> [] | Some idents -> idents in
+ num, idents
+ ]
+ ];
+ using: [ [ using = OPT [ IDENT "using"; t = tactic_term -> t ] -> using ] ];
tactic: [
[ IDENT "absurd"; t = tactic_term ->
GrafiteAst.Absurd (loc, t)
| IDENT "auto";
depth = OPT [ IDENT "depth"; SYMBOL "="; i = int -> i ];
width = OPT [ IDENT "width"; SYMBOL "="; i = int -> i ];
- paramodulation = OPT [ IDENT "paramodulation" ] -> (* ALB *)
- GrafiteAst.Auto (loc,depth,width,paramodulation)
+ paramodulation = OPT [ IDENT "paramodulation" ];
+ full = OPT [ IDENT "full" ] -> (* ALB *)
+ GrafiteAst.Auto (loc,depth,width,paramodulation,full)
| IDENT "clear"; id = IDENT ->
GrafiteAst.Clear (loc,id)
| IDENT "clearbody"; id = IDENT ->
| IDENT "decide"; IDENT "equality" ->
GrafiteAst.DecideEquality loc
| IDENT "decompose"; types = OPT ident_list0; what = IDENT;
- OPT "names"; num = OPT [num = int -> num];
- idents = OPT ident_list0 ->
- let idents = match idents with None -> [] | Some idents -> idents in
+ (num, idents) = intros_spec ->
let types = match types with None -> [] | Some types -> types in
let to_spec id = GrafiteAst.Ident id in
GrafiteAst.Decompose (loc, List.rev_map to_spec types, what, idents)
| IDENT "discriminate"; t = tactic_term ->
GrafiteAst.Discriminate (loc, t)
- | IDENT "elim"; what = tactic_term;
- using = OPT [ "using"; using = tactic_term -> using ];
- OPT "names"; num = OPT [num = int -> num];
- idents = OPT ident_list0 ->
- let idents = match idents with None -> [] | Some idents -> idents in
+ | IDENT "elim"; what = tactic_term; using = using;
+ (num, idents) = intros_spec ->
GrafiteAst.Elim (loc, what, using, num, idents)
- | IDENT "elimType"; what = tactic_term;
- using = OPT [ "using"; using = tactic_term -> using ];
- OPT "names"; num = OPT [num = int -> num]; idents = OPT ident_list0 ->
- let idents = match idents with None -> [] | Some idents -> idents in
+ | IDENT "elimType"; what = tactic_term; using = using;
+ (num, idents) = intros_spec ->
GrafiteAst.ElimType (loc, what, using, num, idents)
| IDENT "exact"; t = tactic_term ->
GrafiteAst.Exact (loc, t)
| IDENT "fold"; kind = reduction_kind; t = tactic_term; p = pattern_spec ->
let (pt,_,_) = p in
if pt <> None then
- raise (CicNotationParser.Parse_error
- (loc, "the pattern cannot specify the term to replace, only its"
- ^ " paths in the hypotheses and in the conclusion"))
+ raise (HExtlib.Localized (loc, CicNotationParser.Parse_error
+ ("the pattern cannot specify the term to replace, only its"
+ ^ " paths in the hypotheses and in the conclusion")))
else
GrafiteAst.Fold (loc, kind, t, p)
| IDENT "fourier" ->
| IDENT "intro"; ident = OPT IDENT ->
let idents = match ident with None -> [] | Some id -> [id] in
GrafiteAst.Intros (loc, Some 1, idents)
- | IDENT "intros"; num = OPT [num = int -> num]; idents = OPT ident_list0 ->
- let idents = match idents with None -> [] | Some idents -> idents in
+ | IDENT "intros"; (num, idents) = intros_spec ->
GrafiteAst.Intros (loc, num, idents)
| IDENT "lapply";
depth = OPT [ IDENT "depth"; SYMBOL "="; i = int -> i ];
what = tactic_term;
to_what = OPT [ "to" ; t = tactic_term_list1 -> t ];
- ident = OPT [ "using" ; ident = IDENT -> ident ] ->
+ ident = OPT [ IDENT "using" ; ident = IDENT -> ident ] ->
let to_what = match to_what with None -> [] | Some to_what -> to_what in
GrafiteAst.LApply (loc, depth, to_what, what, ident)
| IDENT "left" -> GrafiteAst.Left loc
let (pt,_,_) = p in
if pt <> None then
raise
- (CicNotationParser.Parse_error
- (loc,"the pattern cannot specify the term to rewrite, only its paths in the hypotheses and in the conclusion"))
+ (HExtlib.Localized (loc,
+ (CicNotationParser.Parse_error
+ "the pattern cannot specify the term to rewrite, only its paths in the hypotheses and in the conclusion")))
else
GrafiteAst.Rewrite (loc, d, t, p)
| IDENT "right" ->
GrafiteAst.Transitivity (loc, t)
]
];
- tactical:
+ atomic_tactical:
[ "sequence" LEFTA
- [ tacticals = LIST1 NEXT SEP SYMBOL ";" ->
- match tacticals with
- [] -> assert false
- | [tac] -> tac
- | l -> GrafiteAst.Seq (loc, l)
+ [ t1 = SELF; SYMBOL ";"; t2 = SELF ->
+ let ts =
+ match t1 with
+ | GrafiteAst.Seq (_, l) -> l @ [ t2 ]
+ | _ -> [ t1; t2 ]
+ in
+ GrafiteAst.Seq (loc, ts)
]
| "then" NONA
- [ tac = tactical; SYMBOL ";";
- SYMBOL "["; tacs = LIST0 tactical SEP SYMBOL "|"; SYMBOL "]" ->
+ [ tac = SELF; SYMBOL ";";
+ SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
(GrafiteAst.Then (loc, tac, tacs))
]
| "loops" RIGHTA
- [ IDENT "do"; count = int; tac = tactical ->
+ [ IDENT "do"; count = int; tac = SELF; IDENT "end" ->
GrafiteAst.Do (loc, count, tac)
- | IDENT "repeat"; tac = tactical ->
- GrafiteAst.Repeat (loc, tac)
+ | IDENT "repeat"; tac = SELF; IDENT "end" -> GrafiteAst.Repeat (loc, tac)
]
| "simple" NONA
[ IDENT "first";
- SYMBOL "["; tacs = LIST0 tactical SEP SYMBOL "|"; SYMBOL "]" ->
+ SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
GrafiteAst.First (loc, tacs)
- | IDENT "try"; tac = NEXT ->
- GrafiteAst.Try (loc, tac)
+ | IDENT "try"; tac = SELF -> GrafiteAst.Try (loc, tac)
| IDENT "solve";
- SYMBOL "["; tacs = LIST0 tactical SEP SYMBOL "|"; SYMBOL "]" ->
+ SYMBOL "["; tacs = LIST0 SELF SEP SYMBOL "|"; SYMBOL "]"->
GrafiteAst.Solve (loc, tacs)
- | LPAREN; tac = tactical; RPAREN -> tac
+ | LPAREN; tac = SELF; RPAREN -> tac
| tac = tactic -> GrafiteAst.Tactic (loc, tac)
]
];
+ punctuation_tactical:
+ [
+ [ SYMBOL "[" -> GrafiteAst.Branch loc
+ | SYMBOL "|" -> GrafiteAst.Shift loc
+ | i = int; SYMBOL ":" -> GrafiteAst.Pos (loc, i)
+ | SYMBOL "]" -> GrafiteAst.Merge loc
+ | SYMBOL ";" -> GrafiteAst.Semicolon loc
+ | SYMBOL "." -> GrafiteAst.Dot loc
+ ]
+ ];
+ tactical:
+ [ "simple" NONA
+ [ IDENT "focus"; goals = LIST1 int -> GrafiteAst.Focus (loc, goals)
+ | IDENT "unfocus" -> GrafiteAst.Unfocus loc
+ | IDENT "skip" -> GrafiteAst.Skip loc
+ | tac = atomic_tactical LEVEL "loops" -> tac
+ ]
+ ];
theorem_flavour: [
[ [ IDENT "definition" ] -> `Definition
| [ IDENT "fact" ] -> `Fact
macro: [
[ [ IDENT "quit" ] -> GrafiteAst.Quit loc
(* | [ IDENT "abort" ] -> GrafiteAst.Abort loc *)
- | [ IDENT "print" ]; name = QSTRING -> GrafiteAst.Print (loc, name)
(* | [ IDENT "undo" ]; steps = OPT NUMBER ->
GrafiteAst.Undo (loc, int_opt steps)
| [ IDENT "redo" ]; steps = OPT NUMBER ->
then
GrafiteAst.Ident_alias (id, uri)
else
- raise (CicNotationParser.Parse_error (loc,sprintf "Not a valid uri: %s" uri))
+ raise
+ (HExtlib.Localized (loc, CicNotationParser.Parse_error (sprintf "Not a valid uri: %s" uri)))
else
- raise (CicNotationParser.Parse_error (loc,
- sprintf "Not a valid identifier: %s" id))
+ raise (HExtlib.Localized (loc, CicNotationParser.Parse_error (
+ sprintf "Not a valid identifier: %s" id)))
| IDENT "symbol"; symbol = QSTRING;
instance = OPT [ LPAREN; IDENT "instance"; n = int; RPAREN -> n ];
SYMBOL "="; dsc = QSTRING ->
| flavour = theorem_flavour; name = IDENT; SYMBOL ":"; typ = term;
body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
GrafiteAst.Obj (loc,GrafiteAst.Theorem (flavour, name, typ, body))
- | flavour = theorem_flavour; name = IDENT;
- body = OPT [ SYMBOL <:unicode<def>> (* ≝ *); body = term -> body ] ->
+ | flavour = theorem_flavour; name = IDENT; SYMBOL <:unicode<def>> (* ≝ *);
+ body = term ->
GrafiteAst.Obj (loc,
- GrafiteAst.Theorem (flavour, name, Ast.Implicit, body))
+ GrafiteAst.Theorem (flavour, name, Ast.Implicit, Some body))
| "let"; ind_kind = [ "corec" -> `CoInductive | "rec"-> `Inductive ];
defs = CicNotationParser.let_defs ->
let name,ty =
let body = Ast.Ident (name,None) in
GrafiteAst.Obj (loc,GrafiteAst.Theorem(`Definition, name, ty,
Some (Ast.LetRec (ind_kind, defs, body))))
- | [ IDENT "inductive" ]; spec = inductive_spec ->
+ | IDENT "inductive"; spec = inductive_spec ->
let (params, ind_types) = spec in
GrafiteAst.Obj (loc,GrafiteAst.Inductive (params, ind_types))
- | [ IDENT "coinductive" ]; spec = inductive_spec ->
+ | IDENT "coinductive"; spec = inductive_spec ->
let (params, ind_types) = spec in
let ind_types = (* set inductive flags to false (coinductive) *)
List.map (fun (name, _, term, ctors) -> (name, false, term, ctors))
| IDENT "interpretation"; id = QSTRING;
(symbol, args, l3) = interpretation ->
GrafiteAst.Interpretation (loc, id, (symbol, args), l3)
+ | IDENT "metadata"; [ IDENT "dependency" | IDENT "baseuri" ] ; URI ->
+ (** metadata commands lives only in .moo, where they are in marshalled
+ * form *)
+ raise (HExtlib.Localized (loc,CicNotationParser.Parse_error "metadata not allowed here"))
| IDENT "dump" -> GrafiteAst.Dump loc
| IDENT "render"; u = URI ->
]];
executable: [
[ cmd = command; SYMBOL "." -> GrafiteAst.Command (loc, cmd)
- | tac = tactical; SYMBOL "." -> GrafiteAst.Tactical (loc, tac)
+ | tac = tactical; punct = punctuation_tactical ->
+ GrafiteAst.Tactical (loc, tac, Some punct)
+ | punct = punctuation_tactical -> GrafiteAst.Tactical (loc, punct, None)
| mac = macro; SYMBOL "." -> GrafiteAst.Macro (loc, mac)
]
];
with
| Stdpp.Exc_located (_, End_of_file) -> raise End_of_file
| Stdpp.Exc_located (floc, Stream.Error msg) ->
- raise (CicNotationParser.Parse_error (floc, msg))
+ raise (HExtlib.Localized (floc,CicNotationParser.Parse_error msg))
| Stdpp.Exc_located (floc, exn) ->
- raise (CicNotationParser.Parse_error (floc, (Printexc.to_string exn)))
+ raise
+ (HExtlib.Localized (floc,CicNotationParser.Parse_error (Printexc.to_string exn)))
let parse_statement lexbuf =
exc_located_wrapper