Skip to content

Commit

Permalink
Add support for new Python 3.7 attrs/builtins
Browse files Browse the repository at this point in the history
Fixes #151 and #126
  • Loading branch information
1st1 committed Oct 4, 2018
1 parent 4030374 commit 9540297
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ node_modules
.DS_Store
*.cache
*.pyc

package-lock.json
10 changes: 5 additions & 5 deletions grammars/MagicPython.cson
Original file line number Diff line number Diff line change
Expand Up @@ -1729,7 +1729,7 @@ repository:
match: '''
(?x)
(?<!\\.) \\b(
__import__ | abs | all | any | ascii | bin | callable
__import__ | abs | all | any | ascii | bin | breakpoint | callable
| chr | compile | copyright | credits | delattr | dir | divmod
| enumerate | eval | exec | exit | filter | format | getattr
| globals | hasattr | hash | help | hex | id | input
Expand Down Expand Up @@ -1810,10 +1810,10 @@ repository:
(?x)
\\b(
__(?:
all | bases | builtins | class | code | debug | defaults | dict
| doc | file | func | kwdefaults | members
| metaclass | methods | module | mro | name
| qualname | self | signature | slots | subclasses
all | bases | builtins | class | class_getitem | code | debug
| defaults | dict | doc | file | func | kwdefaults | members
| metaclass | methods | module | mro | mro_entries | name
| qualname | post_init | self | signature | slots | subclasses
| version | weakref | wrapped | annotations | classcell
| spec | path | package | future | traceback
)__
Expand Down
10 changes: 5 additions & 5 deletions grammars/MagicPython.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,7 @@
<key>match</key>
<string>(?x)
(?&lt;!\.) \b(
__import__ | abs | all | any | ascii | bin | callable
__import__ | abs | all | any | ascii | bin | breakpoint | callable
| chr | compile | copyright | credits | delattr | dir | divmod
| enumerate | eval | exec | exit | filter | format | getattr
| globals | hasattr | hash | help | hex | id | input
Expand Down Expand Up @@ -2798,10 +2798,10 @@ indirectly through syntactic constructs
<string>(?x)
\b(
__(?:
all | bases | builtins | class | code | debug | defaults | dict
| doc | file | func | kwdefaults | members
| metaclass | methods | module | mro | name
| qualname | self | signature | slots | subclasses
all | bases | builtins | class | class_getitem | code | debug
| defaults | dict | doc | file | func | kwdefaults | members
| metaclass | methods | module | mro | mro_entries | name
| qualname | post_init | self | signature | slots | subclasses
| version | weakref | wrapped | annotations | classcell
| spec | path | package | future | traceback
)__
Expand Down
10 changes: 5 additions & 5 deletions grammars/src/MagicPython.syntax.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ repository:
match: |
(?x)
(?<!\.) \b(
__import__ | abs | all | any | ascii | bin | callable
__import__ | abs | all | any | ascii | bin | breakpoint | callable
| chr | compile | copyright | credits | delattr | dir | divmod
| enumerate | eval | exec | exit | filter | format | getattr
| globals | hasattr | hash | help | hex | id | input
Expand Down Expand Up @@ -1364,10 +1364,10 @@ repository:
(?x)
\b(
__(?:
all | bases | builtins | class | code | debug | defaults | dict
| doc | file | func | kwdefaults | members
| metaclass | methods | module | mro | name
| qualname | self | signature | slots | subclasses
all | bases | builtins | class | class_getitem | code | debug
| defaults | dict | doc | file | func | kwdefaults | members
| metaclass | methods | module | mro | mro_entries | name
| qualname | post_init | self | signature | slots | subclasses
| version | weakref | wrapped | annotations | classcell
| spec | path | package | future | traceback
)__
Expand Down
36 changes: 36 additions & 0 deletions test/atom-spec/python-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,17 @@ describe("Grammar Tests", function() {
expect(tokens[1][3].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.end.python"]);
});

it("test/builtins/builtins7.py",
function() {
tokens = grammar.tokenizeLines("breakpoint()")
expect(tokens[0][0].value).toBe("breakpoint");
expect(tokens[0][0].scopes).toEqual(["source.python","meta.function-call.python","support.function.builtin.python"]);
expect(tokens[0][1].value).toBe("(");
expect(tokens[0][1].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.begin.python"]);
expect(tokens[0][2].value).toBe(")");
expect(tokens[0][2].scopes).toEqual(["source.python","meta.function-call.python","punctuation.definition.arguments.end.python"]);
});

it("test/calls/call1.py",
function() {
tokens = grammar.tokenizeLines("some_call(A, b, c[1], *args, FOO=lambda:{'q': 42}, **kwargs)")
Expand Down Expand Up @@ -6177,6 +6188,31 @@ describe("Grammar Tests", function() {
expect(tokens[1][0].scopes).toEqual(["source.python"]);
});

it("test/expressions/special2.py",
function() {
tokens = grammar.tokenizeLines("__post_init__\ndef __class_getitem__(): pass\n__mro_entries__")
expect(tokens[0][0].value).toBe("__post_init__");
expect(tokens[0][0].scopes).toEqual(["source.python","support.variable.magic.python"]);
expect(tokens[1][0].value).toBe("def");
expect(tokens[1][0].scopes).toEqual(["source.python","meta.function.python","storage.type.function.python"]);
expect(tokens[1][1].value).toBe(" ");
expect(tokens[1][1].scopes).toEqual(["source.python","meta.function.python"]);
expect(tokens[1][2].value).toBe("__class_getitem__");
expect(tokens[1][2].scopes).toEqual(["source.python","meta.function.python","support.variable.magic.python"]);
expect(tokens[1][3].value).toBe("(");
expect(tokens[1][3].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.definition.parameters.begin.python"]);
expect(tokens[1][4].value).toBe(")");
expect(tokens[1][4].scopes).toEqual(["source.python","meta.function.python","meta.function.parameters.python","punctuation.definition.parameters.end.python"]);
expect(tokens[1][5].value).toBe(":");
expect(tokens[1][5].scopes).toEqual(["source.python","meta.function.python","punctuation.section.function.begin.python"]);
expect(tokens[1][6].value).toBe(" ");
expect(tokens[1][6].scopes).toEqual(["source.python"]);
expect(tokens[1][7].value).toBe("pass");
expect(tokens[1][7].scopes).toEqual(["source.python","keyword.control.flow.python"]);
expect(tokens[2][0].value).toBe("__mro_entries__");
expect(tokens[2][0].scopes).toEqual(["source.python","support.variable.magic.python"]);
});

it("test/fstrings/comment1.py",
function() {
tokens = grammar.tokenizeLines("f'prefix{10 # comment, making the string technically illegal\ndef foo(): pass")
Expand Down
8 changes: 8 additions & 0 deletions test/builtins/builtins7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
breakpoint()




breakpoint : meta.function-call.python, source.python, support.function.builtin.python
( : meta.function-call.python, punctuation.definition.arguments.begin.python, source.python
) : meta.function-call.python, punctuation.definition.arguments.end.python, source.python
16 changes: 16 additions & 0 deletions test/expressions/special2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__post_init__
def __class_getitem__(): pass
__mro_entries__



__post_init__ : source.python, support.variable.magic.python
def : meta.function.python, source.python, storage.type.function.python
: meta.function.python, source.python
__class_getitem__ : meta.function.python, source.python, support.variable.magic.python
( : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.begin.python, source.python
) : meta.function.parameters.python, meta.function.python, punctuation.definition.parameters.end.python, source.python
: : meta.function.python, punctuation.section.function.begin.python, source.python
: source.python
pass : keyword.control.flow.python, source.python
__mro_entries__ : source.python, support.variable.magic.python

0 comments on commit 9540297

Please sign in to comment.