Skip to content

Fix syntax #62

@pitag-ha

Description

@pitag-ha

With the syntax type t = [%import: Foo.bla], the [%import: Foo.bla] is written at a place where the OCaml parser expects a core type extension node. But ppx_import doesn't only want to inject a core type (ptype_manifest) into the corresponding type declaration. It also wants to inject the concrete type definition (ptype_kind), which breaks with the idea of an extension node being local.

To express ppx_import in an OCaml AST conform syntax, it would have to be written as a extension node at the level of a structure item. Derivers such as sexp or yojson would just be packed into the payload. That would look as follows:

[%%import : type t = Foo.bla [@@deriving sexp,yojson]]

or, expressed in a nicer way:

type%import t = Foo.bla [@@deriving sexp,yojson]

That syntax would be conform with the OCaml AST and, as a nice "side-effect", it would also be convenient from a source-code point of view.

Of course, releasing that syntax change would break all users. But it doesn't break the semantics or features, it only breaks the syntax and so one could use a simple sed command on a project in order to upgrade to the new ppx_import. You could also prepare for the breaking change by making a 1.x release allowing both syntaxes, but deprecating the old one.

What do you think about the proposed syntax in general? And what do you think about introducing it in a major release?

(cc @NathanReb since we've been talking about this)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions