Sublime Forum

Support for \K and/or variable-length lookbehinds in .tmlanguage files

#1

It would be greatly helpful for regular expressions in .tmlanguage files to support the \K flag and/or variable-length lookbehinds. It’s a common pattern, for example in MarkdownEditing’s Markdown.tmlanguage, to use a zero-width match before or after some sequence, so as to include the matched sequence in a highlighting context. Without either of these features, the power of the expression matching that sequence is severely limited.

1 Like

#2

I suppose half of the features you need are already supported. The regular expression engine used is Oniguruma, partly for backwards compatibility and partly for performance reasons I assume. You can check out its docs here: github.com/kkos/oniguruma/blob/master/doc/RE

Furthermore, there were a few changes to the syntax definition structure in the latest dev builds, which you can read about here: sublimetext.com/docs/3/syntax.html

0 Likes

#3

[quote=“FichteFoll”]I suppose half of the features you need are already supported. The regular expression engine used is Oniguruma, partly for backwards compatibility and partly for performance reasons I assume. You can check out its docs here: github.com/kkos/oniguruma/blob/master/doc/RE

Furthermore, there were a few changes to the syntax definition structure in the latest dev builds, which you can read about here: sublimetext.com/docs/3/syntax.html[/quote]

Thanks for the reply. I don’t know how I messed up before, but I see that subroutines are there. But, I just found that tmlanguage files are strictly limited to single-line regular expressions, so I think this is a lost cause.

.sublime-syntax looks like a great solution and an all-around improvement, but I take it it’s not compatible with Sublime Text 2?

Variable-length lookbehinds and \K would still be nice, but with my use case impossible either way I can’t really give a good reason to implement them.

0 Likes

#4

[quote=“twhb”]But, I just found that tmlanguage files are strictly limited to single-line regular expressions, so I think this is a lost cause.

.sublime-syntax looks like a great solution and an all-around improvement, but I take it it’s not compatible with Sublime Text 2?

Variable-length lookbehinds and \K would still be nice, but with my use case impossible either way I can’t really give a good reason to implement them.[/quote]

Yes, all regular expressions operate on a single line for performance reason. There is no way around that, at least for the moment. You can parse constructs that span multiple lines with the .sublime-syntax format by utilizing contexts, but a single expression can not span multiple lines (as would be required for something like markdown or rest headings).

.sublime-syntax has been added in 3084 and is considered “stable” or “usable” since 3092. That means they are only available on the dev channel of Sublime Text 3. You shouldn’t be using 2 anymore since it’s inferior in almost every way.

1 Like

#5

[quote=“FichteFoll”]Yes, all regular expressions operate on a single line for performance reason. There is no way around that, at least for the moment. You can parse constructs that span multiple lines with the .sublime-syntax format by utilizing contexts, but a single expression can not span multiple lines (as would be required for something like markdown or rest headings).

.sublime-syntax has been added in 3084 and is considered “stable” or “usable” since 3092. That means they are only available on the dev channel of Sublime Text 3. You shouldn’t be using 2 anymore since it’s inferior in almost every way.[/quote]

Alright, thanks again. I’m not using 2, but I think popular packages won’t want to drop support for 2 yet.

0 Likes

#6

I’ve edited the original post to remove the part about subroutines and rephrase the request accordingly.

I would still like to advocate that either the \K flag or variable-length lookbehinds be implemented. Lacking them places real limits on what tmlanguage files are capable of. (More on that in the edited OP.)

1 Like