Auto-mapping HTML/x-expressions back to Pollen markup
#99
Open
opened 4 years ago by otherjoel
·
2 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?
This isn’t a support question, just an idle question that I’m throwing out there in case anyone has insight.
Any given
pollen.rkt
is basically a kind of one-way map of marked-up text → x-expressions. For example, a tag function might map◊youtube-embed[...]
to'(iframe [[src "…"]] …)
. But it’s one-way; there’s no function for mapping theiframe
x-expression back to the markup that would generate it (unless you write one).What would be an approach for automatically building, given a set of tag functions, some way of mapping in the reverse direction? So that you hand it your
pollen.rkt
and, e.g., a set of HTML files, and it produces the equivalent Pollen markup? That is, not just the Pollen syntax equivalent of the HTML as-is, but using the custom tag functions found in thepollen.rkt
? I know I could just manually write a set of complementary “reverse tag functions” for each tag function, but it seems like in principle this is something a Racket program should be able to figure out from the one-way map I’ve already given it.This question occasioned by the idea of reverse-converting a bunch of old HTML files back into a Pollen ur-format.
it should be doable if your tag functions are simple enough (like in the example you gave), but if you don't restrict what they can do (giving up Turing completeness) it's impossible to find an inverse algorithmically. e.g., if two tag functions end up mapping to the same X-expression, there's no way to know which one originated it (although in this case maybe you could just pick any of them, I guess). so you'd want a
#lang invertible-pollen
or something!you can search for bidirectional parsing/serialization libraries for solutions to a similar enough version of this problem! looking at it abstractly, GF also does something similar
Racket’s web server library has a facility for defining bidirectional server routes. Meaning, you define a single pattern and get two functions back: one that parses a route into arguments, and one that takes the arguments and generates the route. Maybe some ideas there that are worth stealing.