Sublime Forum

Editing Python 3

#1

Hello. I have created a **sublime-build **file so that I can run a Python file as Python3.2. I can copy and modify my Python.tmLanguage file so that it will recognise a few new methods. However, this would entail my swapping out tmLanguage files to enable me to switch syntax versions.

  1. Is there a way that I can retain two language files and have ‘Python3’ appear as a syntax option in the list at the bottom-right corner of ST?

  2. Is there a simple way in the tmLanguage file that I can signify, for example, the **print **statement as an error? That is, where do I need to enter ‘print’?

Andy.

0 Likes

#2

You can duplicate the python.tmLanguage file into your own package and change the name key to something else (Python3).

	<key>name</key>
	<string>Python3</string>

From there you can select the new Python3 syntax by either using the Command Palette or clicking on the syntax far right in the status bar.

tmLanguage files are parsed top to bottom, so you can add a match for your print statement at the beginning, right after the opening patterns key and scope it as invalid.illegal.blah.blah.python. see Naming Conventions manual.macromates.com/en/language_grammars

...
	<key>patterns</key>
	<array>
		<dict>
			<key>match</key>
			<string>print statement blah regex here</string>
			<key>name</key>
			<string>invalid.illegal.print-statement.python</string>
		</dict>
...
0 Likes

#3

@atomi. Thank you very much - great info :wink:

0 Likes