Sublime Forum

*sublime-syntax - Problems with capturing a variable type

#1

Hi,
can anybody help with the regex for capturing a variable for a custom syntax?

    - match: '(?:<)[^<].+(?:>)'
      scope: variable.other.constant.xys

This one isn’t too bad but it exposes a problem.

A few examples:

01. $eol    = <crlf>;
02. $sep    = <crlf 2>;
03. $items1 = <get selecteditemsnames <crlf 3>>;
// Yes, the single double quote is intentional in 04.
04. $items2 = <get selecteditemsnames ">;

05. $heredoc = <<<>>>
    ...
>>>;

It captures the right hand side variable for 01. - 04. fine but also this part of 05.:

<>>>

which is part of a heredoc (and which it shouldn’t capture).

Any idea how to avoid that it captures a part of the heredoc but still works fine for the first four examples?

I don’t use a - match for heredocs in my syntax file because I don’t want it’s content be formatted as e.g. a whole string…

0 Likes

#2

I guess you’d need to place the heredoc pattern somewhere before your variable pattern

context:
  - match: ([<]{3})(\S+)
    scope: string.other.heredoc
    captures:
       1: punctuation.definition.heredoc
  - match: (?:<)[^<].+(?:>)
    scope: variable.other.constant.xys

…so if the lexer sees something like <<< it matches the heredoc first.

0 Likes

#3

@deathaxe

Thanks a lot!

0 Likes