I know I know, s-exp are god, but I find some constructions hard to read, like those where the car are lists, like this:
(((alpha a b c) are letters) is a fact)
So, if you just put the car outside of the parentheses, you get something more readable, like:
alpha(a b c)(are letters)(is a fact)
The syntax would be
document = element*
element = word | structure
structure = element "(" element* ")"
but this is a case of left recursion. So I managed to find a small workaround. Here is a PEGjs syntax for it:
doc
= element*
element
= _ head:word body:block* _ {
var result = head;
for (var b of body)
result = { head: result, body: b };
return result;
}
word
= c:[a-zA-Z0-9]+ { return c.join(''); }
block
= "(" e:element* ")" { return e; }
_
= [ \t\r\n]*
When given this:
one two(foo) three(foo)(bar)
The parser yields this:
[
"one",
{
"head": "two",
"body": [
"foo"
]
},
{
"head": {
"head": "three",
"body": [
"foo"
]
},
"body": [
"bar"
]
}
]
Which is the result we want.
I think a decent minimalist programming language wouldn't need blocks at all, except to express data structures.
Here is a little html:
<div id="here" class="stuff">foo bar</div>
It turns into this:
div( id(here) class(stuff) )(foo bar)
Not bad IMO./
You understood correctly. Here is the translation:
( ((I) (am)) (letters) )
I()( am() )( letters() )