from perplexitywrite an example of how to get this information from a extension
To access information from an OCaml extension using ppxlib, you can define a simple extension that utilizes the Expansion_context.Base module to retrieve context information. Here's an example:
open Ppxlib
let my_extension =
Extension.declare
"my_extension"
Extension.Context.structure_item
Ast_pattern.(pstr nil)
(fun ~ctxt:_ ->
let context = Expansion_context.Base in
let code_path = Expansion_context.Base.code_path context in
let input_name = Expansion_context.Base.input_name context in
let tool_name = Expansion_context.Base.tool_name context in
Printf.printf "Code path: %s\nInput name: %s\nTool name: %s\n"
(Code_path.to_string code_path) input_name tool_name;
[])
This example defines a simple extension my_extension that prints the code path, input name, and tool name from the expansion context. You would register this extension with the Ppxlib.Driver to use it during preprocessing.
from perplexitywrite an example of how to get this information from a extension
To access information from an OCaml extension using
ppxlib
, you can define a simple extension that utilizes theExpansion_context.Base
module to retrieve context information. Here's an example:This example defines a simple extension
my_extension
that prints the code path, input name, and tool name from the expansion context. You would register this extension with thePpxlib.Driver
to use it during preprocessing.