[TxMt] Re: formal definition of scope selector syntax?
Allan Odgaard
mailinglist at textmate.org
Thu Jun 26 19:26:18 UTC 2008
On 25 Jun 2008, at 21:07, Matt Neuburg wrote:
> In the Help for TextMate, the following are given as examples of legal
> selectors (with explanations of what they mean / match):
> [...]
> Then, in a blog entry
> (http://blog.macromates.com/2005/introduction-to-scopes/),
> additional info
> is given:
>
> (a | b) & c - d
>
> I find that last one incoherent; I don't get where the pieces are or
> how the
> operators here fit, priority-wise, with the previously given
> operators. For
> example, which of the selectors given in the first list would be a
> legal
> substitute for "b" here? And conversely, for which expressions in
> the first
> list of legal selectors, if any, could this expression be substituted?
>
> So, my question is: Can I somewhere get a formal coherent definition
> of the
> rules of selector syntax?
I’ll see if I can’t add a BNF section to the manual. I won’t be
online for an unknown amount of time, so not sure when I will push this.
As for your concrete question, in the last example you quote, a, b, c,
and d can all be scope selectors of the form given in the manual
section 13.1 or 13.2 (13.1 being a subset of 13.2).
So scopes are matched literally (e.g. “string”). These can form a
“descendent selector” (13.2) e.g. “source.ruby string”, and for
descendent selectors one can take the union (| or ,), the intersection
(&), or the asymmetric difference (-).
As for the exact precedence of these operators, I’ll have to check
the grammar in the source, but one can also group with parenthesis.
The reason though that both , and | can be used for union is that ,
was introduced long before the other operators (mimics CSS syntax), so
when & was added, I felt that there should be | and | has higher
precedence than , it is the operator with lowest precedence, so e.g.:
a - b | c & d, e - f | g & h ⇔ (a - b | c & d), (e - f | g & h)
A bit like | versus || in C.
More information about the textmate
mailing list