BenjaminSchaaf / sbnf

A BNF-style language for writing sublime-syntax files
MIT License
58 stars 6 forks source link

Meta-scope from a subsequent rule applied to a previous rule #36

Closed eugenesvk closed 1 year ago

eugenesvk commented 1 year ago

I was surprised when some of the previous rules in a list of rules got scopes from subsequent rules

Below is a minimal reproduction: there are 2 rules with 2 scopes (one per rule). The issue is that the scope punctuation.separator.id from the second rule creeps into all the 2nd+ terminals in the 1st rule

main                          : type id;
type{scope_type}              : '\(' 'ttype' '\)' ; # 1a 'ttype)' also gets unnecessary punctuation.separator.id
#type{scope_type}             : '\(tty'    'pe\)' ; # 1b 'tty' only has its own scope, 'pe)' gets an extra
id{punctuation.separator.id}  : 'tid'             ; # 2

The test string is (ttype)tid, I'd expect

BUT for some reason rule 2 id also applies its scope to the text ttype) (except for the first match () that rule 1a already dealt with. (1b highlights that the issue seems to be with all the subsequent rules in 1a type, the first in the list is somehow special and not affected)

Is there a way to limit the damage from rule 2? If I wanted to attach a meta scope to (ttype), I'd just add it directly on the left hand side, and if I wanted to attach some scope to 2nd+ rules ttype and ) within 1 type, I'd do the same thing directly in the terminals