Sublime Forum

Syntax bug, sort of

#1

Hi

When updating a syntax, I encountered a behavior with prototypes that may not be obvious at first. At the line 49 I match a heredoc’s beginning and set the new context that will change based on the escaped character or embedded variable.

The problem is the prototype, ideally I would write it like so:
`

  • match: (?i)^\1;$
    scope: >-
    string.unquoted.heredoc.php.7
    punctuation.delimiter.string.end.php.7
    pop: true
    `
    using the capturing group matched in the line 49 but as soon as I set a new context, the group becomes null. I understand why this behavior occurs, as sublime will:
    1: Embed the prototype into the contexts
    2: Resolve the groups when the match is executed

Can it be reversed in a sublime’s new version?
1: Resolve the groups at the declaration of the prototype
2: Embed the prototype with the groups resolved into the contexts

It would make more sense since we declare the prototype immediately after the parent match.
Thanks

1 Like

#2

This is currently not implemented on purpose, due to performance reasons. with_prototype clones an entire context (and all included contexts) and prepends match rules to them. It then compiles all of those rules and regexes into an efficient representation that we can use for tokenizing. It effectively saves a bunch of copy-paste for the syntax author.

Performing that operation with a string extracted from another regex pattern, in the middle of tokenizing, could cause significant performance issues during tokenizing.

The reason it is allowed in a normal context is that it only results in a single regex to be compiled on the fly, not a whole new tree of nested contexts each containing the regex.

3 Likes