let grammar = Grammar.gcreate CicTextualLexer2.lex
let term = Grammar.Entry.create grammar "term"
+let term0 = Grammar.Entry.create grammar "term0"
(* let tactic = Grammar.Entry.create grammar "tactic" *)
(* let tactical = Grammar.Entry.create grammar "tactical" *)
failwith (Printf.sprintf "Error at characters %d - %d: %s" x y msg)
EXTEND
- GLOBAL: term;
+ GLOBAL: term term0;
meta_subst: [
[ s = SYMBOL "_" -> None
| t = term -> Some t ]
[ s = [ IDENT | SYMBOL ];
subst = OPT [
SYMBOL "\subst"; (* to avoid catching frequent "a [1]" cases *)
- LPAREN "[";
+ PAREN "[";
substs = LIST1 [
i = IDENT; SYMBOL <:unicode<Assign>> (* ≔ *); t = term -> (i, t)
] SEP SYMBOL ";";
- RPAREN "]" ->
+ PAREN "]" ->
substs
] ->
(match subst with
];
pattern: [
[ n = name -> [n]
- | LPAREN "("; names = LIST1 name; RPAREN ")" -> names ]
+ | PAREN "("; names = LIST1 name; PAREN ")" -> names ]
];
+ term0: [ [ t = term -> return_term loc t ] ];
term:
[ "arrow" RIGHTA
[ t1 = term; SYMBOL <:unicode<to>>; t2 = term ->
] ->
CicTextualParser2Ast.Sort sort_kind
| n = substituted_name -> return_term loc n
- | LPAREN "("; head = term; args = LIST1 term; RPAREN ")" ->
+ | PAREN "("; head = term; args = LIST1 term; PAREN ")" ->
return_term loc (CicTextualParser2Ast.Appl (head :: args))
| i = NUM -> return_term loc (CicTextualParser2Ast.Num (i, 0))
| m = META;
substs = [
- LPAREN "["; substs = LIST0 meta_subst SEP SYMBOL ";" ; RPAREN "]" ->
+ PAREN "["; substs = LIST0 meta_subst SEP SYMBOL ";" ; PAREN "]" ->
substs
] ->
let index =
| "let"; ind_kind = [ "corec" -> `CoInductive | "rec"-> `Inductive ];
defs = LIST1 [
name = IDENT;
- index = OPT [ LPAREN "("; index = INT; RPAREN ")" ->
+ index = OPT [ PAREN "("; index = INT; PAREN ")" ->
int_of_string index
];
typ = OPT [ SYMBOL ":"; typ = term -> typ ];
] SEP (IDENT "and");
IDENT "in"; body = term ->
return_term loc (CicTextualParser2Ast.LetRec (ind_kind, defs, body))
- | outtyp = OPT [ LPAREN "["; typ = term; RPAREN "]" -> typ ];
+ | outtyp = OPT [ PAREN "["; typ = term; PAREN "]" -> typ ];
"match"; t = term;
SYMBOL ":"; indty = IDENT;
"with";
- LPAREN "[";
+ PAREN "[";
patterns = LIST0 [
- p = pattern; SYMBOL <:unicode<Rightarrow>> (* ⇒ *); t = term -> (p, t)
+ p = pattern; SYMBOL <:unicode<Rightarrow>> (* ⇒ *); t = term ->
+ (p, t)
] SEP SYMBOL "|";
- RPAREN "]" ->
- return_term loc (CicTextualParser2Ast.Case (t, indty, outtyp, patterns))
- | LPAREN "("; t = term; RPAREN ")" -> return_term loc t
+ PAREN "]" ->
+ return_term loc
+ (CicTextualParser2Ast.Case (t, indty, outtyp, patterns))
+ | PAREN "("; t = term; PAREN ")" -> return_term loc t
]
];
END
let parse_term stream =
try
- Grammar.Entry.parse term stream
+ Grammar.Entry.parse term0 stream
with Stdpp.Exc_located ((x, y), exn) ->
raise (Parse_error (sprintf "parse error at characters %d-%d: %s" x y
(Printexc.to_string exn)))