Skip to content

Commit 9f7e839

Browse files
committed
Make operators scoping more granular (to match Atom language-python)
1 parent 13bf534 commit 9f7e839

File tree

29 files changed

+214
-96
lines changed

29 files changed

+214
-96
lines changed

grammars/MagicPython.cson

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,20 +445,34 @@ repository:
445445
446446
'''
447447
operator:
448-
name: "keyword.operator.python"
449448
match: '''
450449
(?x)
451-
\\b(?<!\\.)(
452-
and | or | not | in | is | for | if | else | await
453-
| (yield(\\s+from)?)
454-
)(?!\\s*:)\\b
450+
\\b(?<!\\.)
451+
(?:
452+
(and | or | not | in | is) (?# 1)
453+
|
454+
(for | if | else | await | (?:yield(?:\\s+from)?)) (?# 2)
455+
)
456+
(?!\\s*:)\\b
457+
458+
| (<< | >> | & | \\| | \\^ | ~) (?# 3)
459+
460+
| (\\*\\* | \\* | \\+ | - | % | // | / | @) (?# 4)
455461
456-
| != | == | >= | <= | << | >>
457-
| && | \\|\\| | \\*\\* | //
458-
| > | < | \\+ | - | \\* | % | \\| | & | \\^
459-
| ~ | / | @
462+
| (!= | == | >= | <= | < | >) (?# 5)
460463
461464
'''
465+
captures:
466+
"1":
467+
name: "keyword.operator.logical.python"
468+
"2":
469+
name: "keyword.control.flow.python"
470+
"3":
471+
name: "keyword.operator.bitwise.python"
472+
"4":
473+
name: "keyword.operator.arithmetic.python"
474+
"5":
475+
name: "keyword.operator.comparison.python"
462476
literal:
463477
patterns: [
464478
{
@@ -1394,16 +1408,36 @@ repository:
13941408
}
13951409
]
13961410
"function-arguments":
1397-
begin: "(\\()"
1411+
begin: '''
1412+
(?x)
1413+
(?:
1414+
(\\()
1415+
(?:\\s*(\\*\\*|\\*))?
1416+
)
1417+
1418+
'''
13981419
end: "(?=\\))(?!\\)\\s*\\()"
13991420
beginCaptures:
14001421
"1":
14011422
name: "punctuation.definition.arguments.begin.python"
1423+
"2":
1424+
name: "keyword.operator.unpacking.arguments.python"
14021425
contentName: "meta.function-call.arguments.python"
14031426
patterns: [
14041427
{
1405-
name: "punctuation.separator.arguments.python"
1406-
match: ","
1428+
match: '''
1429+
(?x)
1430+
(?:
1431+
(,)
1432+
(?:\\s*(\\*\\*|\\*))?
1433+
)
1434+
1435+
'''
1436+
captures:
1437+
"1":
1438+
name: "punctuation.separator.arguments.python"
1439+
"2":
1440+
name: "keyword.operator.unpacking.arguments.python"
14071441
}
14081442
{
14091443
include: "#lambda-incomplete"

grammars/MagicPython.syntax.yaml

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,28 @@ repository:
327327
| =
328328
329329
operator:
330-
name: keyword.operator.python
331330
match: |
332331
(?x)
333-
\b(?<!\.)(
334-
and | or | not | in | is | for | if | else | await
335-
| (yield(\s+from)?)
336-
)(?!\s*:)\b
332+
\b(?<!\.)
333+
(?:
334+
(and | or | not | in | is) (?# 1)
335+
|
336+
(for | if | else | await | (?:yield(?:\s+from)?)) (?# 2)
337+
)
338+
(?!\s*:)\b
339+
340+
| (<< | >> | & | \| | \^ | ~) (?# 3)
337341
338-
| != | == | >= | <= | << | >>
339-
| && | \|\| | \*\* | //
340-
| > | < | \+ | - | \* | % | \| | & | \^
341-
| ~ | / | @
342+
| (\*\* | \* | \+ | - | % | // | / | @) (?# 4)
343+
344+
| (!= | == | >= | <= | < | >) (?# 5)
345+
346+
captures:
347+
'1': {name: keyword.operator.logical.python}
348+
'2': {name: keyword.control.flow.python}
349+
'3': {name: keyword.operator.bitwise.python}
350+
'4': {name: keyword.operator.arithmetic.python}
351+
'5': {name: keyword.operator.comparison.python}
342352

343353
literal:
344354
patterns:
@@ -936,14 +946,27 @@ repository:
936946
\b ([[:alpha:]_]\w*) \b
937947
938948
function-arguments:
939-
begin: (\()
949+
begin: |
950+
(?x)
951+
(?:
952+
(\()
953+
(?:\s*(\*\*|\*))?
954+
)
940955
end: (?=\))(?!\)\s*\()
941956
beginCaptures:
942957
'1': {name: punctuation.definition.arguments.begin.python}
958+
'2': {name: keyword.operator.unpacking.arguments.python}
943959
contentName: meta.function-call.arguments.python
944960
patterns:
945-
- name: punctuation.separator.arguments.python
946-
match: ','
961+
- match: |
962+
(?x)
963+
(?:
964+
(,)
965+
(?:\s*(\*\*|\*))?
966+
)
967+
captures:
968+
'1': {name: punctuation.separator.arguments.python}
969+
'2': {name: keyword.operator.unpacking.arguments.python}
947970
- include: '#lambda-incomplete'
948971
- include: '#illegal-names'
949972
- match: '\b([[:alpha:]_]\w*)\s*(=)'

grammars/MagicPython.tmLanguage

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -699,20 +699,50 @@
699699
</dict>
700700
<key>operator</key>
701701
<dict>
702-
<key>name</key>
703-
<string>keyword.operator.python</string>
704702
<key>match</key>
705703
<string>(?x)
706-
\b(?&lt;!\.)(
707-
and | or | not | in | is | for | if | else | await
708-
| (yield(\s+from)?)
709-
)(?!\s*:)\b
704+
\b(?&lt;!\.)
705+
(?:
706+
(and | or | not | in | is) (?# 1)
707+
|
708+
(for | if | else | await | (?:yield(?:\s+from)?)) (?# 2)
709+
)
710+
(?!\s*:)\b
711+
712+
| (&lt;&lt; | &gt;&gt; | &amp; | \| | \^ | ~) (?# 3)
710713
711-
| != | == | &gt;= | &lt;= | &lt;&lt; | &gt;&gt;
712-
| &amp;&amp; | \|\| | \*\* | //
713-
| &gt; | &lt; | \+ | - | \* | % | \| | &amp; | \^
714-
| ~ | / | @
714+
| (\*\* | \* | \+ | - | % | // | / | @) (?# 4)
715+
716+
| (!= | == | &gt;= | &lt;= | &lt; | &gt;) (?# 5)
715717
</string>
718+
<key>captures</key>
719+
<dict>
720+
<key>1</key>
721+
<dict>
722+
<key>name</key>
723+
<string>keyword.operator.logical.python</string>
724+
</dict>
725+
<key>2</key>
726+
<dict>
727+
<key>name</key>
728+
<string>keyword.control.flow.python</string>
729+
</dict>
730+
<key>3</key>
731+
<dict>
732+
<key>name</key>
733+
<string>keyword.operator.bitwise.python</string>
734+
</dict>
735+
<key>4</key>
736+
<dict>
737+
<key>name</key>
738+
<string>keyword.operator.arithmetic.python</string>
739+
</dict>
740+
<key>5</key>
741+
<dict>
742+
<key>name</key>
743+
<string>keyword.operator.comparison.python</string>
744+
</dict>
745+
</dict>
716746
</dict>
717747
<key>literal</key>
718748
<dict>
@@ -2235,7 +2265,12 @@ it&apos;s not tokenized as ellipsis.
22352265
<key>function-arguments</key>
22362266
<dict>
22372267
<key>begin</key>
2238-
<string>(\()</string>
2268+
<string>(?x)
2269+
(?:
2270+
(\()
2271+
(?:\s*(\*\*|\*))?
2272+
)
2273+
</string>
22392274
<key>end</key>
22402275
<string>(?=\))(?!\)\s*\()</string>
22412276
<key>beginCaptures</key>
@@ -2245,16 +2280,37 @@ it&apos;s not tokenized as ellipsis.
22452280
<key>name</key>
22462281
<string>punctuation.definition.arguments.begin.python</string>
22472282
</dict>
2283+
<key>2</key>
2284+
<dict>
2285+
<key>name</key>
2286+
<string>keyword.operator.unpacking.arguments.python</string>
2287+
</dict>
22482288
</dict>
22492289
<key>contentName</key>
22502290
<string>meta.function-call.arguments.python</string>
22512291
<key>patterns</key>
22522292
<array>
22532293
<dict>
2254-
<key>name</key>
2255-
<string>punctuation.separator.arguments.python</string>
22562294
<key>match</key>
2257-
<string>,</string>
2295+
<string>(?x)
2296+
(?:
2297+
(,)
2298+
(?:\s*(\*\*|\*))?
2299+
)
2300+
</string>
2301+
<key>captures</key>
2302+
<dict>
2303+
<key>1</key>
2304+
<dict>
2305+
<key>name</key>
2306+
<string>punctuation.separator.arguments.python</string>
2307+
</dict>
2308+
<key>2</key>
2309+
<dict>
2310+
<key>name</key>
2311+
<string>keyword.operator.unpacking.arguments.python</string>
2312+
</dict>
2313+
</dict>
22582314
</dict>
22592315
<dict>
22602316
<key>include</key>

misc/scopes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,22 @@ invalid.illegal.prefix.python
4040
keyword.codetag.notation.python
4141
keyword.control.flow.python
4242
keyword.invalid.illegal.name.python
43+
keyword.operator.arithmetic.python
4344
keyword.operator.assignment.python
45+
keyword.operator.bitwise.python
46+
keyword.operator.comparison.python
4447
keyword.operator.conditional.negative.regexp
4548
keyword.operator.conditional.regexp
4649
keyword.operator.disjunction.regexp
50+
keyword.operator.logical.python
4751
keyword.operator.lookahead.negative.regexp
4852
keyword.operator.lookahead.regexp
4953
keyword.operator.lookbehind.negative.regexp
5054
keyword.operator.lookbehind.regexp
5155
keyword.operator.negation.regexp
5256
keyword.operator.python
5357
keyword.operator.quantifier.regexp
58+
keyword.operator.unpacking.arguments.python
5459
meta.backreference.named.regexp
5560
meta.backreference.regexp
5661
meta.character.set.regexp

test/calls/call1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
] : meta.function-call.arguments.python, meta.function-call.python, meta.item-access.python, punctuation.definition.arguments.end.python, source.python
1616
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
1717
: meta.function-call.arguments.python, meta.function-call.python, source.python
18-
* : keyword.operator.python, meta.function-call.arguments.python, meta.function-call.python, source.python
18+
* : keyword.operator.unpacking.arguments.python, meta.function-call.arguments.python, meta.function-call.python, source.python
1919
args : meta.function-call.arguments.python, meta.function-call.python, source.python
2020
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
2121
: meta.function-call.arguments.python, meta.function-call.python, source.python
@@ -32,6 +32,6 @@
3232
} : meta.function-call.arguments.python, meta.function-call.python, punctuation.definition.dict.end.python, source.python
3333
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
3434
: meta.function-call.arguments.python, meta.function-call.python, source.python
35-
** : keyword.operator.python, meta.function-call.arguments.python, meta.function-call.python, source.python
35+
** : keyword.operator.unpacking.arguments.python, meta.function-call.arguments.python, meta.function-call.python, source.python
3636
kwargs : meta.function-call.arguments.python, meta.function-call.python, source.python
3737
) : meta.function-call.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
@@ -23,7 +23,7 @@
2323
. : source.python
2424
None : keyword.invalid.illegal.name.python, source.python
2525
: source.python
26-
and : keyword.operator.python, source.python
26+
and : keyword.operator.logical.python, source.python
2727
foo. : source.python
2828
None : constant.language.python, source.python
2929
. : source.python

test/calls/print1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
" : punctuation.definition.string.end.python, source.python, string.quoted.single.python
1919
, : source.python
2020
2 : constant.numeric.dec.python, source.python
21-
* : keyword.operator.python, source.python
21+
* : keyword.operator.arithmetic.python, source.python
2222
2 : constant.numeric.dec.python, source.python
2323
print : meta.function-call.python, source.python, support.function.builtin.python
2424
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
@@ -28,7 +28,7 @@
2828
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
2929
: meta.function-call.arguments.python, meta.function-call.python, source.python
3030
2 : constant.numeric.dec.python, meta.function-call.arguments.python, meta.function-call.python, source.python
31-
* : keyword.operator.python, meta.function-call.arguments.python, meta.function-call.python, source.python
31+
* : keyword.operator.arithmetic.python, meta.function-call.arguments.python, meta.function-call.python, source.python
3232
2 : constant.numeric.dec.python, meta.function-call.arguments.python, meta.function-call.python, source.python
3333
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python
3434
print : source.python, support.function.builtin.python
@@ -50,7 +50,7 @@
5050
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python
5151
print : source.python, support.function.builtin.python
5252
: source.python
53-
>> : keyword.operator.python, source.python
53+
>> : keyword.operator.bitwise.python, source.python
5454
sys.stderr, : source.python
5555
" : punctuation.definition.string.begin.python, source.python, string.quoted.single.python
5656
er : source.python, string.quoted.single.python

test/classes/class12.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def : meta.function.python, source.python, storage.type.function.pytho
6161
: source.python
6262
cls : source.python, variable.language.special.cls.python
6363
: source.python
64-
+ : keyword.operator.python, source.python
64+
+ : keyword.operator.arithmetic.python, source.python
6565
: source.python
6666
1 : constant.numeric.dec.python, source.python
6767
a : source.python

test/docstrings/oneline1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
>>> : keyword.control.flow.python, source.python, string.quoted.docstring.multi.python
2121
print('''docstring''') : source.python, string.quoted.docstring.multi.python
2222
""" : punctuation.definition.string.end.python, source.python, string.quoted.docstring.multi.python
23-
await : keyword.operator.python, source.python
23+
await : keyword.control.flow.python, source.python
2424
""" : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.multi.python
2525
\n : constant.character.python, source.python, string.quoted.docstring.multi.python
2626
>>> print('''docstring''') : source.python, string.quoted.docstring.multi.python
2727
""" : punctuation.definition.string.end.python, source.python, string.quoted.docstring.multi.python
28-
await : keyword.operator.python, source.python
28+
await : keyword.control.flow.python, source.python
2929
""" : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.multi.python
3030
: source.python, string.quoted.docstring.multi.python
3131
>>> : keyword.control.flow.python, source.python, string.quoted.docstring.multi.python
3232
print('''docstring''') : source.python, string.quoted.docstring.multi.python
3333
""" : punctuation.definition.string.end.python, source.python, string.quoted.docstring.multi.python
34-
await : keyword.operator.python, source.python
34+
await : keyword.control.flow.python, source.python
3535
""" : punctuation.definition.string.begin.python, source.python, string.quoted.docstring.multi.python
3636
1 >>> print('''docstring''') : source.python, string.quoted.docstring.multi.python
3737
""" : punctuation.definition.string.end.python, source.python, string.quoted.docstring.multi.python
38-
await : keyword.operator.python, source.python
38+
await : keyword.control.flow.python, source.python

0 commit comments

Comments
 (0)