Sublime Forum

Inner pattern swallows end tag in begin/end definitions

#1

Consider this example

- name: foo.bar begin: /\* end: \*/ patterns: - name: baz.foo.bar match: \*.*\*

This causes the inner pattern to swallow the ‘*’ part of the end pattern - preventing it from being closed. This is not the documented behavior: inner patterns are supposed to be matched between begin and end.

Is this a bug or am i doing something wrong? Thanks

0 Likes

#2

you might want to use positive lookahead

0 Likes

#3

You need to adjust your mental model of how the begin/end rules work. Here’s what really happens:

  1. The ‘/*’ text from begin is matched. The patterns are pushed on the stack.
  2. Each pattern is applied in order. The topmost pattern has the highest precedence. The \*.*\*
    regex will consume text all the way to the * in the */ end-comment token. There
    is only the last / character for additional patterns or the end regex to consume.
  3. The end regex fails to match */, because there is only / left. Therefore, the
    patterns are never popped off the stack and the begin/end rule doesn’t end where you
    think it should.

tl;dr The end regex will only be applied after the patterns, so it’s possible for the
patterns to break out of their cage.

0 Likes