-
Notifications
You must be signed in to change notification settings - Fork 701
Description
...I'm just thinking from the syntax side, but not being experienced in compiler. I will just discuss on the syntax side.
I made a video to demonstrate the main ideas behind Cirru:
https://www.youtube.com/watch?v=1ShYO_A8g-0 (14mins)
Short version:
- Cirru is trying to build a syntax tree that we can edit directly
- that syntax tree has a text syntax, with parser and formatter
- that text syntax is based on indentations
- I've been thinking about it for several years and have been using it for months
For Cirru code like this:
defn add2 (x y) (+ x y)it is equivalent to a piece of data in JSON:
["defn", "add2", ["x", "y"], ["+", "x", "y"]]once you get JSON you are free to make an DOM editor or simply render to HTML/CSS:

and also it can be turned back to Cirru code as you want.
Check these links if you need details.
http://cirru.org/
https://github.com/Cirru/
https://twitter.com/cirrulang
https://github.com/Cirru/cirru-wasm-ast (mostly based on @indutny 's work)
https://github.com/Cirru/cirru-wasm-cli
From my side I got some experience using Cirru:
Pros
- Preciously we are programming by manipulating text files, we all say it's about AST, which is a tree, but we need the help of text syntax to do it. Some languages pushed syntax even further and it becomes hard for newcomers to pick up. Cirru is giving more possibilities. I mean we can manipulate the syntax tree directly now.
- Cirru syntax is simple. It's based on indentations and reduced the usage of parentheses a lot.
- Cirru syntax is flexible. When recovered from binary files, it can be turned into serveral styles of text form, such as "smart folding look like human wrote it", "expression unfolded for the purpose of add break points", "tree view for a better user interface", etc.
- I've been generating my JavaScript code and ClojureScript code in Cirru for many months, the syntax is quite handy now.
Cons
- People hate to learn one more syntax, what's worse, it's different from C, Java or Python.
- String syntax in Cirru can be confusing according to my experience introducing Cirru to others. Because Cirru was originally designed as a tree editor and people does not quote marks in a tree editor.
- After Cirru code is parsed into a tree, we need another step to turn that tree into an AST. I'm not quite clear about how compilers will handle this. So I'm not sure it's good or bad.
- I think we don't have very much experience programming with a tree rather than a text file. Our toolchains are mostly based on text files.
Even if we don't want the graphical part of CIrru, we can still try its text syntax. It's basic Lisp in indentations(with string syntax a bit strange):
https://gist.github.com/jiyinyiyong/0fc58e2ed7c641973d9b
module
export :even $even
export "odd" $odd
func $even (param $n i32) (result i32)
if (i32.eq (get_local $n) (i32.const 0))
i32.const 1
call $odd (i32.sub (get_local $n) (i32.const 1))
func $odd (param $n i32) (result i32)
store_global $scratch (get_local $n)
if (i32.eq (get_local $n) (i32.const 0))
i32.const 0
call $even (i32.sub (get_local $n) (i32.const 1))
global $scratch i32I'm a big fan of Lisp(mainly Clojure), but dislike the parentheses in Lisp. So this is my idea to fix it and that in WebAssembly.