Sublime Forum

[SOLVED] Syntax word boundary matches with regex extended form

#1

I need to match set export but not set exported in my syntax. I have this code:

variables:
  boolean_settings: |
    (?x)
     dotenv-load | export

contexts:
  settings-boolean:
    - match: '\b{{boolean_settings}}\b'
      scope: entity.name.definition.just
      push:
        - constant-boolean
        - assignment-operator
    - include: else-pop

However, this doesn’t prevent matches when the settings name is followed by something which is not a word boundary:

234125654-97c514a1-af7a-44b0-b1f2-d4c081057a58

I want to use the (?x) extended form because I have many keywords to match, and ignoring whitespace makes it much easier to read.

How can I combine these? More code available in this GitHub issue.

0 Likes

#2

This is it.

0 Likes

#3

wrap your variable in a non-capturing group - currently it is expanded as \b(?x) dotenv-load | export\b, which only looks for a word boundary before dotenv-load and after export.

variables:
  boolean_settings: |
    (?x)(?:
     dotenv-load | export
    )

contexts:
  settings-boolean:
    - match: '\b{{boolean_settings}}\b'
      scope: entity.name.definition.just
      push:
        - constant-boolean
        - assignment-operator
    - include: else-pop
1 Like

#4

That totally fixed the problem. Thank you @kingkeith!

0 Likes