I’m updating the syntax definition for the Just language. It’s very similar to Make, but it focuses on running tasks instead of building things.
Just has if
statements which require an else
condition: if "a" == "a" {"b"} else {"c"}
. You can also chain the if
statements. When chained, they look like this:
foo := if "hello" == "goodbye" {
"xyz"
} else if "a" == "a" {
"abc"
} else {
"123"
}
They can be on a single line or stretch across several lines as above. Furthermore, you can put if statements inside an interpolation block in a recipe:
bar foo:
@echo {{ if foo == "bar" { "hello" } else { "goodbye" } }}
Here is the code I have written to handle this syntax. With this code, nested if
s and interpolation both work well:
However, if
chaining does not work:
A recipe name should instead have a scope of entity.name.function.just
and some different contexts on the stack.
In looking to resolve this, I changed the push
on line 143 (in if-statements
) to a set
. That solved the chaining issue! However, now the interpolation is broken.
It seems like I may not be popping the stack enough or in the right places. Does anyone have ideas on how to go about fixing or even diagnosing this? I’ve been scratching my head and trying different things for hours, but I’m at a loss. It can be hard to think with the context stack when a bunch of contexts are popped (or supposed to be) going from one character to another.
The code is all in the repo above, and I have a bunch of tests. So if some angel were inclined to download the repo and run the tests in syntax_test_just.control_flow.just
, it should be easy to see the problem for yourself.
Two things I’m not sure about that could be relevant:
- Am I using the correct number of pops and in the correct place on line 194? (I tried lowering to 3 pops, and that didn’t pop enough.) Should that be a set?
- I notice that I’m using
include: if-statements
in one place, but thenset: if-statements
in another. This seems like a problem, sinceif-statements
is the context which is sticking around in the chaining failure screenshot above. Is the issue with how I’m adding it to the stack, or how I’m failing to take it off?