Sublime Forum

Python - tuple syntax does not work

#1

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

		<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

0 Likes

#2

I found problem cause

There are lines in Python.tmLanguage

		<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

		<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

0 Likes

#3

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)


0 Likes