Home Download Buy Blog Forum Support

python - tuple syntax does not work

python - tuple syntax does not work

Postby tracktor on Thu Mar 22, 2012 2:25 pm

There is two scopes defined in python.tmLanguage:
  • punctuation.definition.list.begin.python
  • punctuation.definition.tuple.begin.python

In my test.tmTheme I try to coloring this scopes
Code: Select all
      <dict>
         <key>name</key>
         <string>Python test list</string>
         <key>scope</key>
         <string>punctuation.definition.list.begin.python</string>
         <key>settings</key>
         <dict>
            <key>foreground</key>
            <string>#ff0000</string>
         </dict>
      </dict>
      <dict>
         <key>name</key>
         <string>Python test tuple</string>
         <key>scope</key>
         <string>punctuation.definition.tuple.begin.python</string>
         <key>settings</key>
         <dict>
            <key>foreground</key>
            <string>#ff0000</string>
         </dict>
      </dict>


Test with list works fine but test with tuple does not work (see picture).
Therefore it seams like there is some bug with python tuple syntax.

Sorry for my bad english
Attachments
py.png
py.png (2.83 KiB) Viewed 467 times
Last edited by tracktor on Fri Mar 23, 2012 4:43 am, edited 1 time in total.
tracktor
 
Posts: 4
Joined: Thu Mar 22, 2012 6:06 am

Re: python - tuple syntax does not work

Postby tracktor on Thu Mar 22, 2012 2:42 pm

I found problem cause

There are lines in Python.tmLanguage

Code: Select all
      <dict>
         <key>begin</key>
         <string>(\()</string>
         <key>end</key>
         <string>(\))</string>
         <key>patterns</key>
         <array>
            <dict>
               <key>include</key>
               <string>$self</string>
            </dict>
         </array>
      </dict>


I remove this lines and add this lines instead

Code: Select all
      <dict>
         <key>begin</key>
         <string>(\()</string>
         <key>beginCaptures</key>
         <dict>
            <key>1</key>
            <dict>
               <key>name</key>
               <string>punctuation.definition.tuple.begin.python</string>
            </dict>
         </dict>
         <key>end</key>
         <string>(\))</string>
         <key>endCaptures</key>
         <dict>
            <key>1</key>
            <dict>
               <key>name</key>
               <string>punctuation.definition.tuple.end.python</string>
            </dict>
         </dict>
         <key>name</key>
         <string>meta.structure.tuple.python</string>
         <key>patterns</key>
         <array>
            <dict>
               <key>begin</key>
               <string>(?&lt;=\(|\,)\s*(?![\),])</string>
               <key>contentName</key>
               <string>meta.structure.tuple.item.python</string>
               <key>end</key>
               <string>\s*(?:(,)|(?=\)))</string>
               <key>endCaptures</key>
               <dict>
                  <key>1</key>
                  <dict>
                     <key>name</key>
                     <string>punctuation.separator.tuple.python</string>
                  </dict>
               </dict>
               <key>patterns</key>
               <array>
                  <dict>
                     <key>include</key>
                     <string>$self</string>
                  </dict>
               </array>
            </dict>
         </array>
      </dict>


This lines are constructed by analogy with lines for python "list".

Now tuple syntax works fine

But I am not sure that this is a correct solution
tracktor
 
Posts: 4
Joined: Thu Mar 22, 2012 6:06 am

Re: python - tuple syntax does not work

Postby tracktor on Fri Mar 23, 2012 5:01 am

Why do it?

This allows me to styling ALL punctuation and I got something like this (this is color scheme from SciTE editor)

Looks very comfortably with bold punctuation (see brackets for example, they are bold)
Attachments
sublimetext-scite.png
sublimetext-scite.png (89.55 KiB) Viewed 430 times
tracktor
 
Posts: 4
Joined: Thu Mar 22, 2012 6:06 am


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 19 guests