Sublime Forum

Using syntax highlighting from GitHub/Atom

#1

Similarly to Syntax highlighter from atom to sublime, I wanted to convert the SmPL syntax from an Atom extension, that is also used by GitHub’s syntax hightlighting.

Indeed, one of the formats Atom supports is TextMate’s grammar represented as CoffeScript’s variant of JSON. So I first had to convert the CSON syntax to something more usable.

I found https://github.com/relaxdiego/relaxdiego-sublime-tools, which promised to convert YAML files into the plist format tmlLanguage expects.

So I converted the CSON syntax into JSON (which works as subset of YAML) using https://www.convertsimple.com/convert-cson-to-json/ and saved it into my working directory with tmLanguage.yml @relaxdiego’s tools expect.

Then I downloaded the tools and after fixing it slightly, it produced a TextMate syntax.

git clone git@github.com:relaxdiego/relaxdiego-sublime-tools.git
ruby relaxdiego-sublime-tools/lib/translate_yaml_to_tmlanguage.rb SmPL.tmLanguage.yml

Unfortunately, copying the produced SmPL.tmLanguage file to ~/.config/sublime-text-3/Packages/User/ did not work, with the following error appearing in Sublime Text’s console:

error parsing lexer: Packages/User/SmPL.tmLanguage: Unexpected capture value

Looking briefly at the JSON file, I noticed that it includes etc#comma and etc#string, which refers to the Atom package. So I also converted https://github.com/Alhadis/language-etc/blob/669f7b1ca0d1a37bf63754b9df7c53bd89ba4fd9/grammars/etc.cson to etc.tmLanguage. Unfortunately, that one also fails to parse with:

error parsing lexer: Packages/User/etc.tmLanguage: Expected key name

So I tried manually copying the the necessary items from the etc’s repository into SaML’s repository and updating the includes. Unfortunately, that did not do anything. The error was still “Unexpected capture value”.

Is there a way to get more information on why the parsing failed?

The grammar I managed to produce: https://gist.github.com/jtojnar/ae41fdf515d7ed91e5bfdb50107d1772#file-saml-tmlanguage

0 Likes

#2

Usually I would just take this and convert it into a .sublime-syntax file with ST’s builtin command.
image

But unfortuanately, this one uses feature that ST (or the converter?) doesn’t support.

patterns and includes are not supported within captures: {‘1’: {‘name’: ‘keyword.control.directive.$1.smpl’}, ‘2’: {‘patterns’: [{‘include’: ‘#str’}]}, ‘3’: {‘patterns’: [{‘include’: ‘#isoPath’}]}}
patterns and includes are not supported within captures: {‘1’: {‘name’: ‘keyword.control.directive.$1.smpl’}, ‘2’: {‘patterns’: [{‘include’: ‘#str’}]}, ‘3’: {‘patterns’: [{‘include’: ‘#isoPath’}]}}
patterns and includes are not supported within captures: {‘1’: {‘name’: ‘storage.modifier.virtual.smpl’}, ‘2’: {‘patterns’: [{‘match’: ‘[^\s,]+’, ‘name’: ‘entity.name.rule.smpl’}, {‘include’: ‘#comma’}]}}

1 Like

#3

Thanks, that was helpful. Even with the incomplete conversion, the produced syntax works splendidly.

0 Likes