The appelt priorities work only for the same regions of text (e.g. earlier match wins and longer match wins). Text consumed by a previous rule cannot be matched by a later rule...
From the documentation:
With the appelt style, only one rule can be fired for the same region
of text, according to a set of priority rules. Priority operates in
the following way.
- From all the rules that match a region of the document starting at
some point X, the one which matches the longest region is fired.
- If
more than one rule matches the same region, the one with the highest
priority is fired
- If there is more than one rule with the same
priority, the one defined earlier in the grammar is fired.
...
Note also that depending on the control style, firing a rule may
‘consume’ that part of the text, making it unavailable to be matched
by other rules. This can be a problem for example if one rule uses
context to make it more specific, and that context is then missed by
later rules, having been consumed due to use of for example the
‘Brill’ control style.
The rule TableRow
can win as longer with following modification, note that I added the :tableRow
label, which does not include the leading number token.
(
({Token.kind == number})?
(
({Lookup.majorType == "keyword"})
({Token.kind == punctuation})[0,4]
({Lookup.majorType == "unit"})
):tableRow
)