Extended syntax in Pollen? (e.g. begin/end)
#147
Closed
opened 7 years ago by daantjie
·
10 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?
What capability is there for extending the Pollen syntax; e.g. adding LaTeX-style
◊begin{...}/◊end{...}
syntax:versus
Or using more Unicode characters to do create a more readable
itemize
syntax:instead of
I wouldn’t call this extending the syntax, exactly — you’d just be using
decode-elements
to pick out thebegin
andend
markers, and gather the elements between, for instance —Result:
For another approach using whitespace instead of
◊item
, seedetect-list-items
in thepollen-tfl
sample project.Thanks for the speedy reply! I'd thought (with mounting dread) that I'd need to extend Pollen's reader to pull something like is off – so it heartens me to find that it's actually rather easy. Thanks also for the link to the sample project. ;)
BTW you can generalize the
start
/end
detection with a macro, e.g. —BTW2 the disadvantage of this approach vs. using tag functions is that it’s less composable. Meaning, when
◊itemize
is a tag function, it can be used anywhere in the document. Whereas with this “flag” approach,◊itemize
relies on cooperation with theroot
tag (and thus◊itemize
could not be used inside other tags).If you wanted every
◊start{foo} ··· ◊end{foo}
block to be interpreted as◊foo{···}
, no matter where it appears, then you’d need to extend the reader.Another way to write the loop:
Okay, two questions then:
◊root
tag come from outside the source file? I.e., could I load a pollen file into a(root ...)
txexpr? (So that the file wouldn't be cluttered with an all-encompassing◊root{···}
.)No idea. Pollen relies on the @-reader. Though I have a few minor quibbles with the @-reader, I’ve found it’s wiser to overlook these so that Pollen remains consistent with the @-reader (the same is true of X-expressions).
I don’t know how long you’ve used the @-reader, but if the answer is “not long”, I’d gently recommend giving it a try before attempting surgery. The idea of
begin / end
blocks goes against the grain of how S-expressions work.Right, that’s ordinarily how Pollen works — the
root
wrapper is implicitly added. In this example, I’m just including it for clarity.BTW here’s an example of why
begin / end
blocks are difficult to get right — what should happen in this example? Whereas with the @-reader, this can never happen.You're right in guessing that I haven't used the
@
-reader for long! (Though I'm used to S-expressions, coming from a Common Lisp background – it was in fact Pollen which drew me to Racket.) To me, the example you give above should just barf – but given thatroot
is added implicitly anyway (allowing for these sort of additions), that seems like a much cleaner solution than messing with a perfectly good reader.Thanks for all your help on this! (I don't think I've ever seen such an engaged maintainer…)
Unlike many OSS maintainers, 1) I use Pollen every day 2) I make money from it 😉