Daily Thought - 2024-12-29
Hey, I'm Hanno! These are my daily thoughts on Crosscut, the programming language I'm creating. If you have any questions, comments, or feedback, please get in touch!
The new comments on branches required changes to the syntax. I want them to be associated with the branch in the syntax tree, so they can be used to generate documentation, for example. Or, as I've already done, to add metadata to branches for use in tests. Why did this require changes to the syntax? Consider this example:
my_function: fn
\ 0 ->
0
# This comment is part of the body of the first branch.
\ 1 ->
1
end
Versus this:
my_function: fn
\ 0 ->
0
# This comment applies to the second branch.
\ 1 ->
1
end
The parser ignores whitespace, and it doesn't look ahead beyond the next token
it's going to process (the grammar is
LL(1)). So it can't distinguish
between those two cases. To fix that, I required that branches end with end
,
like functions:
my_function: fn
\ 0 ->
0
# Now this comment can be clearly distinguished...
end
# ...from this other comment.
\ 1 ->
1
end
end
I thought that having the end
there made it look inconsistent, that branches
are started using an \
token. So I replaced that with the new br
keyword:
my_function: fn
br 0 ->
0
end
br 1 ->
1
end
end
The new syntax still looks weird to me, but that's fine. I've come to realize more and more, that everything I do syntax-wise before the code database exists, is temporary at best. But that's a topic for another day.
Hey, you! Want to subscribe to my daily thoughts? Just let me know (maybe include a nice message, if you're up for it), and I'll send you an email whenever I post a new one.