I’m working with a simple language that defines tools. An example of the syntax is:
TOOL <name>
# tool definition here
END TOOL
I’ve written a custom syntax for this, and it works fine. The part I’m having trouble with is that the “END TOOL” is optional. For example:
TOOL abc
# definition for abc
TOOL def
# definition for def
END TOOL # for def
The idea is that a new “TOOL” declaration implicitly ends the old one. I can certainly write patterns in my custom syntax to match this, and highlighting works as expected. The problem is that in the latter case, “expand selection to scope” doesn’t work. If I have the cursor anywhere in either the abc or def definition, it thinks the enclosing scope is both abc and def. I’m guessing that the reason for this is that the scope for abc doesn’t end until the scope for def starts, so there is no character in the buffer that isn’t in the scope of some tool definition, so it seems that the “scope” includes both of them.
I could make the “TOOL” keyword itself not be part of the tool scope, which would fix this problem (because the old one would end before the new one starts), but I really would rather the scope include the TOOL keyword, too, if that’s possible.
Is there a way to define the syntax such that expanding the selection to the scope does what I want? I would imagine that this is is a general problem. For instance, you don’t know where a python function ends until something else starts (and I’ve noticed that the python syntax doesn’t seem to have a scope for function definitions, so I don’t see anything to pattern-match there).
Thanks.