Question

I'm currently writing Regular-Expressions for a Sublime Text - Syntaxdefinition. Sublime has the same format as TextMate, if anyone is familiar with it.

(If not: you write regular Expressions (Python), and define the scope of the match. And theme-files then define the styling of those scopes)

I have troubles with identifying escape-Sequences within strings

This is the Syntax, which should define strings (in quotes) and escape-Sequences within:

- match: ("((?:(\\.)|[^"\\])*)")
  captures:
           '1': {name: punctuation.definition.string.fave}
           '2': {name: string.quotes.fave}
           '3': {name: escape.fave}

I want 3 different colors/scopes for the quotes, the string, and all escape-sequences within this String.

This is my output:

output

As you can see, the regex only matches the last escape-Sequence, and ignores all others.

What is the Problem?

Was it helpful?

Solution

This is a prime example for using the begin and end syntax with the repository. Try using this

patterns:
- begin: \"
  end: \"
  beginCaptures:
    '0': { name: string.quotes.fave }
  endCaptures:
    '0': { name: string.quotes.fave }
  contentName: punctuation.definition.string.fave
  patterns:
  - include: '#escaped_char'

With the repository

repository:
  escaped_char:
    match: '\\.'
    name: escape.fave

Tried to replicate your color theme. With the above, I got this:

enter image description here

Sorry for reviving a zombie post.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top