Sublime Forum

SublimeSyntax capture group regression?

#1

Prior to a recent dev channel release (I’m afraid I’m not sure which), the following context worked as expected in ST:

regex_AFTER_PATTERN:
  - meta_include_prototype: false
  - match: >-
      (?x) ((
        ([gimyu])
        (?:
          (?!\1) ([gimyu])
          (?:
            (?!\1|\2) ([gimyu])
            (?:
              (?!\1|\2|\3) ([gimyu])
              (?:
                (?!\1|\2|\3|\4) ([gimyu])
              )?
            )?
          )?
        )?
        ))
        {{idEnd}}
    captures:
      1: string.regexp.js keyword.other.js # ^BS
      2: string.regexp.flags.es
    pop: true
  - match: '\w+'
    scope: invalid.illegal.token
    pop: true
  - include: else_pop

That was great; it followed the grammar perfectly. It would match “gim” or “mig”, and it would capture the “gi” in “gig”, but the second “g” was correctly scoped as an invalid token.

Something’s changed – this pattern no longer seems to work as of a recent ST3 dev channel release. It now matches only single character flag sequences; anything else is invalid. Are we no longer using Oniguruma?

0 Likes

#2

Back references are not supported in pop matches; in this context they’ll always refer to the corresponding capture in the push match.

0 Likes

#3

So the workaround would be to instead “set” an anonymous context that immediately pops (by matching an empty string?

0 Likes

#4

Thanks JPS / FichteFoll. Setting to an autopop context worked, but I also needed to adjust all the references by +2, which made me wonder if that means in-match references could break depending on how the context was entered? i.e. would the number of ancestral matches make it so you can’t depend on in-match backrefs in such cases? Sorry, I’m an idiot, I just realized there were indeed two outer captures, which accounts for the needed offset. Though I wonder why it worked prior to these changes at all, then…

0 Likes