SublimeText / PackageDev

Tools to ease the creation of snippets, syntax definitions, etc. for Sublime Text.
MIT License
436 stars 83 forks source link

syntax highlight with newline #64

Closed marcelhollerbach closed 9 years ago

marcelhollerbach commented 9 years ago

I have the following code:


 comment: general eolian class
  begin: (class|mixin|interface|abstract) ([A-Za-z0-9._]+)[ \n]*[\(]*[[A-Za-z0-9._]+, \n]+[\)]*[ \n]*\{
  beginCaptures:
      '1': {name: "keyword.other"}
  end: \}
  patterns:
  - include: '#methods_block'
  - include: '#implements'
  - include: '#events'
  - include: '#comments'

I can enter as many " " as I want, but no newline between class(..) and { Is the rule wrong here ? or is this a bug?

FichteFoll commented 9 years ago

I don't quite understand what you need. What do you want to do and what is the problem?

marcelhollerbach commented 9 years ago

There can be syntax like :

class Foo(Bar) {
...
}

but it can also be

class Foo(Bar)
{
...
}

With the given rule above, only the first example gets corretly highlighted, the second is not. So I guess the \n in the begin regex is not understood correctly. Am I doing something wrong here ? Or what is the way to get this working ?

FichteFoll commented 9 years ago

Sublime Text only applies regular expressions on a single line due to performance optimizations. It is not possible to match the opening brace on the second line in a single pattern.

The only way to properly match this would be to use a begin-end match and then some special "inline" patterns, or to use the new and more powerful .sublime-syntax format, which follows a concept of a "stack of contexts". You can read more about it here: http://www.sublimetext.com/docs/3/syntax.html. (Note: you need to use the dev channel for this)