Sublime Forum

Ctrl+r, jack, and syntax files (maybe a tree too)


I’m programming in the jack language. There is a Jack.sublime-syntax file, but ctrl+r doesn’t recognise any functions, methods etc, i.e ctrl+r doesn’t do the same for a .jack file as a .cpp or .py file (C++, python).

Does ctrl+r use the syntax file ?
If yes, what mods do I have to make to the syntax file for ctrl+r to work for a Jack program…
Or if no, how do i get started if I’m barking up the wrong tree.

I’ve had a quick look on this forum and the interweb at large (say 20min) but no joy as yet.

Instructions or correct tree to bark up, much appreciated :evergreen_tree::poodle:
Thanks in advance, Lozminda



The symbol list is populated by a combination of the syntax definition and a separate metadata file that tells Sublime what parts of the language are symbols worth looking at.

If the syntax definition can distinctly recognize the items that you want in the symbol list (that’s generally the case if the color scheme can apply a style to just that particular text), then you’re probably just missing out on the metadata information. You should only need to modify the syntax definition if it doesn’t already match what you’re trying to capture.

As far as the metadata information goes, that requires a tmPreferences file that associates a scope selector with a setting that tells Sublime that the symbols that match the selector should appear in the symbol list.

As a simple example, you can use View Package File from the command palette to open Python/Symbol List.tmPreferences; the content of that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
	<string>Symbol List</string>
	<string>source.python meta.function - meta.function.inline, source.python meta.class</string>

This metadata tells Sublime that any text that matches the scope selector provided (non-inline functions as well as classes) should appear in the symbol list. By default the symbol list will show you the text as it appears in the file; the optional symbolTransformation can be used to modify the text that appears in the symbol list.

The name of the file doesn’t matter (so long as the extension is correct) but it’s common practice to name it something like the above so that you can tell what it’s doing easier. For more examples of what’s possible you can look at some of the other metadata files the same way.

The Package of the file doesn’t matter, nor does the name of the file (so long as it has the correct extension), so you could create a file in your User package (or perhaps submit a PR upstream to the package author) that has the appropriate content to get things working.

1 Like


OK made some mistakes, don’t know if you can see the withdrawn post or no.

So I copied and pasted the above Symbol List.tmPreferences changing the source.python to source.jack. Saved it as jackSymbol Index.tmPreferences in the same folder as the jack syntax file and also my User folder.

No result crtl+r still only shows an ‘@’.

Obvs I’m doing something wrong/not understanding your previous message.

Thanks so far for your help, you seem to be single handedly being my sublime coach ! Cheers, Lozminda



The scopes may be different in the syntax that you’re using from what they appear as in Python, so that may be the issue. Can you provide a link to where the Syntax definition that you’re using is?



I downloaded it using Package Manager, just typing in “jack”.
So I copied it, and it follows. It does look very different to all the other syntax files i’ve looked at (for C++, haskell etc)

name: Jack

  • jack
    scope: source.jack
    • match: \b(class|int|char|boolean|void)\b
      scope: storage.type.jack
    • match: \b(constructor|function|method)\b
      scope: storage.modifier.jack
    • match: \b(field|static|var)\b
      scope: storage.modifier.jack
    • match: \b(let |if |else |while |do |return)\b
      scope: keyword.control.jack
    • match: ‘"’
      • meta_scope: string.quoted.double.jack
      • match: ‘"’
        pop: true
    • match: /*
      • meta_scope: comment.block.jack
      • match: */
        pop: true
    • match: //
      • meta_scope: comment.line.double-slash.jack
      • match: $\n?
        pop: true
    • match: ‘\b[0-9]+\b’
      scope: constant.numeric.jack
    • match: \b(true|false|null|this)\b
      scope: constant.language.jack


Hmm… the package in Packge Control includes a tmLanguage version of the syntax (although it does convert to the sublime-syntax version that you outlined above.

This is a very simple syntax definition; it’s providing highlighting for keywords, but it doesn’t capture the sort of information that you need to do what you want; For example it matches the words constructor, function and method and assigns them the scope storage.modifier.jack, but it doesn’t capture the actual name of those things and apply a scope to them. Without a scope being applied to the symbols that you want in the symbol list, there’s not a way to extract them to put them into the symbol list.



What would be the simplest modification i can do to the jack syntax file (i.e put in the appropriate scopes) so that the symbol index works? Or is it going to be a lot more complicated? Unfortunately C++, C, and jack (some forgotten Fortran/Pascal/Assembled Basic) I don’t think are going to help with this problem much. I can understand in the vaguist of terms what’s going on but I can’t be of any real help…sorry.

It is, in the grand scheme of things, in no way urgent. Not remotely. I have more important work to do, as I’m sure you do… But it would be quite cool, coz crtl+r is very handy in other languages, some one has gone to the effort of writing a jack syntax and peeps are always signing up to the Elements of Computer Systems course ! (Nand2Tetris, from which comes the jack language.)
Perhaps when we’re both retired and have more spare time… ?
Maybe someone else can help ?
I’ve got to crack on with my chores, thanks again !



If you can provide some sample code that shows how constructors, functions and methods are defined (I searched a bit but couldn’t find any examples of code in this language) it might be a relatively simple manner to alter the syntax enough to get this working.



This is an example of a jack program
The closest language (according to the authors of the book Nand2Tetris) is java.

It’s a really simple OOP.

If you need any help decoding give ,give me a shout, but I won’t be back on till the w.e. (work).




pps I’ve got some stuff I’m writing in jack, but don’t yet have a github account so I’ll just have to past it in (from sublime), and it gets a bit mangled (I guess) going to a html format (??)




Ppps (Credit where credit’s due)



That is indeed extremely java-like. Those are the sorts of non-trivial(ish) changes which are unfortunately outside of my bailiwick. I get my hands dirty with a lot of package development in Sublime, but syntax definitions are not my strong suit. There are some other forum members that are more versed though, so someone may be able to help.

As a matter of curiosity, have you tried setting the syntax to Java for these files while you’re editing them? I’m not sure how close the full syntax is, and it’s not totally viable because the scopes are wrong. If it seems “good enough” it’s relatively simple to make a version of the Java syntax that associates itself with Jack files and has an appropriate Jack scope.

The potential problem there is in exactly how compatible the two languages seem to be; it may work really well (and possibly highlight some things that it shouldn’t, but otherwise be better) or it may be complete chaos…



Cheers ! Sorry for the late ackknowledgement