Skip to content

Commit 4fd74e3

Browse files
committed
Give kwargs in class declarations a special scope.
1 parent 133f72f commit 4fd74e3

File tree

6 files changed

+68
-24
lines changed

6 files changed

+68
-24
lines changed

grammars/MagicPython.cson

+22-8
Original file line numberDiff line numberDiff line change
@@ -1105,14 +1105,28 @@ repository:
11051105
}
11061106
]
11071107
"inheritance-identifier":
1108-
match: '''
1109-
(?x)
1110-
\\b ([[:alpha:]_]\\w*) \\b
1111-
1112-
'''
1113-
captures:
1114-
"1":
1115-
name: "entity.other.inherited-class.python"
1108+
patterns: [
1109+
{
1110+
match: '''
1111+
(?x)
1112+
\\b ([[:alpha:]_]\\w*) \\b (?=\\s*=)
1113+
1114+
'''
1115+
captures:
1116+
"1":
1117+
name: "entity.other.inherited-class.python variable.parameter.class.python"
1118+
}
1119+
{
1120+
match: '''
1121+
(?x)
1122+
\\b ([[:alpha:]_]\\w*) \\b
1123+
1124+
'''
1125+
captures:
1126+
"1":
1127+
name: "entity.other.inherited-class.python"
1128+
}
1129+
]
11161130
"expression-class":
11171131
patterns: [
11181132
{

grammars/MagicPython.tmLanguage

+28-9
Original file line numberDiff line numberDiff line change
@@ -1708,18 +1708,37 @@
17081708
</dict>
17091709
<key>inheritance-identifier</key>
17101710
<dict>
1711-
<key>match</key>
1712-
<string>(?x)
1713-
\b ([[:alpha:]_]\w*) \b
1711+
<key>patterns</key>
1712+
<array>
1713+
<dict>
1714+
<key>match</key>
1715+
<string>(?x)
1716+
\b ([[:alpha:]_]\w*) \b (?=\s*=)
17141717
</string>
1715-
<key>captures</key>
1716-
<dict>
1717-
<key>1</key>
1718+
<key>captures</key>
1719+
<dict>
1720+
<key>1</key>
1721+
<dict>
1722+
<key>name</key>
1723+
<string>entity.other.inherited-class.python variable.parameter.class.python</string>
1724+
</dict>
1725+
</dict>
1726+
</dict>
17181727
<dict>
1719-
<key>name</key>
1720-
<string>entity.other.inherited-class.python</string>
1728+
<key>match</key>
1729+
<string>(?x)
1730+
\b ([[:alpha:]_]\w*) \b
1731+
</string>
1732+
<key>captures</key>
1733+
<dict>
1734+
<key>1</key>
1735+
<dict>
1736+
<key>name</key>
1737+
<string>entity.other.inherited-class.python</string>
1738+
</dict>
1739+
</dict>
17211740
</dict>
1722-
</dict>
1741+
</array>
17231742
</dict>
17241743
<key>expression-class</key>
17251744
<dict>

grammars/src/MagicPython.syntax.yaml

+12-5
Original file line numberDiff line numberDiff line change
@@ -887,11 +887,18 @@ repository:
887887
- include: '#inheritance-identifier'
888888

889889
inheritance-identifier:
890-
match: |
891-
(?x)
892-
\b ([[:alpha:]_]\w*) \b
893-
captures:
894-
'1': {name: entity.other.inherited-class.python}
890+
patterns:
891+
- match: |
892+
(?x)
893+
\b ([[:alpha:]_]\w*) \b (?=\s*=)
894+
captures:
895+
'1': {name: entity.other.inherited-class.python
896+
variable.parameter.class.python}
897+
- match: |
898+
(?x)
899+
\b ([[:alpha:]_]\w*) \b
900+
captures:
901+
'1': {name: entity.other.inherited-class.python}
895902
896903
expression-class:
897904
patterns:

misc/scopes

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ support.variable.magic.python
161161
variable.language.special.cls.python
162162
variable.language.special.self.python
163163
variable.legacy.builtin.python
164+
variable.parameter.class.python
164165
variable.parameter.function-call.python
165166
variable.parameter.function.language.python
166167
variable.parameter.function.language.special.cls.python

test/classes/class14.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class : meta.class.python, source.python, storage.type.class.python
2525
a : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python
2626
, : meta.class.inheritance.python, meta.class.python, punctuation.separator.inheritance.python, source.python
2727
: meta.class.inheritance.python, meta.class.python, source.python
28-
b : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python
28+
b : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python, variable.parameter.class.python
2929
= : keyword.operator.assignment.python, meta.class.inheritance.python, meta.class.python, source.python
3030
Exception : meta.class.inheritance.python, meta.class.python, source.python, support.type.exception.python
3131
) : meta.class.inheritance.python, meta.class.python, punctuation.definition.inheritance.end.python, source.python

test/classes/class2.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
@dec
2+
# Bar.name=... is not legal, but the test is for highlighter not breaking badly
23
class Spam(Foo.Bar, Bar.name={'very': 'odd'}):
34
pass
45

56

67

78
@ : entity.name.function.decorator.python, meta.function.decorator.python, source.python
89
dec : entity.name.function.decorator.python, meta.function.decorator.python, source.python
10+
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
11+
Bar.name=... is not legal, but the test is for highlighter not breaking badly : comment.line.number-sign.python, source.python
912
class : meta.class.python, source.python, storage.type.class.python
1013
: meta.class.python, source.python
1114
Spam : entity.name.type.class.python, meta.class.python, source.python
@@ -17,7 +20,7 @@ class : meta.class.python, source.python, storage.type.class.python
1720
: meta.class.inheritance.python, meta.class.python, source.python
1821
Bar : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python
1922
. : meta.class.inheritance.python, meta.class.python, source.python
20-
name : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python
23+
name : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python, variable.parameter.class.python
2124
= : keyword.operator.assignment.python, meta.class.inheritance.python, meta.class.python, source.python
2225
{ : meta.class.inheritance.python, meta.class.python, punctuation.definition.dict.begin.python, source.python
2326
' : meta.class.inheritance.python, meta.class.python, punctuation.definition.string.begin.python, source.python, string.quoted.single.python

0 commit comments

Comments
 (0)