In an Atom package, how do I overllap patterns in a grammar?
Asked Answered
S

1

8

I want to go further and style more things. For example I will like to style the following:

setting1 = 4
setting2 = 192.168.1.12
etc...

I will like to style everything to the left of the = blue and everything to the right purple.

The problem is that atom regex engine does not support negative look ahead or positive look ahead. As a result, I have tried using the begin and end directives but that still does not work. In other words I have tried:

{
  # section reference
  'begin': '^\\s*.*?=' # match a line that contains an = sign
  'end': '.+$' # continue until the end of the line
  'match': '^\\s*[^=]*'  #only match everything that is not an equal sign 
  'name': 'blue' #style it with the blue style
},

So basically, I need it to look like this:

enter image description here

Any ideas?

Solvent answered 19/8, 2016 at 2:47 Comment(0)
S
3

I came up with this solution: (reules.cson)

'scopeName': 'source.conf'
'name': 'CONF'
'fileTypes': ['CONF']
'patterns': [     
  {
    # equality
    'match': '(?x) ^ ([^=;]+) (=)  (.+?)\\n'
    'captures':
      '1' :
        'name' : 'blue'
      '2' :
        'name' : 'yellow'
      '3' :
        'name' : 'purple'
  }

]

You can style every capture differently.

Solvent answered 19/8, 2016 at 4:36 Comment(1)
An fyi: If you don't match ([^=;]+), a required amount of text, you can never match (=) (.+?) also required. And visa-versa. At minimum, you should change it to '(?x) ^ ([^=;]+) (=) (.*)\\n?'.Parietal

© 2022 - 2024 — McMap. All rights reserved.