Skip to content

Commit 9540297

Browse files
committed
Add support for new Python 3.7 attrs/builtins
Fixes #151 and #126
1 parent 4030374 commit 9540297

File tree

7 files changed

+76
-16
lines changed

7 files changed

+76
-16
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ node_modules
22
.DS_Store
33
*.cache
44
*.pyc
5-
5+
package-lock.json

grammars/MagicPython.cson

+5-5
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ repository:
17291729
match: '''
17301730
(?x)
17311731
(?<!\\.) \\b(
1732-
__import__ | abs | all | any | ascii | bin | callable
1732+
__import__ | abs | all | any | ascii | bin | breakpoint | callable
17331733
| chr | compile | copyright | credits | delattr | dir | divmod
17341734
| enumerate | eval | exec | exit | filter | format | getattr
17351735
| globals | hasattr | hash | help | hex | id | input
@@ -1810,10 +1810,10 @@ repository:
18101810
(?x)
18111811
\\b(
18121812
__(?:
1813-
all | bases | builtins | class | code | debug | defaults | dict
1814-
| doc | file | func | kwdefaults | members
1815-
| metaclass | methods | module | mro | name
1816-
| qualname | self | signature | slots | subclasses
1813+
all | bases | builtins | class | class_getitem | code | debug
1814+
| defaults | dict | doc | file | func | kwdefaults | members
1815+
| metaclass | methods | module | mro | mro_entries | name
1816+
| qualname | post_init | self | signature | slots | subclasses
18171817
| version | weakref | wrapped | annotations | classcell
18181818
| spec | path | package | future | traceback
18191819
)__

grammars/MagicPython.tmLanguage

+5-5
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,7 @@
27082708
<key>match</key>
27092709
<string>(?x)
27102710
(?&lt;!\.) \b(
2711-
__import__ | abs | all | any | ascii | bin | callable
2711+
__import__ | abs | all | any | ascii | bin | breakpoint | callable
27122712
| chr | compile | copyright | credits | delattr | dir | divmod
27132713
| enumerate | eval | exec | exit | filter | format | getattr
27142714
| globals | hasattr | hash | help | hex | id | input
@@ -2798,10 +2798,10 @@ indirectly through syntactic constructs
27982798
<string>(?x)
27992799
\b(
28002800
__(?:
2801-
all | bases | builtins | class | code | debug | defaults | dict
2802-
| doc | file | func | kwdefaults | members
2803-
| metaclass | methods | module | mro | name
2804-
| qualname | self | signature | slots | subclasses
2801+
all | bases | builtins | class | class_getitem | code | debug
2802+
| defaults | dict | doc | file | func | kwdefaults | members
2803+
| metaclass | methods | module | mro | mro_entries | name
2804+
| qualname | post_init | self | signature | slots | subclasses
28052805
| version | weakref | wrapped | annotations | classcell
28062806
| spec | path | package | future | traceback
28072807
)__

grammars/src/MagicPython.syntax.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ repository:
12941294
match: |
12951295
(?x)
12961296
(?<!\.) \b(
1297-
__import__ | abs | all | any | ascii | bin | callable
1297+
__import__ | abs | all | any | ascii | bin | breakpoint | callable
12981298
| chr | compile | copyright | credits | delattr | dir | divmod
12991299
| enumerate | eval | exec | exit | filter | format | getattr
13001300
| globals | hasattr | hash | help | hex | id | input
@@ -1364,10 +1364,10 @@ repository:
13641364
(?x)
13651365
\b(
13661366
__(?:
1367-
all | bases | builtins | class | code | debug | defaults | dict
1368-
| doc | file | func | kwdefaults | members
1369-
| metaclass | methods | module | mro | name
1370-
| qualname | self | signature | slots | subclasses
1367+
all | bases | builtins | class | class_getitem | code | debug
1368+
| defaults | dict | doc | file | func | kwdefaults | members
1369+
| metaclass | methods | module | mro | mro_entries | name
1370+
| qualname | post_init | self | signature | slots | subclasses
13711371
| version | weakref | wrapped | annotations | classcell
13721372
| spec | path | package | future | traceback
13731373
)__

test/atom-spec/python-spec.js

+36
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,17 @@ describe("Grammar Tests", function() {
514514
expect(tokens[1][3].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.end.python"]);
515515
});
516516

517+
it("test/builtins/builtins7.py",
518+
function() {
519+
tokens = grammar.tokenizeLines("breakpoint()")
520+
expect(tokens[0][0].value).toBe("breakpoint");
521+
expect(tokens[0][0].scopes).toEqual(["source.python","meta.function-call.python","support.function.builtin.python"]);
522+
expect(tokens[0][1].value).toBe("(");
523+
expect(tokens[0][1].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]);
524+
expect(tokens[0][2].value).toBe(")");
525+
expect(tokens[0][2].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.end.python"]);
526+
});
527+
517528
it("test/calls/call1.py",
518529
function() {
519530
tokens = grammar.tokenizeLines("some_call(A, b, c[1], *args, FOO=lambda:{'q': 42}, **kwargs)")
@@ -6177,6 +6188,31 @@ describe("Grammar Tests", function() {
61776188
expect(tokens[1][0].scopes).toEqual(["source.python"]);
61786189
});
61796190

6191+
it("test/expressions/special2.py",
6192+
function() {
6193+
tokens = grammar.tokenizeLines("__post_init__\ndef __class_getitem__(): pass\n__mro_entries__")
6194+
expect(tokens[0][0].value).toBe("__post_init__");
6195+
expect(tokens[0][0].scopes).toEqual(["source.python","support.variable.magic.python"]);
6196+
expect(tokens[1][0].value).toBe("def");
6197+
expect(tokens[1][0].scopes).toEqual(["source.python","meta.function.python","storage.type.function.python"]);
6198+
expect(tokens[1][1].value).toBe(" ");
6199+
expect(tokens[1][1].scopes).toEqual(["source.python","meta.function.python"]);
6200+
expect(tokens[1][2].value).toBe("__class_getitem__");
6201+
expect(tokens[1][2].scopes).toEqual(["source.python","meta.function.python","support.variable.magic.python"]);
6202+
expect(tokens[1][3].value).toBe("(");
6203+
expect(tokens[1][3].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.definition.parameters.begin.python"]);
6204+
expect(tokens[1][4].value).toBe(")");
6205+
expect(tokens[1][4].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.definition.parameters.end.python"]);
6206+
expect(tokens[1][5].value).toBe(":");
6207+
expect(tokens[1][5].scopes).toEqual(["source.python","meta.function.python","punctuation.section.function.begin.python"]);
6208+
expect(tokens[1][6].value).toBe(" ");
6209+
expect(tokens[1][6].scopes).toEqual(["source.python"]);
6210+
expect(tokens[1][7].value).toBe("pass");
6211+
expect(tokens[1][7].scopes).toEqual(["source.python","keyword.control.flow.python"]);
6212+
expect(tokens[2][0].value).toBe("__mro_entries__");
6213+
expect(tokens[2][0].scopes).toEqual(["source.python","support.variable.magic.python"]);
6214+
});
6215+
61806216
it("test/fstrings/comment1.py",
61816217
function() {
61826218
tokens = grammar.tokenizeLines("f'prefix{10 # comment, making the string technically illegal\ndef foo(): pass")

test/builtins/builtins7.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
breakpoint()
2+
3+
4+
5+
6+
breakpoint : meta.function-call.python, source.python, support.function.builtin.python
7+
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
8+
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python

test/expressions/special2.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
__post_init__
2+
def __class_getitem__(): pass
3+
__mro_entries__
4+
5+
6+
7+
__post_init__ : source.python, support.variable.magic.python
8+
def : meta.function.python, source.python, storage.type.function.python
9+
: meta.function.python, source.python
10+
__class_getitem__ : meta.function.python, source.python, support.variable.magic.python
11+
( : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.begin.python, source.python
12+
) : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.end.python, source.python
13+
: : meta.function.python, punctuation.section.function.begin.python, source.python
14+
: source.python
15+
pass : keyword.control.flow.python, source.python
16+
__mro_entries__ : source.python, support.variable.magic.python

0 commit comments

Comments
 (0)