by djedr · 4y ago · 0 comments
To anybody dabbling as I do in syntax design, who may be looking for an extremely minimal representation for trees (even more minimal than S-exprs!) I would like to introduce my little project called Jevko: https://djedr.github.io/posts/jevko-2022-02-22.html
It is pure distilled treeness. Its grammar fits into one line, if compressed well:
Jevko = *("[" Jevko "]" / "`" ("`" / "[" / "]") / %x0-5a / %x5c / %x5e-5f / %x61-10ffff)
This took me years of syntax golfing to figure out. I think it's turned out pretty nice. It's complete, formally defined, with a few simple parsers written, except it has no users. ;DTo relate back to the article, an interesting and AFAIK original feature of this syntax is that newlines or other whitespace are neither significant nor insignificant nor "possibly significant" in Jevko. I'd call it whitespace-agnostic. Various whitespace rules can be laid on top of it, producing for example a Lisp-like language with native multiword identifiers with spaces, e.g.:
define [sum primes [[a][b]]
accumulate [
[+]
[0]
filter [
[prime?]
enumerate interval [[a][b]]
]
]
]
here "sum primes" and "enumerate interval" are two double-word identifiers. It's the only right_solution to the identifierWars, I-tell-you!For a long time I couldn't find the right name that would express the generic nature of it.
An earlier prototype was called TAO, as an acronym for Tree Annotation Operator (it had an extra feature called operators), and as a reference to the ancient Chinese concept, in essence nameless and by design hard to pin down -- this seemed to fit perfectly.
However there is about 2^42 cowznofski potrzebie things called TAO (kind of ironic, as the original idea was that the Tao would be distinct from the countless named things), so it turned out to be a bad name after all. So I decided to find a more unique one and here we are.
The amount of time spent thinking about this and the lengths I went to are better left untold.
In other words, naming is hard.
Ease of implementing is a goal, so that there is minimal friction when porting into any language.
This reminds me that I should finish this tutorial: https://github.com/jevko/tutorials/blob/master/parser.md
I hope you can get your friends excited! ;)
I'd really love to see folks put Jevko to use!
Before I was aware of the existence of Tree Notation I put my syntax online at tree-annotation.org (now defunct), so even naming converged. I was initially very confused myself. :D
Ultimately I think that the existence of multiple incarnations of this idea suggests that there is (perhaps a very niche) need for a minimal syntax like this. Something like S-exps, but general-purpose. Trying to satisfy that need is the common cause.
The way I imagine it is that it would be supported across programming languages, like JSON. It could be an universal format for (tree) structured data. There is this piece of the Unix philosophy which says that text streams are the universal interface. That's true on a certain level. On another level not far below binary streams are the universal interface. On another level not far above... there was nothing universal until XML. But that was overkill, so JSON displaced it. But that's still overkill, so...
I have done some deep-digging for markup languages and came across more than one project in this space. (I've added Jevko to my list; https://twitter.com/abathur/status/1582492437984837632)
You may have already seen it as well, but you might also find https://github.com/teamtreesurf/link interesting.
Link Text is particularly ~~spooky~~ interesting to me, as it quotes Tao Te Ching. :O
See https://news.ycombinator.com/item?id=33251715
Maybe it should become recommended reading for minimalist syntax designers. :D
The spirit that lives in the computer must be the same one as the one in the Chinese classics.
The universal interface below text streams was also somewhat inspired by one:
https://en.wikipedia.org/wiki/Binary_number#Leibniz_and_the_...
Pretty fun to think about.
newtype Jevko = Jevko ([(String, Jevko)], String)See also: https://xtao.org/blog/rose.html
> I wonder if I should use it for something...
I'd be honored!
A couple of ideas:
How about a simple configuration format? https://gist.github.com/djedr/681e0199859874b3324eaa84192c42... (I should make a library out of this)
Or you can put it in your query strings to make them more humane: https://github.com/jevko/queryjevko.js
Or make up a markup DSL: https://github.com/jevko/markup-experiments#asttohtmltable
Or serialize game objects in your indie game. Or make it the interface of your experimental app. Or use it to shave off a few unnecessary characters off your data: https://jevko.github.io/compactness.html
No parser in your favorite language? A basic one should be only a couple dozen lines! https://github.com/jevko/parsejevko.js / https://github.com/jevko/specifications/blob/master/spec-sta...
(define (sum-primes a b)
(accumulate +
0
(filter prime? (enumerate-interval a b))))
If you have an S-exp parser built into your optical nerve (to paraphrase L. Torvalds), it will be indeed hard to parse.The translation rules for an S-exp are roughly:
1. switch to square brackets
2. surround all symbols except the first in brackets
3. move the first symbol outside the opening bracket
4. replace dashes in symbols with spaces
5. leading and trailing whitespace doesn't count into a symbol.
That's basically it.
Besides that indentation and closing brackets are written C-style rather than Lisp-style.
Now the real confusion might begin if you have an S-exp with an S-exp as the first element like:
((fnr) 1 2)
This would translate to: fnr[][[1][2]]
which is... interesting.Anyway, this is just a theoretical example to demonstrate the whitespace-agnosticism. I have not implemented this particular language. But it's one way to arrange these trees into a Lisp-like language, if one was so inclined.
The cool thing is the simplicity and identifiers with spaces. Not cool, besides unfamiliarity, is the verbosity compared to regular S-exps (more brackets).
[0] https://mitp-content-server.mit.edu/books/content/sectbyfn/b...