Commit 5ecba3df authored by POTTIER Francois's avatar POTTIER Francois

Change the type [Positions.t] to just a pair of positions.

It is abstract, so this makes no difference outside this module.
parent 42ee683d
......@@ -14,10 +14,8 @@
open Lexing
type t =
{
start_p : Lexing.position;
end_p : Lexing.position
}
(* Start and end positions. *)
position * position
type 'a located =
{
......@@ -38,7 +36,7 @@ let with_pos p v =
}
let with_poss p1 p2 v =
with_pos { start_p = p1; end_p = p2 } v
with_pos (p1, p2) v
let map f v =
{
......@@ -56,10 +54,7 @@ let mapd f v =
{ value = w2; position = pos }
let dummy =
{
start_p = Lexing.dummy_pos;
end_p = Lexing.dummy_pos
}
(dummy_pos, dummy_pos)
let unknown_pos v =
{
......@@ -67,12 +62,12 @@ let unknown_pos v =
position = dummy
}
let start_of_position p = p.start_p
let start_of_position (p, _) = p
let end_of_position p = p.end_p
let end_of_position (_, p) = p
let filename_of_position p =
p.start_p.Lexing.pos_fname
(start_of_position p).pos_fname
let line p =
p.pos_lnum
......@@ -84,16 +79,13 @@ let characters p1 p2 =
(column p1, p2.pos_cnum - p1.pos_bol) (* intentionally [p1.pos_bol] *)
let join x1 x2 =
{
start_p = if x1 = dummy then x2.start_p else x1.start_p;
end_p = if x2 = dummy then x1.end_p else x2.end_p
}
(
start_of_position (if x1 = dummy then x2 else x1),
end_of_position (if x2 = dummy then x1 else x2)
)
let lex_join x1 x2 =
{
start_p = x1;
end_p = x2
}
(x1, x2)
let join_located l1 l2 f =
{
......@@ -108,8 +100,8 @@ let string_of_lex_pos p =
let string_of_pos p =
let filename = filename_of_position p in
(* [filename] is hopefully not "". *)
let l = line p.start_p in
let c1, c2 = characters p.start_p p.end_p in
let l = line (start_of_position p) in
let c1, c2 = characters (start_of_position p) (end_of_position p) in
Printf.sprintf "File \"%s\", line %d, characters %d-%d" filename l c1 c2
let pos_or_undef = function
......@@ -117,10 +109,7 @@ let pos_or_undef = function
| Some x -> x
let cpos lexbuf =
{
start_p = Lexing.lexeme_start_p lexbuf;
end_p = Lexing.lexeme_end_p lexbuf;
}
(lexeme_start_p lexbuf, lexeme_end_p lexbuf)
let with_cpos lexbuf v =
with_pos (cpos lexbuf) v
......@@ -146,16 +135,16 @@ let join_located_list ls f =
type positions =
t list
let one (pos : Lexing.position) : positions =
[ { start_p = pos; end_p = pos } ] (* or: lex_join pos pos *)
let one (pos : position) : positions =
[ (pos, pos) ] (* or: lex_join pos pos *)
let two (pos1 : Lexing.position) (pos2 : Lexing.position) : positions =
let two (pos1 : position) (pos2 : position) : positions =
[ lex_join pos1 pos2 ]
let lexbuf (lexbuf : Lexing.lexbuf) : positions =
[ lex_join lexbuf.Lexing.lex_start_p lexbuf.Lexing.lex_curr_p ]
let lexbuf (lexbuf : lexbuf) : positions =
[ lex_join lexbuf.lex_start_p lexbuf.lex_curr_p ]
let print (pos : Lexing.position) =
let print (pos : position) =
Printf.printf
"{ pos_fname = \"%s\"; pos_lnum = %d; pos_bol = %d; pos_cnum = %d }\n"
pos.pos_fname
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment