Sublime Forum

[Fixed]Syntax defintion ST2/ST3 differences in YAML-tmLanguage

#1

Hi guys,
Is there any topic for defferences between syntax definition file for ST2 and ST3?

Last year I’ve develop a syntax and autocomletions helper for our own project’s “programming” language.
(Based on ST2 doc)

At first Ive started developing tmlanguage for ST2, but later I’ve switched to ST3 and use old tmLanguage(yaml) file.
Now I want to use full power of ST3 syntax highlighting and I can’t understand the difference between those two formats (Like one here: ST3 Doc) of tmLanguage.

Old one uses:

patterns:
- comment: Tab stops like $1, $2...
  name: keyword.other.ssraw
  match: \$\d+

repository:
  other_definitions:
    name: constant.other.tplpre
    comment: Tags
    match: \s+(tags)\s+(.*?);


And etc - which is looks fine for me.

New format is something like:

contexts:
  main:
    - match: \b(if|else|for|while)\b
      scope: keyword.control.c

Which is totally broke my old format and my mind.

  1. Can I somehow reformat old to new - automatically \ or should I start the develpment from the beggining and forgot the old format?
  2. Is there huge difference and enchansement or advantages in new format comparing with old one / or it’s better to use old and change nothing?

P.S. I also tried to include new format in old - but it does not work. It builds without errors but not highlighting.

Thanks in advance.

0 Likes

#2

The menu includes an item to convert a tmLanguage file to a sublime-syntax file. Sublime-syntax provides a superset of features compared to tmLanguage and is overall a lot more flexible (and easier to work with, once you understand how it works). Many things the default syntax definitions do now wouldn’t be possible in the old format.

As such, I will always recommend to use the new syntax format, unless you specifically need to support ST2.

0 Likes

#3

Thanks!
I see in Developer tools only “New Syntax from YAML…” which creates draft from default yaml syntax definition.

0 Likes

#4

Can you please point me to that conversion option in ST3? I can’t find it now.

0 Likes

#5

Iirc you need to have a view active with the syntax selected (i.e. in use) that you want to convert. Otherwise the menu item won’t be visible.

Feels pretty backwards to me, but my comment was ignored when this feature was released.

1 Like

#6

This is the only one option I can find:


But this opens new syntax from YAML, not from my current custom.

0 Likes

#7

Run Set Syntax: in the command palette first, then Plugin Development:Convert Syntax to .sublime-syntax.

0 Likes

#8

Got it now.
But also catches as exception:

Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 797, in run_
    return self.run()
  File "convert_syntax in C:\Program Files\Sublime Text 3\Packages\Default.sublime-package", line 431, in run
  File "convert_syntax in C:\Program Files\Sublime Text 3\Packages\Default.sublime-package", line 358, in convert
  File "convert_syntax in C:\Program Files\Sublime Text 3\Packages\Default.sublime-package", line 312, in make_context
Exception: no entry in repository for xpath
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 797, in run_
    return self.run()
  File "convert_syntax in C:\Program Files\Sublime Text 3\Packages\Default.sublime-package", line 431, in run
  File "convert_syntax in C:\Program Files\Sublime Text 3\Packages\Default.sublime-package", line 358, in convert
  File "convert_syntax in C:\Program Files\Sublime Text 3\Packages\Default.sublime-package", line 312, in make_context
Exception: no entry in repository for xpath

Now will try to fix it.
Thanks for clarify.

0 Likes

#9

Seems like you tried to include an “xpath” context/entry in the syntax definition, which does not exist.

1 Like

#10
0 Likes

#11

Thanks a lot,
I’ve currenlty fixed all orphaned includes and it helps.

0 Likes