~pinkstringmachine


#247 Accessing the AST of the current macro and its uses (`assert-compile`) 2 months ago

Ticket created by ~pinkstringmachine on ~technomancy/fennel

This is a continuation from a conversation in the #fennel:matrix.org channel.

Some macros, e.g. no parameters, primitive parameters, etc., do not have an AST to pass to assert-compile, which limits its utility. Anecdotally, this limitation has meant that with several macros I've written, fennel-ls raises compile errors with code hints on the line where the macros are imported (import-macros), seemingly because it's unsure what line is relevant. My guess is that the primary use of assert-compile is to validate that the macro its called in is correctly structured as well, so I'm wondering if there are ways for us maximize for the presumably most common case.

Two potential options:

  1. The AST of the macro that is being evaluated is available for itself on the compile global environment, such that ast-source will give you the line and col numbers. This could then be passed into assert-compile if desired.
  2. If no AST is provided to a assert-compile call, it will default to the AST source of the macro from which it is called.

The nuances of whether or not we can expose AST information like that and what the consequences would be are beyond my scope of understanding, but I wanted to drop this in here for posterity. : )