Home Download Buy Blog Forum Support

Editing Python 3

Editing Python 3

Postby agibsonsw on Sun May 20, 2012 10:55 pm

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.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Editing Python 3

Postby atomi on Mon May 21, 2012 2:45 am

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

Code: Select all
   <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 http://manual.macromates.com/en/language_grammars

Code: Select all
...
   <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>
...
Last edited by atomi on Tue May 22, 2012 7:37 am, edited 1 time in total.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: Editing Python 3

Postby agibsonsw on Mon May 21, 2012 12:21 pm

@atomi. Thank you very much - great info ;)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm


Return to Technical Support

Who is online

Users browsing this forum: Alexa [Bot] and 16 guests

cron