aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/loc.ml
diff options
context:
space:
mode:
authorGravatar Emilio Jesus Gallego Arias <e+git@x80.org>2017-01-18 15:46:23 +0100
committerGravatar Emilio Jesus Gallego Arias <e+git@x80.org>2017-04-25 00:28:53 +0200
commite8a6467545c2814c9418889201e8be19c0cef201 (patch)
tree7f513d854b76b02f52f98ee0e87052c376175a0f /lib/loc.ml
parent30d3515546cf244837c6340b6b87c5f51e68cbf4 (diff)
[location] Make location optional in Loc.located
This completes the Loc.ghost removal, the idea is to gear the API towards optional, but uniform, location handling. We don't print <unknown> anymore in the case there is no location. This is what the test suite expects. The old printing logic for located items was a bit inconsistent as it sometimes printed <unknown> and other times it printed nothing as the caller checked for `is_ghost` upstream.
Diffstat (limited to 'lib/loc.ml')
-rw-r--r--lib/loc.ml25
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/loc.ml b/lib/loc.ml
index 3051ca7b9..e02fe108d 100644
--- a/lib/loc.ml
+++ b/lib/loc.ml
@@ -45,33 +45,32 @@ let merge loc1 loc2 =
bp = loc2.bp; ep = loc1.ep; }
else loc2
-let merge_opt l1 l2 = Option.cata (fun l1 -> merge l1 l2) l2 l1
-let opt_merge l1 l2 = Option.cata (fun l2 -> merge l1 l2) l1 l2
+let merge_opt l1 l2 = match l1, l2 with
+ | None, None -> None
+ | Some l , None -> Some l
+ | None, Some l -> Some l
+ | Some l1, Some l2 -> Some (merge l1 l2)
let unloc loc = (loc.bp, loc.ep)
let join_loc = merge
-(** Located type *)
-
-type 'a located = t * 'a
-
-let is_ghost loc = loc.ep = 0
-
-let ghost = {
+let internal_ghost = {
fname = ""; line_nb = -1; bol_pos = 0; line_nb_last = -1; bol_pos_last = 0;
bp = 0; ep = 0; }
-let internal_ghost = ghost
+(** Located type *)
+type 'a located = t option * 'a
+
let to_pair x = x
-let tag ?loc x = Option.default ghost loc, x
+let tag ?loc x = loc, x
let obj (_,x) = x
-let with_loc f (loc, x) = f ~loc x
+let with_loc f (loc, x) = f ?loc x
let with_unloc f (_,x) = f x
let map f (l,x) = (l, f x)
-let map_with_loc f (loc, x) = (loc, f ~loc x)
+let map_with_loc f (loc, x) = (loc, f ?loc x)
let located_fold_left f x (_,a) = f x a
let located_iter2 f (_,a) (_,b) = f a b