Poly definitions in separate files by output type
#111
Open
opened 3 years ago by bluebear94
·
9 comments
Loading…
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
Is it possible to define tags that depend on the output format by using a separate file for each format?
For example, if I specify
html
andtex
output formats, then can I put the HTML-specific definitions inpollen-html.rkt
and the LaTeX-specific definitions inpollen-latex.rkt
, including whichever file is appropriate for the output?I'd imagine that to do this, you'd need to:
pollen-html.rkt
andpollen-latex.rkt
at phase n+1The disadvantage is that the generated functions in the main
pollen.rkt
wouldn't be able to know what signature to expect, so errors having to do with signatures would blamepollen.rkt
and not the calling code. Exported non-function variables (such as(define br '(br))
wouldn't play well with this approach as well; they'd have to be re-exported as functions, requiring existing code to be changed.Alternatively:
pollen-html.rkt
andpollen-latex.rkt
at phase n+1but this requires the arguments to be valid X-exprs, so I'm not too keen on that.
If stuff that you are gonna import are run-time definitions, you can use
dynamic-require
, FWIW.I'm not getting much luck using
dynamic-require
from Pollen:pollen.rkt:
pollen/common.rkt:
This works fine when imported from a .pm file in the project root, but from a file in a subdirectory such as
grammar/index.html.pm
, thedynamic-require
tries to require the module atgrammar/pollen/common.rkt
.And now I have a proof of concept. Perhaps the grossest thing I've done in Racket.
current-load-relative-directory
is currently parameterized to a hard-coded path; I'm still looking for a way to avoid the hard-coding.As I've mentioned earlier, we can't
require
pollen/setup
for syntax because if we did, then loadingpollen.rkt
would requirepollen/setup
when compiling which depends onpollen.rkt
for the setup parameters ad infinitum. This also prevents us fromrequire
-ing any Pollen-related modules inpollen/html.rkt
orpollen/tex.rkt
.Can you use
define-runtime-path
to solve the wrong directory problem?Perhaps, but I don't think it'll solve the import cycle.
I think this is the most promising approach that I have come across: https://github.com/otherjoel/thenotepad/tree/master/pollen-local
It does some trickery with defining the functions according to a naming scheme, so it doesn't go by file itself but allows for separating it that way. I'd suggest at
polytag.rkt
, where the macro is defined, then the actual tag functions are in other files.I have a slightly more evolved version of that approach here: https://thelocalyarn.com/code/file?name=pollen.rkt&ci=tip