SublimeText / PackageDev

Tools to ease the creation of snippets, syntax definitions, etc. for Sublime Text.
MIT License
436 stars 83 forks source link

Capture highlighter does not ignore look-ahead groups #114

Closed FichteFoll closed 7 years ago

FichteFoll commented 7 years ago

sample

via https://github.com/SublimeTextIssues/Core/issues/1796#issuecomment-312920245

evandrocoan commented 7 years ago

This is not a bug as we can see from this example,

sublime_shell

Sublime Text is accepting capture groups inside look ahead. You can try it out with (look)(?=(ing))\2, which makes Sublime Text to correctly apply scopes for the capture group inside the look ahead:

%YAML 1.2
---
name: test
scope: source.syntax_name

contexts:
  main:
    - match: '(look)(?=(ing))\2'
      captures:
        1: first.looking.assignment
        2: second.looking.assignment
      push:
        - meta_scope: third.looking.assignment
        - match: '(?=ing)'
          scope: forth.looking.assignment
        - match: ''
          pop: true

Sublime text is just not applying any scope to the text if the text is not eaten by the regular expression. Here bellow we see the scopes being correctly applied by Sublime Text one the `\2 was introduced to the original regular expression.

sublime_shell

sublime_shell

  1. https://regex101.com/r/UlNaHg/3
FichteFoll commented 7 years ago

Via https://github.com/SublimeTextIssues/Core/issues/1796#issuecomment-313269920, this is actually the proper behavior and thus not a bug.