ppxlib icon indicating copy to clipboard operation
ppxlib copied to clipboard

No-arguments pattern in Ast_pattern

Open zbaylin opened this issue 6 years ago • 2 comments

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?

zbaylin avatar Dec 23 '19 05:12 zbaylin

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?

rgrinberg avatar Dec 23 '19 05:12 rgrinberg

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

pitag-ha avatar Jun 01 '21 08:06 pitag-ha