[SVN] Naming considerations for language elements/rules

Allan Odgaard allan at macromates.com
Wed Feb 23 12:55:44 UTC 2005

In the Ruby syntax file, interpolated code in strings is named: 
strings.interpolation.ruby (the same probably holds for other 

While we can use “strings.interpolation” as a selector to target 
interpolated code in strings, there is the problem that the selector 
“strings” will also match, and with the same precedence.

Currently my algorithm for deciding on precedence is this:

Assign the score 2^i to each element in the path, where i is the index 
of the path. E.g.:

  foo bar fud
  2^0 2^1 2^2
    1   2   4

If the selector is a subset of the path then add the score for each 
path element matched, where the selector element only needs to be a 
prefix of the path element, and of course maximizing the score.

So if we have path: A B C A and selector A, it gets 8 points (matching 
the last A, and not the first, which would only give a score of 1).

For the selector A C the score would be 5 and so on.

So back to the problem: the problem is that with the current naming of 
interpolated code in strings, it is not possible to assign anything 
special to these, since everything assigned generally to strings, will 
have the same precedence (a tie breaker might be the ordering that they 
appear in in the style sheet, but e.g. for scope that won't exist, and 
it would be best not to rely on this ordering too much).

So I'd suggest that we do not use “strings” as a prefix for stuff 
inside strings. A general selector of “strings” will still match the 
stuff inside strings, since this appears higher up in the path.

Does this make sense?

Just for clarity, here's a piece of text in a HTML file:
  <%= "foo #{ 42 }" %>

This gets tokonized into:
  1: <%=
  2: "foo
  3: #{
  4: 42
  5: }
  6: "
  7: %>

And the path for the most nested token (#4) is:

FYI: While it may look inefficient, most paths can be represented with 
a single integer, including this one.

Additionally I should add:
  1) there is a new key in syntax files so that captures can be named and
  2) it is possible to use > in the selector to require something be the 
direct child, using this at the begin/end of the selector means there 
is no parent/child, e.g.: “> source” or "strings >", first matches only 
paths where source is the first element (unlike in the example above) 
and the latter matches paths where strings is the last element in the 
path (again, unlike token #4 above, but would match #2, #3, #5, and 

More information about the textmate-dev mailing list