4 ms·
Very nice little article! Learned some new terms. To anybody dabbling as I do in syntax design, who may be looking for an extremely minimal representation for
by djedr 4y ago
Very nice little article! Learned some new terms.
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 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. ;D
To 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!
- nathell 4y agoI thought “what a weird name”, then silently pronounced it and my Polish ear heard “drzewko”, meaning “little tree”. What a fitting name. :)
- djedr 4y ago:) 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.
- znkr 4y agoThis is very beautiful, nice work. I wonder if I should use it for something...
- djedr 4y agoThank you. :) > 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/681e0199859874b3324eaa84192c4210 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 https://github.com/jevko/queryjevko.js Or make up a markup DSL: https://github.com/jevko/markup-experiments#asttohtmltable 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 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/parsejevko.js / https://github.com/jevko/specifications/blob/master/spec-standard-grammar.md https://github.com/jevko/specifications/blob/master/spec-sta...
- abathur 4y agoThis reminds me of Breck Yunits' Tree Notation (https://treenotation.org/ https://treenotation.org/). Both seem to have a ~totalizing energy. Maybe some common cause. :)
- djedr 4y agoIndeed, it's close. Obviously mine and Breck's levels of appreciation for indentation/brackets are very different. ;) Although independent, the paths we have taken to arrive at these are somewhat similar (somewhere early in there are experiments with visual programming). As are the tools of thought (minimalism). We were thus taken to similar places. 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...
- abathur 4y agoI agree that it feels like multiple projects are converging on something that is ripe (or close). 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 https://twitter.com/abathur/status/1582492437984837632) You may have already seen it as well, but you might also find https://github.com/teamtreesurf/link https://github.com/teamtreesurf/link interesting.
- djedr 4y agoNice list! I haven't seen any of these before. Link Text is particularly ~~spooky~~ interesting to me, as it quotes Tao Te Ching. :O See https://news.ycombinator.com/item?id=33251715 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_I_Ching https://en.wikipedia.org/wiki/Binary_number#Leibniz_and_the_... Pretty fun to think about.
- justinpombrio 4y agoCould you write that example as an s-expression? I can't quite parse it.
- djedr 4y agoSure. This is translated straight out of SICP 3.5.1[0]: (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/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-24.html#%_sec_3.5.1 https://mitp-content-server.mit.edu/books/content/sectbyfn/b...
- emmelaich 4y agoI like the idea of [] rather than {} or (). Saves using the shift key!
- djedr 4y agoGlad you like it. That's the intention. ;)
- kenshoen 4y agoSo is it a sintax for n-ary trees? Nice! newtype Jevko = Jevko ([(String, Jevko)], String)
- djedr 4y agoIndeed that's a useful way to look at it and a type definition that'll do the job of storing Jevko parse trees. See also: https://xtao.org/blog/rose.html https://xtao.org/blog/rose.html
- mcluck 4y agoI just want to tell you that Jevko is quite a fun little language you've built. I just threw together a parser for it in TypeScript (I'll upload it to Github eventually haha). It was super easy. I'm going to recommend it to my friends who aren't as excited about parsers and things as me for an introduction to parsing programming languages.
- djedr 4y agoThank you, I'm very happy to hear that. :) 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 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!