let level2_ast = Grammar.Entry.create level2_ast_grammar "level2_ast"
let term = Grammar.Entry.create level2_ast_grammar "term"
let let_defs = Grammar.Entry.create level2_ast_grammar "let_defs"
+let protected_binder_vars = Grammar.Entry.create level2_ast_grammar "protected_binder_vars"
let level2_meta = Grammar.Entry.create level2_meta_grammar "level2_meta"
let int_of_string s =
(* {{{ Grammar for ast patterns, notation level 2 *)
EXTEND
- GLOBAL: level2_ast term let_defs;
+ GLOBAL: level2_ast term let_defs protected_binder_vars;
level2_ast: [ [ p = term -> p ] ];
sort: [
[ "Prop" -> `Prop
index_name = OPT [ "on"; id = single_arg -> id ];
ty = OPT [ SYMBOL ":" ; p = term -> p ];
SYMBOL <:unicode<def>> (* ≝ *); body = term ->
- let body = fold_binder `Lambda args body in
- let ty =
- match ty with
- | None -> None
- | Some ty -> Some (fold_binder `Pi args ty)
- in
let rec position_of name p = function
| [] -> None, p
| n :: _ when n = name -> Some p, p
| None -> 0
| Some index_name -> find_arg index_name 0 args
in
- (name, ty), body, index
+ let args =
+ List.concat
+ (List.map
+ (function (names,ty) -> List.map (function x -> x,ty) names
+ ) args)
+ in
+ args, (name, ty), body, index
] SEP "and" ->
defs
]
l = LIST1 single_arg SEP SYMBOL "," -> l
| SYMBOL "_" -> [Ast.Ident ("_", None)] ];
typ = OPT [ SYMBOL ":"; t = term -> t ] -> (vars, typ)
- | LPAREN;
- vars = [
- l = LIST1 single_arg SEP SYMBOL "," -> l
- | SYMBOL "_" -> [Ast.Ident ("_", None)] ];
- typ = OPT [ SYMBOL ":"; t = term -> t ];
- RPAREN -> (vars, typ)
+ ]
+ ];
+ protected_binder_vars: [
+ [ LPAREN; vars = binder_vars; RPAREN -> vars
+ ]
+ ];
+ maybe_protected_binder_vars: [
+ [ vars = binder_vars -> vars
+ | vars = protected_binder_vars -> vars
]
];
term: LEVEL "10N" [ (* let in *)
];
term: LEVEL "20R" (* binder *)
[
- [ b = binder; (vars, typ) = binder_vars; SYMBOL "."; body = term ->
+ [ b = binder; (vars, typ) = maybe_protected_binder_vars; SYMBOL "."; body = term ->
return_term loc (fold_cluster b vars typ body)
| SYMBOL <:unicode<exists>> (* ∃ *);
- (vars, typ) = binder_vars; SYMBOL "."; body = term ->
+ (vars, typ) = maybe_protected_binder_vars; SYMBOL "."; body = term ->
return_term loc (fold_exists vars typ body)
]
];