Skip to content

Commit dcc6acf

Browse files
author
Yury Selivanov
committed
Highlight 'self' and 'cls' as special in item-access (ex: self[1])
1 parent 739ae35 commit dcc6acf

5 files changed

Lines changed: 20 additions & 0 deletions

File tree

grammars/MagicPython.cson

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,9 @@ repository:
11921192
]
11931193
"item-name":
11941194
patterns: [
1195+
{
1196+
include: "#special-variables"
1197+
}
11951198
{
11961199
include: "#special-names"
11971200
}

grammars/MagicPython.syntax.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ repository:
806806

807807
item-name:
808808
patterns:
809+
- include: '#special-variables'
809810
- include: '#special-names'
810811
- match: |
811812
(?x)

grammars/MagicPython.tmLanguage

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,10 @@ it's not tokenized as ellipsis.
19461946
<dict>
19471947
<key>patterns</key>
19481948
<array>
1949+
<dict>
1950+
<key>include</key>
1951+
<string>#special-variables</string>
1952+
</dict>
19491953
<dict>
19501954
<key>include</key>
19511955
<string>#special-names</string>

test/classes/class11.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def __init__(self, a, b=1):
66
self()
77
a.self = 1
88
a.self.bar = 2
9+
self[123]
910

1011

1112

@@ -66,3 +67,8 @@ def : meta.function.python, source.python, storage.type.function.pytho
6667
= : keyword.operator.assignment.python, source.python
6768
: source.python
6869
2 : constant.numeric.dec.python, source.python
70+
: source.python
71+
self : meta.item-access.python, source.python, variable.language.special.self.python
72+
[ : meta.item-access.arguments.python, meta.item-access.python, punctuation.definition.arguments.begin.python, source.python
73+
123 : constant.numeric.dec.python, meta.item-access.arguments.python, meta.item-access.python, source.python
74+
] : meta.item-access.python, punctuation.definition.arguments.end.python, source.python

test/classes/class12.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def meth(cls, a, b=1):
88
cls + 1
99
a.cls = 1
1010
a.cls.__name__
11+
cls[123]
1112

1213

1314

@@ -73,3 +74,8 @@ def : meta.function.python, source.python, storage.type.function.pytho
7374
a.cls : source.python
7475
. : source.python
7576
__name__ : source.python, support.variable.magic.python
77+
: source.python
78+
cls : meta.item-access.python, source.python, variable.language.special.cls.python
79+
[ : meta.item-access.arguments.python, meta.item-access.python, punctuation.definition.arguments.begin.python, source.python
80+
123 : constant.numeric.dec.python, meta.item-access.arguments.python, meta.item-access.python, source.python
81+
] : meta.item-access.python, punctuation.definition.arguments.end.python, source.python

0 commit comments

Comments
 (0)