Skip to content

Commit ad6bd62

Browse files
committed
Update the * and ** in funciton call scopes.
Use `keyword.operator.unpacking.arguments.python` more consistently. Issue #132.
1 parent 7c43d1c commit ad6bd62

File tree

7 files changed

+114
-61
lines changed

7 files changed

+114
-61
lines changed

grammars/MagicPython.cson

+6-16
Original file line numberDiff line numberDiff line change
@@ -1613,35 +1613,25 @@ repository:
16131613
}
16141614
]
16151615
"function-arguments":
1616-
begin: '''
1617-
(?x)
1618-
(?:
1619-
(\\()
1620-
(?:\\s*(\\*\\*|\\*))?
1621-
)
1622-
1623-
'''
1616+
begin: "(\\()"
16241617
end: "(?=\\))(?!\\)\\s*\\()"
16251618
beginCaptures:
16261619
"1":
16271620
name: "punctuation.definition.arguments.begin.python"
1628-
"2":
1629-
name: "keyword.operator.unpacking.arguments.python"
16301621
contentName: "meta.function-call.arguments.python"
16311622
patterns: [
1623+
{
1624+
name: "punctuation.separator.arguments.python"
1625+
match: "(,)"
1626+
}
16321627
{
16331628
match: '''
16341629
(?x)
1635-
(?:
1636-
(,)
1637-
(?:\\s*(\\*\\*|\\*))?
1638-
)
1630+
(?:(?<=[,(])|^) \\s* (\\*{1,2})
16391631
16401632
'''
16411633
captures:
16421634
"1":
1643-
name: "punctuation.separator.arguments.python"
1644-
"2":
16451635
name: "keyword.operator.unpacking.arguments.python"
16461636
}
16471637
{

grammars/MagicPython.tmLanguage

+8-20
Original file line numberDiff line numberDiff line change
@@ -2528,12 +2528,7 @@
25282528
<key>function-arguments</key>
25292529
<dict>
25302530
<key>begin</key>
2531-
<string>(?x)
2532-
(?:
2533-
(\()
2534-
(?:\s*(\*\*|\*))?
2535-
)
2536-
</string>
2531+
<string>(\()</string>
25372532
<key>end</key>
25382533
<string>(?=\))(?!\)\s*\()</string>
25392534
<key>beginCaptures</key>
@@ -2543,32 +2538,25 @@
25432538
<key>name</key>
25442539
<string>punctuation.definition.arguments.begin.python</string>
25452540
</dict>
2546-
<key>2</key>
2547-
<dict>
2548-
<key>name</key>
2549-
<string>keyword.operator.unpacking.arguments.python</string>
2550-
</dict>
25512541
</dict>
25522542
<key>contentName</key>
25532543
<string>meta.function-call.arguments.python</string>
25542544
<key>patterns</key>
25552545
<array>
2546+
<dict>
2547+
<key>name</key>
2548+
<string>punctuation.separator.arguments.python</string>
2549+
<key>match</key>
2550+
<string>(,)</string>
2551+
</dict>
25562552
<dict>
25572553
<key>match</key>
25582554
<string>(?x)
2559-
(?:
2560-
(,)
2561-
(?:\s*(\*\*|\*))?
2562-
)
2555+
(?:(?&lt;=[,(])|^) \s* (\*{1,2})
25632556
</string>
25642557
<key>captures</key>
25652558
<dict>
25662559
<key>1</key>
2567-
<dict>
2568-
<key>name</key>
2569-
<string>punctuation.separator.arguments.python</string>
2570-
</dict>
2571-
<key>2</key>
25722560
<dict>
25732561
<key>name</key>
25742562
<string>keyword.operator.unpacking.arguments.python</string>

grammars/src/MagicPython.syntax.yaml

+5-13
Original file line numberDiff line numberDiff line change
@@ -1219,27 +1219,19 @@ repository:
12191219
\b ([[:alpha:]_]\w*) \b
12201220
12211221
function-arguments:
1222-
begin: |
1223-
(?x)
1224-
(?:
1225-
(\()
1226-
(?:\s*(\*\*|\*))?
1227-
)
1222+
begin: (\()
12281223
end: (?=\))(?!\)\s*\()
12291224
beginCaptures:
12301225
'1': {name: punctuation.definition.arguments.begin.python}
1231-
'2': {name: keyword.operator.unpacking.arguments.python}
12321226
contentName: meta.function-call.arguments.python
12331227
patterns:
1228+
- name: punctuation.separator.arguments.python
1229+
match: (,)
12341230
- match: |
12351231
(?x)
1236-
(?:
1237-
(,)
1238-
(?:\s*(\*\*|\*))?
1239-
)
1232+
(?:(?<=[,(])|^) \s* (\*{1,2})
12401233
captures:
1241-
'1': {name: punctuation.separator.arguments.python}
1242-
'2': {name: keyword.operator.unpacking.arguments.python}
1234+
'1': {name: keyword.operator.unpacking.arguments.python}
12431235
- include: '#lambda-incomplete'
12441236
- include: '#illegal-names'
12451237
- match: '\b([[:alpha:]_]\w*)\s*(=)(?!=)'

test/atom-spec/python-spec.js

+57-6
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,57 @@ describe("Grammar Tests", function() {
589589
expect(tokens[0][34].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.end.python"]);
590590
});
591591

592+
it("test/calls/call10.py",
593+
function() {
594+
tokens = grammar.tokenizeLines("x = foo(True,\n 3 * 4,\n *a,\n **bar)")
595+
expect(tokens[0][0].value).toBe("x");
596+
expect(tokens[0][0].scopes).toEqual(["source.python"]);
597+
expect(tokens[0][1].value).toBe(" ");
598+
expect(tokens[0][1].scopes).toEqual(["source.python"]);
599+
expect(tokens[0][2].value).toBe("=");
600+
expect(tokens[0][2].scopes).toEqual(["source.python","keyword.operator.assignment.python"]);
601+
expect(tokens[0][3].value).toBe(" ");
602+
expect(tokens[0][3].scopes).toEqual(["source.python"]);
603+
expect(tokens[0][4].value).toBe("foo");
604+
expect(tokens[0][4].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.generic.python"]);
605+
expect(tokens[0][5].value).toBe("(");
606+
expect(tokens[0][5].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]);
607+
expect(tokens[0][6].value).toBe("True");
608+
expect(tokens[0][6].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","constant.language.python"]);
609+
expect(tokens[0][7].value).toBe(",");
610+
expect(tokens[0][7].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","punctuation.separator.arguments.python"]);
611+
expect(tokens[1][0].value).toBe(" ");
612+
expect(tokens[1][0].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
613+
expect(tokens[1][1].value).toBe("3");
614+
expect(tokens[1][1].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","constant.numeric.dec.python"]);
615+
expect(tokens[1][2].value).toBe(" ");
616+
expect(tokens[1][2].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
617+
expect(tokens[1][3].value).toBe("*");
618+
expect(tokens[1][3].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","keyword.operator.arithmetic.python"]);
619+
expect(tokens[1][4].value).toBe(" ");
620+
expect(tokens[1][4].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
621+
expect(tokens[1][5].value).toBe("4");
622+
expect(tokens[1][5].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","constant.numeric.dec.python"]);
623+
expect(tokens[1][6].value).toBe(",");
624+
expect(tokens[1][6].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","punctuation.separator.arguments.python"]);
625+
expect(tokens[2][0].value).toBe(" ");
626+
expect(tokens[2][0].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
627+
expect(tokens[2][1].value).toBe("*");
628+
expect(tokens[2][1].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","keyword.operator.unpacking.arguments.python"]);
629+
expect(tokens[2][2].value).toBe("a");
630+
expect(tokens[2][2].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
631+
expect(tokens[2][3].value).toBe(",");
632+
expect(tokens[2][3].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","punctuation.separator.arguments.python"]);
633+
expect(tokens[3][0].value).toBe(" ");
634+
expect(tokens[3][0].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
635+
expect(tokens[3][1].value).toBe("**");
636+
expect(tokens[3][1].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","keyword.operator.unpacking.arguments.python"]);
637+
expect(tokens[3][2].value).toBe("bar");
638+
expect(tokens[3][2].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
639+
expect(tokens[3][3].value).toBe(")");
640+
expect(tokens[3][3].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.end.python"]);
641+
});
642+
592643
it("test/calls/call2.py",
593644
function() {
594645
tokens = grammar.tokenizeLines("foo(from=1)")
@@ -702,7 +753,7 @@ describe("Grammar Tests", function() {
702753
expect(tokens[0][1].value).toBe("(");
703754
expect(tokens[0][1].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]);
704755
expect(tokens[0][2].value).toBe("*");
705-
expect(tokens[0][2].scopes).toEqual(["source.python","meta.function-call.python","keyword.operator.unpacking.arguments.python"]);
756+
expect(tokens[0][2].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","keyword.operator.unpacking.arguments.python"]);
706757
expect(tokens[0][3].value).toBe("a");
707758
expect(tokens[0][3].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
708759
expect(tokens[0][4].value).toBe(")");
@@ -712,7 +763,7 @@ describe("Grammar Tests", function() {
712763
expect(tokens[1][1].value).toBe("(");
713764
expect(tokens[1][1].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]);
714765
expect(tokens[1][2].value).toBe("**");
715-
expect(tokens[1][2].scopes).toEqual(["source.python","meta.function-call.python","keyword.operator.unpacking.arguments.python"]);
766+
expect(tokens[1][2].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","keyword.operator.unpacking.arguments.python"]);
716767
expect(tokens[1][3].value).toBe("a");
717768
expect(tokens[1][3].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
718769
expect(tokens[1][4].value).toBe(")");
@@ -727,9 +778,9 @@ describe("Grammar Tests", function() {
727778
expect(tokens[0][1].value).toBe("(");
728779
expect(tokens[0][1].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]);
729780
expect(tokens[0][2].value).toBe(" ");
730-
expect(tokens[0][2].scopes).toEqual(["source.python","meta.function-call.python"]);
781+
expect(tokens[0][2].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
731782
expect(tokens[0][3].value).toBe("*");
732-
expect(tokens[0][3].scopes).toEqual(["source.python","meta.function-call.python","keyword.operator.unpacking.arguments.python"]);
783+
expect(tokens[0][3].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","keyword.operator.unpacking.arguments.python"]);
733784
expect(tokens[0][4].value).toBe("a");
734785
expect(tokens[0][4].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
735786
expect(tokens[0][5].value).toBe(" ");
@@ -751,9 +802,9 @@ describe("Grammar Tests", function() {
751802
expect(tokens[1][1].value).toBe("(");
752803
expect(tokens[1][1].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]);
753804
expect(tokens[1][2].value).toBe(" ");
754-
expect(tokens[1][2].scopes).toEqual(["source.python","meta.function-call.python"]);
805+
expect(tokens[1][2].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
755806
expect(tokens[1][3].value).toBe("**");
756-
expect(tokens[1][3].scopes).toEqual(["source.python","meta.function-call.python","keyword.operator.unpacking.arguments.python"]);
807+
expect(tokens[1][3].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python","keyword.operator.unpacking.arguments.python"]);
757808
expect(tokens[1][4].value).toBe("a");
758809
expect(tokens[1][4].scopes).toEqual(["source.python","meta.function-call.python","meta.function-call.arguments.python"]);
759810
expect(tokens[1][5].value).toBe(" ");

test/calls/call10.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
x = foo(True,
2+
3 * 4,
3+
*a,
4+
**bar)
5+
6+
7+
8+
9+
10+
x : source.python
11+
: source.python
12+
= : keyword.operator.assignment.python, source.python
13+
: source.python
14+
foo : meta.function-call.generic.python, meta.function-call.python, source.python
15+
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
16+
True : constant.language.python, meta.function-call.arguments.python, meta.function-call.python, source.python
17+
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
18+
: meta.function-call.arguments.python, meta.function-call.python, source.python
19+
3 : constant.numeric.dec.python, meta.function-call.arguments.python, meta.function-call.python, source.python
20+
: meta.function-call.arguments.python, meta.function-call.python, source.python
21+
* : keyword.operator.arithmetic.python, meta.function-call.arguments.python, meta.function-call.python, source.python
22+
: meta.function-call.arguments.python, meta.function-call.python, source.python
23+
4 : constant.numeric.dec.python, meta.function-call.arguments.python, meta.function-call.python, source.python
24+
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
25+
: meta.function-call.arguments.python, meta.function-call.python, source.python
26+
* : keyword.operator.unpacking.arguments.python, meta.function-call.arguments.python, meta.function-call.python, source.python
27+
a : meta.function-call.arguments.python, meta.function-call.python, source.python
28+
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
29+
: meta.function-call.arguments.python, meta.function-call.python, source.python
30+
** : keyword.operator.unpacking.arguments.python, meta.function-call.arguments.python, meta.function-call.python, source.python
31+
bar : meta.function-call.arguments.python, meta.function-call.python, source.python
32+
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python

test/calls/call5.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
f : meta.function-call.generic.python, meta.function-call.python, source.python
77
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
8-
* : keyword.operator.unpacking.arguments.python, meta.function-call.python, source.python
8+
* : keyword.operator.unpacking.arguments.python, meta.function-call.arguments.python, meta.function-call.python, source.python
99
a : meta.function-call.arguments.python, meta.function-call.python, source.python
1010
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python
1111
f : meta.function-call.generic.python, meta.function-call.python, source.python
1212
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
13-
** : keyword.operator.unpacking.arguments.python, meta.function-call.python, source.python
13+
** : keyword.operator.unpacking.arguments.python, meta.function-call.arguments.python, meta.function-call.python, source.python
1414
a : meta.function-call.arguments.python, meta.function-call.python, source.python
1515
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python

test/calls/call6.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
f : meta.function-call.generic.python, meta.function-call.python, source.python
77
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
8-
: meta.function-call.python, source.python
9-
* : keyword.operator.unpacking.arguments.python, meta.function-call.python, source.python
8+
: meta.function-call.arguments.python, meta.function-call.python, source.python
9+
* : keyword.operator.unpacking.arguments.python, meta.function-call.arguments.python, meta.function-call.python, source.python
1010
a : meta.function-call.arguments.python, meta.function-call.python, source.python
1111
: meta.function-call.arguments.python, meta.function-call.python, source.python
1212
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python
@@ -17,8 +17,8 @@
1717
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python
1818
f : meta.function-call.generic.python, meta.function-call.python, source.python
1919
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
20-
: meta.function-call.python, source.python
21-
** : keyword.operator.unpacking.arguments.python, meta.function-call.python, source.python
20+
: meta.function-call.arguments.python, meta.function-call.python, source.python
21+
** : keyword.operator.unpacking.arguments.python, meta.function-call.arguments.python, meta.function-call.python, source.python
2222
a : meta.function-call.arguments.python, meta.function-call.python, source.python
2323
: meta.function-call.arguments.python, meta.function-call.python, source.python
2424
, : meta.function-call.arguments.python, meta.function-call.python, punctuation.separator.arguments.python, source.python

0 commit comments

Comments
 (0)