I am working on a custom language syntax highlighting extension for VSCode. I am running into a problem where lookbehinds are behaving strangely when used next to whitespaces.
Example of code I want to highlight:
variableName :=thisValueShouldHighlight;
variableName := thisValueShouldHighlight;
variableName := thisValueShouldAlsoHighlight,
A sample of the code I am attempting to use (in tpl.tmLanguage.json
):
"end_variable_assignment": {
"comment": "Covers ending assignment of a value to a variable. IN PROGRESS",
"match": "(?<=:=)\\s*(\\w+)(;|,)$",
"name": "punctuation.accessor.tpl",
"captures": {
"1": {
"name": "entity.name.type.tpl"
},
"2": {
"name": "punctuation.accessor.tpl"
}
}
}
This pattern is included with (in another pattern, which is present throughout the file):
{
"include": "#end_variable_assignment"
}
The sticking point is the \\s*
part of the regular expression. You should be able to do var:=value
or var := value
or any number of spaces between :=
and value
, it doesn't matter how many. However, I get this when I try to use it:
variableName :=thisHighlightsProperly;
variableName := thisFails;
I have also tried just \\s
and \\s+
, and neither work. I've tried stupid examples to make sure my logic works by using some placeholder, like (?<=:=)#(\\w+)...
, and then tested it with var:=#value
, which does work... but it never works with spaces.
I don't understand why this is a problem, because I've used \\s*
elsewhere without any issues (just different circumstances). I don't believe it's a property problem because it works with everything except whitespace.
Additional info: I have tested this on RegexCoach and Regex101.com, and it works there.
For testing purposes, I have also included a testing example of the code that should highlight here: https://drive.google.com/open?id=1yoDXVxW3LFYjejW1wps8ENWUQ4iCal9w
This is the most minimal example I can provide of the code:
tpl 1.15 module Pattern_Module_Name;
pattern Pattern_name 1.0
triggers
on si := SoftwareInstace created, confirmed where name matches "(?i)SomeRegex";
end triggers;
body
// RE: STACKOVERFLOW PROBLEM
// As you can see, these aren't highlighting properly
var_name :=thisShouldHighlight;
var_name := thisShouldHighlightButDoesnt;
var_name := thisShouldHighlightButDoesnt,
end body;
end pattern;
All of my custom language code can be found on my GitHub: https://github.com/cdpautsch/vscode-tpl