SublimeText / PackageDev

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

Invalid illegal closing parentheses in extended regexp patterns #216

Closed deathaxe closed 5 years ago

deathaxe commented 5 years ago

Closing parentheses in extended patterns are highlighted as illegal even though ST accepts this kind of rule. May not be the best style, but works.

    - match: (?x:\b(
          badarg|badarith|badmatch|function_clause|case_clause|if_clause|try_clause|
          undef|badfun|badarity|timeout_value|noproc|nocatch|system_limit
        )\b)
      scope: constant.language.exception.reason
FichteFoll commented 5 years ago

This is hard to implement properly.

Multi-line plain scalars operate on indentation alone and are terminated once a token on the same level as the starting token is found (i.e. on the same level as match). Even if I were to omit this and start off by the indentation of the next line and terminate once I find a line with less indentation than that (which still breaks for this example), it is impossible to track both the indentation level and the regex groups levels.

Ideally, you'd just use block-style scalars for multi-line regular expressions.

However, I could see a way to only terminate a plain scalar when encountering a key or a list item on the next line. It wouldn't be entirely correct of course, but it would manage to fix this issue. Either way, considering how rarely this comes up and how small the inconvenience of having two invalid parentheses highlighted is, I'm not inclined to spend time on this.

deathaxe commented 5 years ago

I just realized it. It is of low priority. Wouldn't bloat or introduce too much complexity to handle this edge case.