Sublime Forum

How to pop if nothing matches in syntax highlighting?

#1

I’m upgrading the “improved” Haskell syntax highlighter in the SublimeHaskell package. ST3’s approach is much improved over ST2, although having some kind of indent-based language support would be helpful in a future (ST4?) release.

My basic problem: Haskell function calls and detecting the end of the function call arguments. The number of terms is fairly extensive and it’s not easy to detect the end of the function argument list by a simple lookahead (?=) regexp.

Is there a relatively straightforward way to express “none of the above” in a match sequence? I originally toyed with the following, but it didn’t really work:

arg_pattern:
  - match: '{{var_id}}'
    scope: variable.generic.haskell
  - match: '{{qualified_type}}'
    captures:
      2: storage.module
      3: storage.module
  ## More match patterns
  ## ...
  ## None of the above?
  - match: ''
    pop: true
0 Likes

#2

Most of the time in cases like these, you want to pop if you see a non-whitespace character that doesn’t match any other pattern. So:

else-pop:
  - match: (?=\S)
    pop: true

arg_pattern:
  # rules...
  - include: else-pop
0 Likes

#3

@ThomSmith: Yup, that helped! Thanks!

0 Likes