Sublime Forum

Errors when attempting to convert TmLanguage to Sublime-Syntax

#1

When attempting to convert https://github.com/russCloak/SublimePuppet over to the new syntax using “New Syntax from Puppet.TmLanguage”, my console shows the following error and nothing happens on screen:

  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 553, in run_
    return self.run()
  File "convert_syntax in /Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package", line 398, in run
  File "convert_syntax in /Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package", line 322, in convert
  File "convert_syntax in /Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package", line 243, in make_context
  File "convert_syntax in /Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package", line 286, in make_context
Exception: no entry in repository for variables

I’ve tested this with something like Ruby and was able to generate a YAML file without any issue or console errors.

0 Likes

#2

Did you try my Ruby gem? Was it successful?

To be honest the code quality of the original python convertor is pretty terrible! mine has a better code structure but lacks tests! I’ve done it more than 6 month ago and I hope I get some time to go back and revisit it.

0 Likes

#3

I just tried:

gem install sublime_syntax_convertor

[frizop@profail]~/Library/Application Support/Sublime Text 3/Packages/Puppet/Syntaxes% sublime_syntax_convertor Puppet.tmLanguage
/usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:81:in `handle_include_pattern': undefined method `Exception' for #<SublimeSyntaxConvertor::Convertor:0x007fda3c8b44a8> (NoMethodError)
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:102:in `block in make_context'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:96:in `each'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:96:in `make_context'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:64:in `handle_child_pattern'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:57:in `handle_begin_pattern'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:98:in `block in make_context'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:96:in `each'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:96:in `make_context'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:33:in `create_contexts'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:50:in `convert'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/lib/sublime_syntax_convertor/convertor.rb:12:in `initialize'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/bin/sublime_syntax_convertor:31:in `new'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/bin/sublime_syntax_convertor:31:in `block in <top (required)>'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/bin/sublime_syntax_convertor:24:in `each'
	from /usr/local/lib/ruby/gems/2.1.0/gems/sublime_syntax_convertor-0.1.0/bin/sublime_syntax_convertor:24:in `<top (required)>'
	from /usr/local/bin/sublime_syntax_convertor:23:in `load'
	from /usr/local/bin/sublime_syntax_convertor:23:in `<main>'
0 Likes

#4

The syntax is errorneous. It attempts to include a “variables” key from its repository, but there is no such key. This is why the conversion fails, or rather aborts since this is a wanted failure.

Remove lines 55-58 and 543-545 or create a repository key for “variables” to fix it.

Also, please use triple-fenced code blocks for exception tracebacks like the above with ``` \n code \n ```, not a quote.

0 Likes

#6

I tried the following:

diff --git a/Syntaxes/Puppet.tmLanguage b/Syntaxes/Puppet.tmLanguage
index 6b69002..1a22422 100755
--- a/Syntaxes/Puppet.tmLanguage
+++ b/Syntaxes/Puppet.tmLanguage
@@ -54,10 +54,6 @@
      <array>
        <dict>
          <key>include</key>
-         <string>#variables</string>
-       </dict>
-       <dict>
-         <key>include</key>
          <string>#constants</string>
        </dict>
        <dict>
@@ -541,10 +537,6 @@
          <string>#numbers</string>
        </dict>
        <dict>
-         <key>include</key>
-         <string>#variables</string>
-       </dict>
-       <dict>
          <key>match</key>
          <string>=</string>
          <key>name</key>

But this still happens when attempting to convert:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 553, in run_
    return self.run()
  File "convert_syntax in /Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package", line 398, in run
  File "convert_syntax in /Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package", line 322, in convert
  File "convert_syntax in /Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package", line 243, in make_context
  File "convert_syntax in /Applications/Sublime Text.app/Contents/MacOS/Packages/Default.sublime-package", line 286, in make_context
Exception: no entry in repository for numbers
0 Likes

#7

Well, it appears you need to remove references of <key>include</key><string>#numbers</string> as well.

Whoever wrote this syntax did a really sloppy job.

0 Likes

#8

While we’re on the subject, is there perhaps a better way to debug these things? Perhaps a blog post :wink:

Also, my intent is to get it moved over to YAML and work on it a bit, then maybe re-release it. I’ve been working with this syntax for a while.

0 Likes

#9

I don’t think there is. Asking on the forum will suffice for the moment.
I’m debugging this partly based on the command’s source code, which you can find in the “Default” package as convert_syntax.py, and partly based on experience with syntax definitions.

1 Like