Auto-mapping HTML/x-expressions back to Pollen markup #99

Open
opened 4 years ago by otherjoel · 2 comments
otherjoel commented 4 years ago (Migrated from github.com)

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 the iframe 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 the pollen.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.

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 the `iframe` 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 the `pollen.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.
odanoburu commented 4 years ago (Migrated from github.com)

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

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](https://www.grammaticalframework.org/) also does something similar
mbutterick commented 4 years ago (Migrated from github.com)

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.

Racket’s web server library has a facility for defining [bidirectional server routes]( https://docs.racket-lang.org/web-server/dispatch.html?q=bidirectional#%28form._%28%28lib._web-server%2Fdispatch%2Fextend..rkt%29._define-bidi-match-expander%29%29). 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.
This repo is archived. You cannot comment on issues.
No Milestone
No project
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: mbutterick/pollen-users#99
Loading…
There is no content yet.