Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ unreleased

### Other Changes

- Add `Longident.to/of_compiler` to astlib to simplify maintenance
of ppx-es that interacts with other parts of the compiler-libs such
as the type checker. (#603, @NathanReb)

- Fix a bug where some infix operators such as `mod` would be printed as
raw identifiers by our `Pprintast`. (#601, @NathanReb)

Expand Down
2 changes: 1 addition & 1 deletion astlib/ast_504.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Longident = struct
type t (*IF_CURRENT = Ocaml_common.Longident.t *) =
type t = Longident_504.t =
| Lident of string
| Ldot of t Location.loc * string Location.loc
| Lapply of t Location.loc * t Location.loc
Expand Down
25 changes: 25 additions & 0 deletions astlib/longident.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,28 @@ let parse s =
(* should not happen, but don't put assert false
so as not to crash the toplevel (see Genprintval) *)
| Some v -> v

let rec to_504_plus lid =
let loc = Location.none in
match lid with
| Lident s -> Longident_504.Lident s
| Ldot (lid, s) ->
Longident_504.Ldot ({txt = to_504_plus lid; loc}, { txt = s; loc})
| Lapply (lid, lid2) ->
Longident_504.Lapply
({txt = to_504_plus lid; loc}, {txt= to_504_plus lid2; loc})

let rec from_504_plus lid =
match lid with
| Longident_504.Lident s -> Lident s
| Longident_504.Ldot (lid, s) -> Ldot (from_504_plus lid.txt, s.txt)
| Longident_504.Lapply (lid, lid2) ->
Lapply (from_504_plus lid.txt, from_504_plus lid2.txt)

let to_compiler lid =
(*IF_NOT_AT_LEAST 504 lid *)
(*IF_AT_LEAST 504 to_504_plus lid *)

let from_compiler lid =
(*IF_NOT_AT_LEAST 504 lid *)
(*IF_AT_LEAST 504 from_504_plus lid *)
4 changes: 4 additions & 0 deletions astlib/longident.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ val flatten : t -> string list

val parse : string -> t
(** Parse a string into a long identifier built upon [Lident] and [Ldot]. *)

val to_compiler : t -> Ocaml_common.Longident.t

val from_compiler : Ocaml_common.Longident.t -> t
5 changes: 5 additions & 0 deletions astlib/longident_504.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type t =
(*IF_AT_LEAST 504 Ocaml_common.Longident.t = *)
| Lident of string
| Ldot of t Location.loc * string Location.loc
| Lapply of t Location.loc * t Location.loc
5 changes: 5 additions & 0 deletions astlib/longident_504.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type t =
(*IF_AT_LEAST 504 Ocaml_common.Longident.t = *)
| Lident of string
| Ldot of t Location.loc * string Location.loc
| Lapply of t Location.loc * t Location.loc