ocaml-ppx / ppxlib

Base library and tools for ppx rewriters
MIT License
248 stars 95 forks source link

No-arguments pattern in Ast_pattern #113

Open zbaylin opened 4 years ago

zbaylin commented 4 years ago

Hello, I am trying to write a ppx that essentially just drop-in replaces the expression [%operating_system] to a string which represents the operating system the user is running on.

In skeleton/pseudocode, this was the idea I was trying to go for:

open Ppxlib

let name = "operating_system"

let expand ~loc ~path:_ (env : string) =
  Ast_builder.Default.estring s ~loc

let ext =
  Extension.declare
    name
    Extension.Context.expression
    ____
    expand

let () = Ppxlib.Driver.register_transformation name ~extensions:[ext]

However, I'm not sure what to put where the ____ is if I don't require any arguments to be passed into my expression. Is there a way to do this without using more direct language hooks?

rgrinberg commented 4 years ago

I believe you're looking for this pattern:

Ast_pattern.(pstr nil)

Although it's not clear to me what you're trying to accomplish. Why can't you just use a normal let binding for the detected operating system?

pitag-ha commented 3 years ago

Hello @zbaylin, has your question been answered back then?