Welcome to the Tsonnet series!
If you're just joining us, you can check out how it all started here.
In the previous post, we covered pretty-printing the JSON output:
Now, it's time to flex our string muscles with concatenation!
Jsonnet uses the plus operator for concatenating strings. Since we already added support for binary operations, implementing string concatenation is surprisingly straightforward. We just need to pattern-match on BinOp(+, String, String)
and return a new value with the two strings combined. Easy-peasy -- our lexer and parser already handle expr + expr
.
Here's the sample Jsonnet file, the cram test, and the implementation:
Pretty boring, right?! But that's all there is to it -- for now! We'll talk more about string concatenation soon.
Next time, we'll take a closer look at the exception handling in our interpreter -- exceptions are a bit fishy, and we can definitely do better!