Sublime Forum

Questions about tmLanguage grammars in Sublime

#1

I’m comparing the features of .tmLanguage and .sublime-syntax to see which one fits my purposes and coding style better. But before I can decide, I need to know a few things about how does sublime use .tmLanguage grammars.

tmLanguage in TextMate can use "include = to include the grammar with such top-level scope name. This would be equivalent to sublime-syntax’s include: . Does this also function in sublime? If so, in which folder will the grammar with be expected to be? Same folder as the including grammar? Same folder or subfolders?

tm.Language also can do include = #item in repository> which would be a very convenient feature that has no equialent in sublime-syntax. So I guess that if the above is possible for .tmLanguage within sublime, this is too?

Finally, can tmLanguage use the new, non-backtracking regex engine sublime has? Or is it limited to using the old backtracking one? I.e. should I be using possessive quantifiers, atomic groups and the like, or should I avoid them?

THanks in advance!

0 Likes

#2

anything .tmLanguage can do, .sublime-syntax can do better.

.tmLanguage only uses the Oniguruma regex engine, whereas .sublime-syntax will use it’s custom one for increased performance for any expressions that are compatible with it.

TL;DR: don’t even consider using .tmLanguage unless you need compatibility with other editors or want to make life hard for yourself and have slower performance

about includes, generally it’s better to use a scope (and optionally a context) rather than a file name (or relative/absolute path), as it then allows other packages to override that syntax definition and have things still work as expected

0 Likes

#3

Some bits of my OP got borked. I meant to say that tmLanguage can do include = , which would be equivalent to sublime syntax’s include: . This is currently impossible in sublime-syntax: you can’t push, set or embed a context from another file other than main, which organisationally is awful. Also, you can’t attack repositories to sublime-syntax contexts which is also an organisational inconvenience.

Wait in sublime you can do include: instead of include: so I can do, say (this is a toy example) include: someOtherLanguage.source instead of include: ? Is this correct? Well, n that case, this is convenient.

But say I want to include a context from another file other than that file’s main context. tmLanguage can do this, but how can sblime-syntax do it?

Edit: also, not having begin-end and recursive parsing of expressions within it is very inconvenient. We can achieve the same with push and pop, but in a way that is more convoluted and less convenient to someone reading/reviewing the syntax.

0 Likes

#4

not true

0 Likes

#5

Ok, my bad, but this should SERIOUSLY be documented. Question: suppose I for some reason have two different syntax with scope: x and then in a third one do include: x. Which one will be pulled?

Oh, another question about sublime-syntax/tmLanguage differences, in tmLanguage we can do e.g. include = $self

is there an aquivalent in sublime-syntax? I want to include the current context with_prototype: and then in THAT modified context include THAT SAME modifier context with_prototype: . How can I acomplish it?

0 Likes

#6

Interested in this as well. I suspect usual package merge order.

It’s equivalent to including the main context, which is the entry point. Or I’m confusing things here and you just want to refer to any current context, in which case you can just include that by name (assuming it is not an anonymous inline context).

Be vary with with_protoype pushes, however, since the way you describe it sounds like you’ll run into infinite recursion.

0 Likes

#7

yes, I want to refer to any current context (that’s what I understood $self did in tmLanguage).

0 Likes

#8

This isn’t the case. We will use sregex with a .tmLanguage if the regex patterns are compatible. Our .tmLanguage and .sublime-syntax parsers both resolve to the same internal data structures, it is just that many of the features of the engine aren’t accessible via .tmLanguage since it does not have matching features.

The features that .sublime-syntax supports that are unavailable with .tmLanguage are:

  1. Variables
  2. Precise context control (push, pop, set), although .tmLanguage has alternatives that are less powerful
  3. clear_scopes
  4. embed
  5. The prototype context and related directives
  6. with_prototype

I may have missed one or two others, but those are the ones that come to mind.

3 Likes

#9

Good to know, thanks - I thought that might be the case, but when I saw that the syntax test regex compatibility build system only worked with .sublime-syntax files, I figured .tmLanguage just always used Oniguruma

0 Likes