Skip to content

Commit c1b73c8

Browse files
committedDec 22, 2016
Make kwargs in class declaration consistent with function calls.
1 parent 079a7a4 commit c1b73c8

File tree

6 files changed

+126
-94
lines changed

6 files changed

+126
-94
lines changed
 

Diff for: ‎grammars/MagicPython.cson

+26-29
Original file line numberDiff line numberDiff line change
@@ -1093,42 +1093,16 @@ repository:
10931093
name: "keyword.operator.assignment.python"
10941094
match: "=(?!=)"
10951095
}
1096-
{
1097-
include: "#expression-class"
1098-
}
10991096
{
11001097
name: "support.type.metaclass.python"
11011098
match: "\\bmetaclass\\b"
11021099
}
11031100
{
1104-
include: "#inheritance-identifier"
1105-
}
1106-
]
1107-
"inheritance-identifier":
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"
1101+
include: "#illegal-names"
11181102
}
11191103
{
1120-
match: '''
1121-
(?x)
1122-
\\b ([[:alpha:]_]\\w*) \\b
1123-
1124-
'''
1125-
captures:
1126-
"1":
1127-
name: "entity.other.inherited-class.python"
1104+
include: "#class-kwarg"
11281105
}
1129-
]
1130-
"expression-class":
1131-
patterns: [
11321106
{
11331107
include: "#call-wrapper-inheritance"
11341108
}
@@ -1138,7 +1112,30 @@ repository:
11381112
{
11391113
include: "#member-access-class"
11401114
}
1115+
{
1116+
include: "#inheritance-identifier"
1117+
}
11411118
]
1119+
"class-kwarg":
1120+
match: '''
1121+
(?x)
1122+
\\b ([[:alpha:]_]\\w*) \\s*(=)(?!=)
1123+
1124+
'''
1125+
captures:
1126+
"1":
1127+
name: "entity.other.inherited-class.python variable.parameter.class.python"
1128+
"2":
1129+
name: "keyword.operator.assignment.python"
1130+
"inheritance-identifier":
1131+
match: '''
1132+
(?x)
1133+
\\b ([[:alpha:]_]\\w*) \\b
1134+
1135+
'''
1136+
captures:
1137+
"1":
1138+
name: "entity.other.inherited-class.python"
11421139
"member-access-class":
11431140
begin: "\\.\\s*(?!\\.)"
11441141
end: "(?<=\\S)(?=\\W)|$"
@@ -1542,7 +1539,7 @@ repository:
15421539
}
15431540
]
15441541
"call-wrapper-inheritance":
1545-
comment: "same as a funciton call, but in inheritance context"
1542+
comment: "same as a function call, but in inheritance context"
15461543
name: "meta.function-call.python"
15471544
begin: '''
15481545
(?x)

Diff for: ‎grammars/MagicPython.tmLanguage

+43-44
Original file line numberDiff line numberDiff line change
@@ -1690,10 +1690,6 @@
16901690
<key>match</key>
16911691
<string>=(?!=)</string>
16921692
</dict>
1693-
<dict>
1694-
<key>include</key>
1695-
<string>#expression-class</string>
1696-
</dict>
16971693
<dict>
16981694
<key>name</key>
16991695
<string>support.type.metaclass.python</string>
@@ -1702,48 +1698,12 @@
17021698
</dict>
17031699
<dict>
17041700
<key>include</key>
1705-
<string>#inheritance-identifier</string>
1701+
<string>#illegal-names</string>
17061702
</dict>
1707-
</array>
1708-
</dict>
1709-
<key>inheritance-identifier</key>
1710-
<dict>
1711-
<key>patterns</key>
1712-
<array>
17131703
<dict>
1714-
<key>match</key>
1715-
<string>(?x)
1716-
\b ([[:alpha:]_]\w*) \b (?=\s*=)
1717-
</string>
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>
1704+
<key>include</key>
1705+
<string>#class-kwarg</string>
17261706
</dict>
1727-
<dict>
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>
1740-
</dict>
1741-
</array>
1742-
</dict>
1743-
<key>expression-class</key>
1744-
<dict>
1745-
<key>patterns</key>
1746-
<array>
17471707
<dict>
17481708
<key>include</key>
17491709
<string>#call-wrapper-inheritance</string>
@@ -1756,8 +1716,47 @@
17561716
<key>include</key>
17571717
<string>#member-access-class</string>
17581718
</dict>
1719+
<dict>
1720+
<key>include</key>
1721+
<string>#inheritance-identifier</string>
1722+
</dict>
17591723
</array>
17601724
</dict>
1725+
<key>class-kwarg</key>
1726+
<dict>
1727+
<key>match</key>
1728+
<string>(?x)
1729+
\b ([[:alpha:]_]\w*) \s*(=)(?!=)
1730+
</string>
1731+
<key>captures</key>
1732+
<dict>
1733+
<key>1</key>
1734+
<dict>
1735+
<key>name</key>
1736+
<string>entity.other.inherited-class.python variable.parameter.class.python</string>
1737+
</dict>
1738+
<key>2</key>
1739+
<dict>
1740+
<key>name</key>
1741+
<string>keyword.operator.assignment.python</string>
1742+
</dict>
1743+
</dict>
1744+
</dict>
1745+
<key>inheritance-identifier</key>
1746+
<dict>
1747+
<key>match</key>
1748+
<string>(?x)
1749+
\b ([[:alpha:]_]\w*) \b
1750+
</string>
1751+
<key>captures</key>
1752+
<dict>
1753+
<key>1</key>
1754+
<dict>
1755+
<key>name</key>
1756+
<string>entity.other.inherited-class.python</string>
1757+
</dict>
1758+
</dict>
1759+
</dict>
17611760
<key>member-access-class</key>
17621761
<dict>
17631762
<key>begin</key>
@@ -2422,7 +2421,7 @@
24222421
<key>call-wrapper-inheritance</key>
24232422
<dict>
24242423
<key>comment</key>
2425-
<string>same as a funciton call, but in inheritance context</string>
2424+
<string>same as a function call, but in inheritance context</string>
24262425
<key>name</key>
24272426
<string>meta.function-call.python</string>
24282427
<key>begin</key>

Diff for: ‎grammars/src/MagicPython.syntax.yaml

+20-20
Original file line numberDiff line numberDiff line change
@@ -881,30 +881,30 @@ repository:
881881
match: ','
882882
- name: keyword.operator.assignment.python
883883
match: =(?!=)
884-
- include: '#expression-class'
885884
- name: support.type.metaclass.python
886885
match: \bmetaclass\b
887-
- include: '#inheritance-identifier'
888-
889-
inheritance-identifier:
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}
902-
903-
expression-class:
904-
patterns:
886+
- include: '#illegal-names'
887+
- include: '#class-kwarg'
905888
- include: '#call-wrapper-inheritance'
906889
- include: '#expression-base'
907890
- include: '#member-access-class'
891+
- include: '#inheritance-identifier'
892+
893+
class-kwarg:
894+
match: |
895+
(?x)
896+
\b ([[:alpha:]_]\w*) \s*(=)(?!=)
897+
captures:
898+
'1': {name: entity.other.inherited-class.python
899+
variable.parameter.class.python}
900+
'2': {name: keyword.operator.assignment.python}
901+
902+
inheritance-identifier:
903+
match: |
904+
(?x)
905+
\b ([[:alpha:]_]\w*) \b
906+
captures:
907+
'1': {name: entity.other.inherited-class.python}
908908

909909
member-access-class:
910910
begin: \.\s*(?!\.)
@@ -1152,7 +1152,7 @@ repository:
11521152
'1': {name: invalid.illegal.decorator.python}
11531153

11541154
call-wrapper-inheritance:
1155-
comment: same as a funciton call, but in inheritance context
1155+
comment: same as a function call, but in inheritance context
11561156
name: meta.function-call.python
11571157
begin: |
11581158
(?x)

Diff for: ‎test/calls/call9.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
foo(type=1)
2+
3+
4+
5+
foo : meta.function-call.generic.python, meta.function-call.python, source.python
6+
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
7+
type : meta.function-call.arguments.python, meta.function-call.python, source.python, variable.parameter.function-call.python
8+
= : keyword.operator.assignment.python, meta.function-call.arguments.python, meta.function-call.python, source.python
9+
1 : constant.numeric.dec.python, meta.function-call.arguments.python, meta.function-call.python, source.python
10+
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python

Diff for: ‎test/classes/class16.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Foo(Bar, str, type=12, metaclass=FooMeta): pass
2+
3+
4+
5+
class : meta.class.python, source.python, storage.type.class.python
6+
: meta.class.python, source.python
7+
Foo : entity.name.type.class.python, meta.class.python, source.python
8+
( : meta.class.inheritance.python, meta.class.python, punctuation.definition.inheritance.begin.python, source.python
9+
Bar : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python
10+
, : meta.class.inheritance.python, meta.class.python, punctuation.separator.inheritance.python, source.python
11+
: meta.class.inheritance.python, meta.class.python, source.python
12+
str : meta.class.inheritance.python, meta.class.python, source.python, support.type.python
13+
, : meta.class.inheritance.python, meta.class.python, punctuation.separator.inheritance.python, source.python
14+
: meta.class.inheritance.python, meta.class.python, source.python
15+
type : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python, variable.parameter.class.python
16+
= : keyword.operator.assignment.python, meta.class.inheritance.python, meta.class.python, source.python
17+
12 : constant.numeric.dec.python, meta.class.inheritance.python, meta.class.python, source.python
18+
, : meta.class.inheritance.python, meta.class.python, punctuation.separator.inheritance.python, source.python
19+
: meta.class.inheritance.python, meta.class.python, source.python
20+
metaclass : meta.class.inheritance.python, meta.class.python, source.python, support.type.metaclass.python
21+
= : keyword.operator.assignment.python, meta.class.inheritance.python, meta.class.python, source.python
22+
FooMeta : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python
23+
) : meta.class.inheritance.python, meta.class.python, punctuation.definition.inheritance.end.python, source.python
24+
: : meta.class.python, punctuation.section.class.begin.python, source.python
25+
: source.python
26+
pass : keyword.control.flow.python, source.python

Diff for: ‎test/classes/class2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class : meta.class.python, source.python, storage.type.class.python
2020
: meta.class.inheritance.python, meta.class.python, source.python
2121
Bar : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python
2222
. : 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
23+
name : entity.other.inherited-class.python, meta.class.inheritance.python, meta.class.python, source.python
2424
= : keyword.operator.assignment.python, meta.class.inheritance.python, meta.class.python, source.python
2525
{ : meta.class.inheritance.python, meta.class.python, punctuation.definition.dict.begin.python, source.python
2626
' : meta.class.inheritance.python, meta.class.python, punctuation.definition.string.begin.python, source.python, string.quoted.single.python

0 commit comments

Comments
 (0)