I am using VScode and create my own language extension to highlight syntax, where I need to use regular expression to find the comments.
The basic rule is that everything after !
is a comment, however there is a special case. When !
is inside eval()
command, it means NOT.
For example some of my code would look like:
if condition=(eval(!DB_EXIST)) ! this is a comment
(eval( !DB_UPDATED && !DB_EXIST)) !---"!" inside eval() means NOT
!this is another comment
<some commands> ! this is also a comment
The !DB_EXIST
in line 1 and 2 should not be interpreted as comments, and !
will be followed by a non-space.
Whitespace doesn't matter in comments.
"comments": {
"patterns" [{
"match":"regex1",
"name":"comment"
}]
},
"operator": {
"patterns" [{
"match":"regex2",
"name":"keyword.operator.NOT"
}]
},
What kind of regex 1 and 2 should I use to show different color for comments and NOT?
I am not good at this extension writing, so if there is any better way to do the job I will be very appreciated to hear. Thanks!
Update
@Gama11 helped me but I didn't completely cover all the case in my code samples. Any non-sapce after "!" should also be comments, as long as "!" is not inside eval().