fypp icon indicating copy to clipboard operation
fypp copied to clipboard

expanding macro in include directive

Open ajshephard opened this issue 2 years ago • 1 comments

I wish to expand a macro in an include directive (to determine the file name). I have something like

#:set FILENAMES = ['file', 'anotherfile']
#:for FILE in FILENAMES
    ! some code
    ! now include a file
    #:include "${FILE}$.fypp"
    ! more code
#:endfor

This does not work, and fypp returns "include file '${FILE}$.fypp' not found". Is it possible to accomplish this? Thanks.

ajshephard avatar Apr 10 '22 02:04 ajshephard

Indeed, currently that is not possible. Include events are handled during parsing, before any evaluation of variables or even conditionals. For example

#:if defined("INCLUDE_ME")
  #:include "me"
#:endif

would always try to read the file me, even if INCLUDE_ME is not defined. But in that, case, the included content would not be evaluated.

In theory, one could change this behavior, but would need some coding, as the evaluation of the #:include directive would have to be shifted.

aradi avatar Apr 27 '22 09:04 aradi