let error_at_end lexbuf msg =
raise (Error (Ulexing.lexeme_end lexbuf, Ulexing.lexeme_end lexbuf, msg))
-let return lexbuf token = (token, Ulexing.loc lexbuf)
+let return lexbuf token =
+ let flocation_begin =
+ { Lexing.pos_fname = ""; Lexing.pos_lnum = -1; Lexing.pos_bol = -1;
+ Lexing.pos_cnum = Ulexing.lexeme_start lexbuf }
+ in
+ let flocation_end =
+ { flocation_begin with Lexing.pos_cnum = Ulexing.lexeme_end lexbuf }
+ in
+ (token, (flocation_begin, flocation_end))
(*
let parse_ext_ident ident =
let tok_func stream =
let lexbuf = Ulexing.from_utf8_stream stream in
- Token.make_stream_and_location
+ Token.make_stream_and_flocation
(fun () ->
try
token lexbuf
let return_tactical loc tactical = TacticAst.LocatedTactical (loc, tactical)
let return_command loc cmd = cmd
-let fail (x, y) msg =
+let fail floc msg =
+ let (x, y) = CicAst.loc_of_floc floc in
failwith (Printf.sprintf "Error at characters %d - %d: %s" x y msg)
let name_of_string = function
try
int_of_string num
with Failure _ ->
- let (x, y) = loc in
+ let (x, y) = CicAst.loc_of_floc loc in
raise (Parse_error (sprintf
"integer literal expected at characters %d-%d" x y))
]
substituted_name: [ (* a subs.name is an explicit substitution subject *)
[ s = [ IDENT | SYMBOL ];
subst = OPT [
- SYMBOL "\subst"; (* to avoid catching frequent "a [1]" cases *)
+ SYMBOL "\\subst"; (* to avoid catching frequent "a [1]" cases *)
PAREN "[";
substs = LIST1 [
i = IDENT; SYMBOL <:unicode<Assign>> (* ≔ *); t = term -> (i, t)
let exc_located_wrapper f =
try
Lazy.force f
- with Stdpp.Exc_located ((x, y), exn) ->
+ with Stdpp.Exc_located (floc, exn) ->
+ let (x, y) = CicAst.loc_of_floc floc in
raise (Parse_error (sprintf "parse error at characters %d-%d: %s" x y
(Printexc.to_string exn)))
else
try
Grammar.Entry.parse aliases (Stream.of_string s)
- with Stdpp.Exc_located ((x, y), exn) ->
+ with Stdpp.Exc_located (floc, exn) ->
+ let (x, y) = CicAst.loc_of_floc floc in
raise (Parse_error (sprintf "parse error at characters %d-%d: %s" x y
(Printexc.to_string exn)))
end
in
match ast with
| CicAst.AttributedTerm (`Loc loc, term) -> aux loc context term
- | term -> aux (-1, -1) context term
+ | term -> aux CicAst.dummy_floc context term
let domain_of_term ~context ast =
(* "aux" keeps domain in reverse order and doesn't care about duplicates.
rev_uniq
(match ast with
| CicAst.AttributedTerm (`Loc loc, term) -> aux loc context term
- | term -> aux (-1, -1) context term)
-
+ | term -> aux CicAst.dummy_floc context term)
(* dom1 \ dom2 *)
let domain_diff dom1 dom2 =
let debug = false
let debug_print s = if debug then prerr_endline s
-let loc = (0, 0)
+let loc =
+ let dummy_pos =
+ { Lexing.pos_fname = ""; Lexing.pos_lnum = -1; Lexing.pos_bol = -1;
+ Lexing.pos_cnum = -1 }
+ in
+ (dummy_pos, dummy_pos)
let expand_unicode_macro macro =
debug_print (Printf.sprintf "Expanding macro '%s' ..." macro);
let map_attribute =
function
- `Loc (n,m) ->
+ `Loc floc ->
+ let (n, m) = CicAst.loc_of_floc floc in
(Some "helm","loc",(string_of_int n)^" "^(string_of_int m))
| `IdRef s ->
(Some "helm","xref",s)
* http://helm.cs.unibo.it/
*)
-type location = int * int
+(** {2 Parsing related types} *)
+
+type location = Lexing.position * Lexing.position
+
+ (* maps old style (i.e. <= 3.07) lexer location to new style location, padding
+ * with dummy values where needed *)
+let floc_of_loc (loc_begin, loc_end) =
+ let floc_begin =
+ { Lexing.pos_fname = ""; Lexing.pos_lnum = -1; Lexing.pos_bol = -1;
+ Lexing.pos_cnum = loc_begin }
+ in
+ let floc_end = { floc_begin with Lexing.pos_cnum = loc_end } in
+ (floc_begin, floc_end)
+
+ (* the other way round *)
+let loc_of_floc = function
+ | { Lexing.pos_cnum = loc_begin }, { Lexing.pos_cnum = loc_end } ->
+ (loc_begin, loc_end)
+
+let dummy_floc = floc_of_loc (-1, -1)
+
+(** {2 Cic Ast} *)
type binder_kind = [ `Lambda | `Pi | `Exists | `Forall ]
type induction_kind = [ `Inductive | `CoInductive ]