Sublime Forum

Need help with syntax highlights. Non capture groups[solved]

#1

I need a little help with my syntax definition for a custom language. In the language there are elements within a body of text that look like this:

[double bracket]] [single bracket]
In my definition file I use begin and end captures for these elements and then apply different highlighting to them and the stuff inside. The issue I’m having is that my regex is picking up the single square bracket elements first and ignoring the double square bracket elements. The regex for the single brackets is:

<key>begin</key>
<string>(\)</string>
<key>end</key>
<string>(\])</string>

The regex for the double brackets is:

<key>begin</key>
<string>(\\)</string>
<key>end</key>
<string>(\]\])</string>

Using the following regex for the begin of the single bracket lets the double bracket work, but it automatically picks up the second matched character as part of the group when I would expect it not to.

(\)^\]

I modified the regex to use a non capture group for the second character, but it still matches the second character.

(\)(?:^\])

I’m wondering if there is something I can do to get these to match properly.

0 Likes

#2

I think you need another order for your definitions.
If you ask for elements, which starting with the same character, you’ll need to ask at first for the element with the most number of this character at start.
All definitions are queried in the order in which they are contained in the file. If you ask first for double brackets and having no match, you can ask for single brackets. If the item starts with it, so it must be a single bracket item, because the double bracket issue in the quest before has failed.

0 Likes

#3

[quote=“BugFix”]I think you need another order for your definitions.
If you ask for elements, which starting with the same character, you’ll need to ask at first for the element with the most number of this character at start.
All definitions are queried in the order in which they are contained in the file. If you ask first for double brackets and having no match, you can ask for single brackets. If the item starts with it, so it must be a single bracket item, because the double bracket issue in the quest before has failed.[/quote]

Thanks. Changing the order of the includes did the trick.

0 Likes