How to match install -X with one Less style and what comes after it with another?


#1

Hi,

I’m trying to improve on my language-shellscript fork, language-unix-shell and one thing I’d like it to do is syntax-highlighting install -X (where I have a set of lower-case letters X is allowed to be like y, f, h, m, etc.), with the support.function.packages.shell style I’ve defined in my stylesheet, and what comes after it (which hopefully should be package names like curl or wget), on the same line, unless the backslash operator (\) is specified (in which case it would follow onto the next line), with no style (i.e., I don’t want it to be syntax-highlighted, I just want it to assume the highlighting given to code unrecognized by the package). I’ve tried to do this myself with this code in my main grammar file for shell scripts (grammars/unix-shell.cson):

      {
        'begin': 'install -y'
        'beginCaptures':
          '0':
            'support.function.packages.shell'
        'name': ''
        'end': '$'
      }

(if the line where this piece of code was placed is relevant it’s line 1005-1012 — right after the patterns: [ line on L1004). This failed, as it gave no syntax-highlighting for either install -y or what came after it. See this screenshot for what I mean:

On line 4 you can clearly see where I tested it out.

Thanks for your time,
Brenton


#2

The beginCaptures array needs a name key for each entry, like so:

      {
        'begin': 'install -y'
        'beginCaptures':
          '0':
            'name': 'support.function.packages.shell'
        'name': ''
        'end': '$'
      }

#3

How do I write an 'end' field that matches $ if and only if it is not preceded by a \ (literal backslash, I know that in regexes \ is used to escape characters too, but in this case I mean a literal backslash that appears in my shell script)?


#4

The regular expression for that is (?<!\\)$ (you can check it out here), but whenever I try to insert that into your grammar, I get a syntax error because the backslashes are messing things up.

I don’t know. It might not be able to work exactly like that.