* http://helm.cs.unibo.it/
*)
-let debug = true
+let debug = false
let debug_print s =
if debug then begin
prerr_endline "<NEW_TEXTUAL_PARSER>";
* thus be interpreted differently than others *)
let use_fresh_num_instances = false
+ (** does the lexer return COMMENT tokens? *)
+let return_comments = false
+
open Printf
open DisambiguateTypes
exception Parse_error of Token.flocation * string
+let cic_lexer = CicTextualLexer2.cic_lexer ~comments:return_comments ()
+
let fresh_num_instance =
let n = ref 0 in
if use_fresh_num_instances then
let term = CicUtil.term_of_uri uri in
(uri, (fun _ _ _ -> term))
-let grammar = Grammar.gcreate CicTextualLexer2.cic_lexer
+let grammar = Grammar.gcreate cic_lexer
let term = Grammar.Entry.create grammar "term"
let term0 = Grammar.Entry.create grammar "term0"
else
uri
+let mk_binder_ast binder typ vars body =
+ List.fold_right
+ (fun var body ->
+ let name = name_of_string var in
+ CicAst.Binder (binder, (name, typ), body))
+ vars body
+
EXTEND
GLOBAL: term term0 tactic tactical tactical0 command script;
int: [
[ s = SYMBOL "_" -> None
| t = term -> Some t ]
];
- binder: [
- [ SYMBOL <:unicode<lambda>> (* λ *) -> `Lambda
- | SYMBOL <:unicode<Pi>> (* Π *) -> `Pi
+ binder_low: [
+ [ SYMBOL <:unicode<Pi>> (* Π *) -> `Pi
| SYMBOL <:unicode<exists>> (* ∃ *) -> `Exists
| SYMBOL <:unicode<forall>> (* ∀ *) -> `Forall ]
];
+ binder_high: [ [ SYMBOL <:unicode<lambda>> (* λ *) -> `Lambda ] ];
sort: [
[ "Prop" -> `Prop
| "Set" -> `Set
] SEP "and" -> defs
]];
constructor: [ [ name = IDENT; SYMBOL ":"; typ = term -> (name, typ) ] ];
+ binder_vars: [
+ [ vars = LIST1 IDENT SEP SYMBOL ",";
+ typ = OPT [ SYMBOL ":"; t = term -> t ] -> (vars, typ)
+ | PAREN "("; vars = LIST1 IDENT SEP SYMBOL ",";
+ typ = OPT [ SYMBOL ":"; t = term -> t ]; PAREN ")" -> (vars, typ)
+ ]
+ ];
term0: [ [ t = term; EOI -> return_term loc t ] ];
term:
[ "letin" NONA
]
| "binder" RIGHTA
[
- b = binder;
- (vars, typ) =
- [ vars = LIST1 IDENT SEP SYMBOL ",";
- typ = OPT [ SYMBOL ":"; t = term -> t ] -> (vars, typ)
- | PAREN "("; vars = LIST1 IDENT SEP SYMBOL ",";
- typ = OPT [ SYMBOL ":"; t = term -> t ]; PAREN ")" -> (vars, typ)
- ];
- SYMBOL "."; body = term ->
- let binder =
- List.fold_right
- (fun var body ->
- let name = name_of_string var in
- CicAst.Binder (b, (name, typ), body))
- vars body
- in
+ b = binder_low; (vars, typ) = binder_vars; SYMBOL "."; body = term ->
+ let binder = mk_binder_ast b typ vars body in
return_term loc binder
| t1 = term; SYMBOL <:unicode<to>> (* → *); t2 = term ->
- return_term loc
- (CicAst.Binder (`Pi, (Cic.Anonymous, Some t1), t2))
+ return_term loc (CicAst.Binder (`Pi, (Cic.Anonymous, Some t1), t2))
]
| "logic_add" LEFTA [ (* nothing here by default *) ]
| "logic_mult" LEFTA [ (* nothing here by default *) ]
in
CicAst.Appl (aux t1 @ [t2])
]
+ | "binder" RIGHTA
+ [
+ b = binder_high; (vars, typ) = binder_vars; SYMBOL "."; body = term ->
+ let binder = mk_binder_ast b typ vars body in
+ return_term loc binder
+ ]
| "simple" NONA
[ sort = sort -> CicAst.Sort sort
| n = substituted_name -> return_term loc n
let idents = match idents with None -> [] | Some idents -> idents in
return_tactic loc (TacticAst.Intros (num, idents))
| [ IDENT "intro" | IDENT "Intro" ] ->
- return_tactic loc (TacticAst.Intros (Some 1, []))
+ return_tactic loc (TacticAst.Intros (None, []))
| [ IDENT "left" | IDENT "Left" ] -> return_tactic loc TacticAst.Left
| [ "let" | "Let" ];
t = tactic_term; "in"; where = IDENT ->
[ cmd = command -> return_tactical loc (TacticAst.Command cmd) ]
| "sequence" LEFTA
[ tactics = LIST1 NEXT SEP SYMBOL ";" ->
- return_tactical loc (TacticAst.Seq tactics)
+ (match tactics with
+ | [tactic] -> tactic
+ | _ -> return_tactical loc (TacticAst.Seq tactics))
]
| "then" NONA
[ tac = tactical;
print_kind: [
[ [ IDENT "Env" | IDENT "env" | IDENT "Environment" | IDENT "environment" ]
-> `Env
+ | [ IDENT "Coer" | IDENT "coer" | IDENT "Coercions" | IDENT "coercions" ]
+ -> `Coer
] ];
command: [
];
script_entry: [
[ cmd = tactical0 -> Command cmd
- | s = COMMENT -> Comment (loc, s)
+(* | s = COMMENT -> Comment (loc, s) *)
]
];
script: [ [ entries = LIST0 script_entry; EOI -> (loc, entries) ] ];
let empty = ""
- let aliases_grammar = Grammar.gcreate CicTextualLexer2.cic_lexer
+ let aliases_grammar = Grammar.gcreate cic_lexer
let aliases = Grammar.Entry.create aliases_grammar "aliases"
let to_string env =