Skip to content

Commit ed044d7

Browse files
authored
Merge pull request #603 from NathanReb/longident-to-compiler
Expose to/from_compiler in Astlib.Longident
2 parents 778974f + d903dfc commit ed044d7

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ unreleased
77

88
### Other Changes
99

10+
- Add `Longident.to/of_compiler` to astlib to simplify maintenance
11+
of ppx-es that interacts with other parts of the compiler-libs such
12+
as the type checker. (#603, @NathanReb)
13+
1014
- Fix a bug where some infix operators such as `mod` would be printed as
1115
raw identifiers by our `Pprintast`. (#601, @NathanReb)
1216

astlib/ast_504.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Longident = struct
2-
type t (*IF_CURRENT = Ocaml_common.Longident.t *) =
2+
type t = Longident_504.t =
33
| Lident of string
44
| Ldot of t Location.loc * string Location.loc
55
| Lapply of t Location.loc * t Location.loc

astlib/longident.ml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,28 @@ let parse s =
2929
(* should not happen, but don't put assert false
3030
so as not to crash the toplevel (see Genprintval) *)
3131
| Some v -> v
32+
33+
let rec to_504_plus lid =
34+
let loc = Location.none in
35+
match lid with
36+
| Lident s -> Longident_504.Lident s
37+
| Ldot (lid, s) ->
38+
Longident_504.Ldot ({txt = to_504_plus lid; loc}, { txt = s; loc})
39+
| Lapply (lid, lid2) ->
40+
Longident_504.Lapply
41+
({txt = to_504_plus lid; loc}, {txt= to_504_plus lid2; loc})
42+
43+
let rec from_504_plus lid =
44+
match lid with
45+
| Longident_504.Lident s -> Lident s
46+
| Longident_504.Ldot (lid, s) -> Ldot (from_504_plus lid.txt, s.txt)
47+
| Longident_504.Lapply (lid, lid2) ->
48+
Lapply (from_504_plus lid.txt, from_504_plus lid2.txt)
49+
50+
let to_compiler lid =
51+
(*IF_NOT_AT_LEAST 504 lid *)
52+
(*IF_AT_LEAST 504 to_504_plus lid *)
53+
54+
let from_compiler lid =
55+
(*IF_NOT_AT_LEAST 504 lid *)
56+
(*IF_AT_LEAST 504 from_504_plus lid *)

astlib/longident.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ val flatten : t -> string list
1313

1414
val parse : string -> t
1515
(** Parse a string into a long identifier built upon [Lident] and [Ldot]. *)
16+
17+
val to_compiler : t -> Ocaml_common.Longident.t
18+
19+
val from_compiler : Ocaml_common.Longident.t -> t

astlib/longident_504.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type t =
2+
(*IF_AT_LEAST 504 Ocaml_common.Longident.t = *)
3+
| Lident of string
4+
| Ldot of t Location.loc * string Location.loc
5+
| Lapply of t Location.loc * t Location.loc

astlib/longident_504.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type t =
2+
(*IF_AT_LEAST 504 Ocaml_common.Longident.t = *)
3+
| Lident of string
4+
| Ldot of t Location.loc * string Location.loc
5+
| Lapply of t Location.loc * t Location.loc

0 commit comments

Comments
 (0)