Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 980
Tono Nam Avatar asked Aug 19 '16 02:08

Tono Nam


People also ask

How do you auto align in atom?

atom-alignment packageUse ctrl+cmd+a on Mac or ctrl+alt+a to align multiple matches. If you want to align the first match only, call Atom Alignment:Align from the command palette.

How do you color text in an atom?

Open a file written in the language that you want to specify the colors for in Atom. Put the cursor at the characters in an element that you want to change the color, pressing Ctrl + Alt + Shift + P (Windows …


1 Answers

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.

like image 133
Tono Nam Avatar answered Sep 19 '22 02:09

Tono Nam