Skip to content

Commit dd48b8f

Browse files
committed
Add some more specific scopes for member access.
Add `meta.attribute.python` to mark otherwise non-special attributes. Add `meta.indexed-name.python` to mark the name of the object being indexed. In combination with `meta.member.access.python` the above scopes can help highlight member access that is no otherwise using a builtin or some other special case. For highlighting method names in method calls the combination of `meta.member.access.python` and `meta.function-call.generic.python` could be used. Fixes #188.
1 parent 0b09c1f commit dd48b8f

File tree

21 files changed

+110
-63
lines changed

21 files changed

+110
-63
lines changed

grammars/MagicPython.cson

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ repository:
431431
{
432432
include: "#member-access-base"
433433
}
434+
{
435+
include: "#member-access-attribute"
436+
}
434437
]
435438
"member-access-base":
436439
patterns: [
@@ -453,6 +456,14 @@ repository:
453456
include: "#item-access"
454457
}
455458
]
459+
"member-access-attribute":
460+
comment: "Highlight attribute access in otherwise non-specialized cases."
461+
name: "meta.attribute.python"
462+
match: '''
463+
(?x)
464+
\\b ([[:alpha:]_]\\w*) \\b
465+
466+
'''
456467
"special-names":
457468
name: "constant.other.caps.python"
458469
match: '''
@@ -1488,6 +1499,7 @@ repository:
14881499
include: "#special-names"
14891500
}
14901501
{
1502+
name: "meta.indexed-name.python"
14911503
match: '''
14921504
(?x)
14931505
\\b ([[:alpha:]_]\\w*) \\b

grammars/MagicPython.tmLanguage

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ it's probably control flow like:
647647
<key>include</key>
648648
<string>#member-access-base</string>
649649
</dict>
650+
<dict>
651+
<key>include</key>
652+
<string>#member-access-attribute</string>
653+
</dict>
650654
</array>
651655
</dict>
652656
<key>member-access-base</key>
@@ -679,6 +683,17 @@ it's probably control flow like:
679683
</dict>
680684
</array>
681685
</dict>
686+
<key>member-access-attribute</key>
687+
<dict>
688+
<key>comment</key>
689+
<string>Highlight attribute access in otherwise non-specialized cases.</string>
690+
<key>name</key>
691+
<string>meta.attribute.python</string>
692+
<key>match</key>
693+
<string>(?x)
694+
\b ([[:alpha:]_]\w*) \b
695+
</string>
696+
</dict>
682697
<key>special-names</key>
683698
<dict>
684699
<key>name</key>
@@ -2340,6 +2355,8 @@ it's probably control flow like:
23402355
<string>#special-names</string>
23412356
</dict>
23422357
<dict>
2358+
<key>name</key>
2359+
<string>meta.indexed-name.python</string>
23432360
<key>match</key>
23442361
<string>(?x)
23452362
\b ([[:alpha:]_]\w*) \b

grammars/src/MagicPython.syntax.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ repository:
449449
patterns:
450450
- include: '#function-call'
451451
- include: '#member-access-base'
452+
- include: '#member-access-attribute'
452453

453454
member-access-base:
454455
patterns:
@@ -459,6 +460,13 @@ repository:
459460
- include: '#line-continuation'
460461
- include: '#item-access'
461462

463+
member-access-attribute:
464+
comment: Highlight attribute access in otherwise non-specialized cases.
465+
name: meta.attribute.python
466+
match: |
467+
(?x)
468+
\b ([[:alpha:]_]\w*) \b
469+
462470
special-names:
463471
name: constant.other.caps.python
464472
match: |
@@ -1142,7 +1150,8 @@ repository:
11421150
- include: '#special-variables'
11431151
- include: '#builtin-functions'
11441152
- include: '#special-names'
1145-
- match: |
1153+
- name: meta.indexed-name.python
1154+
match: |
11461155
(?x)
11471156
\b ([[:alpha:]_]\w*) \b
11481157

misc/scopes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ keyword.operator.python
6060
keyword.operator.quantifier.regexp
6161
keyword.operator.unpacking.arguments.python
6262
keyword.operator.unpacking.parameter.python
63+
meta.attribute.python
6364
meta.backreference.named.regexp
6465
meta.backreference.regexp
6566
meta.character.set.regexp
@@ -73,6 +74,7 @@ meta.function-call.python
7374
meta.function.decorator.python
7475
meta.function.parameters.python
7576
meta.function.python
77+
meta.indexed-name.python
7678
meta.item-access.python
7779
meta.lambda-function.python
7880
meta.member.access.python

test/atom-spec/python-spec.js

Lines changed: 31 additions & 31 deletions
Large diffs are not rendered by default.

test/builtins/builtins3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
__builtins__ : source.python, support.variable.magic.python
7272
__builtins__ : source.python, support.variable.magic.python
7373
. : meta.member.access.python, punctuation.separator.period.python, source.python
74-
len : meta.member.access.python, source.python
74+
len : meta.attribute.python, meta.member.access.python, source.python
7575
print : meta.function-call.python, source.python, support.function.builtin.python
7676
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
7777
__builtins__ : meta.function-call.arguments.python, meta.function-call.python, source.python, support.variable.magic.python
@@ -183,4 +183,4 @@
183183
__traceback__ : meta.member.access.python, source.python, support.variable.magic.python
184184
some : source.python
185185
. : meta.member.access.python, punctuation.separator.period.python, source.python
186-
__notspecial__ : meta.member.access.python, source.python
186+
__notspecial__ : meta.attribute.python, meta.member.access.python, source.python

test/builtins/builtins4.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
some : source.python
1212
. : meta.member.access.python, punctuation.separator.period.python, source.python
13-
int : meta.member.access.python, source.python
13+
int : meta.attribute.python, meta.member.access.python, source.python
1414
some : source.python
1515
. : meta.member.access.python, punctuation.separator.period.python, source.python
16-
sum : meta.member.access.python, source.python
16+
sum : meta.attribute.python, meta.member.access.python, source.python
1717
some : source.python
1818
. : meta.member.access.python, punctuation.separator.period.python, source.python
19-
super : meta.member.access.python, source.python
19+
super : meta.attribute.python, meta.member.access.python, source.python
2020
some : source.python
2121
. : meta.member.access.python, punctuation.separator.period.python, source.python
22-
unicode : meta.member.access.python, source.python
22+
unicode : meta.attribute.python, meta.member.access.python, source.python
2323
some : source.python
2424
. : meta.member.access.python, punctuation.separator.period.python, source.python
25-
foo : meta.member.access.python, source.python
25+
foo : meta.attribute.python, meta.member.access.python, source.python
2626
some : source.python
2727
. : meta.member.access.python, punctuation.separator.period.python, source.python
28-
Exception : meta.member.access.python, source.python
28+
Exception : meta.attribute.python, meta.member.access.python, source.python

test/calls/call1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44

5+
56
some_call : meta.function-call.generic.python, meta.function-call.python, source.python
67
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
78
A : meta.function-call.arguments.python, meta.function-call.python, source.python
@@ -10,7 +11,7 @@
1011
b : meta.function-call.arguments.python, meta.function-call.python, source.python
1112
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
1213
: meta.function-call.arguments.python, meta.function-call.python, source.python
13-
c : meta.function-call.arguments.python, meta.function-call.python, meta.item-access.python, source.python
14+
c : meta.function-call.arguments.python, meta.function-call.python, meta.indexed-name.python, meta.item-access.python, source.python
1415
[ : meta.function-call.arguments.python, meta.function-call.python, meta.item-access.python, punctuation.definition.arguments.begin.python, source.python
1516
1 : constant.numeric.dec.python, meta.function-call.arguments.python, meta.function-call.python, meta.item-access.arguments.python, meta.item-access.python, source.python
1617
] : meta.function-call.arguments.python, meta.function-call.python, meta.item-access.python, punctuation.definition.arguments.end.python, source.python

test/calls/call4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
. : meta.member.access.python, punctuation.separator.period.python, source.python
3030
None : keyword.illegal.name.python, meta.member.access.python, source.python
3131
. : meta.member.access.python, punctuation.separator.period.python, source.python
32-
baz : meta.member.access.python, source.python
32+
baz : meta.attribute.python, meta.member.access.python, source.python

test/calls/print1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
>> : keyword.operator.bitwise.python, source.python
5858
sys : source.python
5959
. : meta.member.access.python, punctuation.separator.period.python, source.python
60-
stderr : meta.member.access.python, source.python
60+
stderr : meta.attribute.python, meta.member.access.python, source.python
6161
, : punctuation.separator.element.python, source.python
6262
: source.python
6363
" : punctuation.definition.string.begin.python, source.python, string.quoted.single.python
@@ -74,7 +74,7 @@
7474
= : keyword.operator.assignment.python, meta.function-call.arguments.python, meta.function-call.python, source.python
7575
sys : meta.function-call.arguments.python, meta.function-call.python, source.python
7676
. : meta.function-call.arguments.python, meta.function-call.python, meta.member.access.python, punctuation.separator.period.python, source.python
77-
stderr : meta.function-call.arguments.python, meta.function-call.python, meta.member.access.python, source.python
77+
stderr : meta.attribute.python, meta.function-call.arguments.python, meta.function-call.python, meta.member.access.python, source.python
7878
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python
7979
print : meta.function-call.python, source.python, support.function.builtin.python
8080
: meta.function-call.python, source.python

0 commit comments

Comments
 (0)