How to inherit the default syntax-highlighting in captures?


#1

Hi,

I’ve been working on my language-unix-shell package and I want strings that appear after = in variable definitions to be syntax-highlighted in the ways defined earlier in the unix-shell.cson file. Unfortunately, no syntax-highlighting is being applied after the equal sign (=), with my current code, which is:

      {
        'begin': '([a-zA-Z0-9_-]+)=(.*)'
        'beginCaptures':
          '1':
            'name': 'variable.definition.name'
          '2':
            'name': 'variable.definition.equal'
        'end': ';|&|$'
        'endCaptures':
          '0':
            'name': 'punctuation.definition.function.shell'
        'patterns': [
          {
            'include': '#string'
          }
        ]
      }

Any ideas as to how to fix this problem? If you want to see an example of this lack of syntax-highlighting after the equal sign see this screenshot:

Thanks for your time,
Brenton


#2

Do you want variable.definition.equal to target the equals sign or the text after the equals sign?


#3

equals sign. But I want what comes after (which could include quotation marks) to be highlighted like it would be if it weren’t after an equal sign.


#4

Right now, 'begin': '([a-zA-Z0-9_-]+)=(.*)' catches all characters after the equals sign up to the end of the line. This includes the & and ; characters. To place your beginCaptures the way you want, you want the regex to be '([a-zA-Z0-9_-]+)(=)' Then everything between that and the end will be content, and matched against child patterns.


#5

Using that regex, namely with the code:

      {
        'begin': '([a-zA-Z0-9_-]+)(=)'
        'beginCaptures':
          '1':
            'name': 'variable.definition.name'
          '2':
            'name': 'variable.definition.equal'
        'end':  ';|&|$'
        'endCaptures':
          '0':
            'name': 'punctuation.definition.function.shell'
      }

isn’t providing syntax-highlighting for what follows the equal sign… See this screenshot, for example.


#6

You don’t have anything inside it. Try adding a 'contentName': '' line to style the stuff inside the begin and end patterns.