Visitar URL original
Fix for loop highlighting #211 by nullie · Pull Request #212 · MagicStack/MagicPython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Look for boundary instead of space
  • Loading branch information
nullie committed May 18, 2020
commit 1e7980e70b34d063709e0635ebdde3287a31bc51
4 changes: 2 additions & 2 deletions grammars/MagicPython.cson
Original file line number Diff line number Diff line change
Expand Up @@ -1330,11 +1330,11 @@ repository:
correctly identify the "in" as a control flow keyword.

'''
begin: "for(?=\\s)"
begin: "\\bfor\\b"
beginCaptures:
"0":
name: "keyword.control.flow.python"
end: "in(?=\\s)"
end: "\\bin\\b"
endCaptures:
"0":
name: "keyword.control.flow.python"
Expand Down
4 changes: 2 additions & 2 deletions grammars/MagicPython.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -2061,7 +2061,7 @@ E.g. "arr[idx](args)"
correctly identify the "in" as a control flow keyword.
</string>
<key>begin</key>
<string>for(?=\s)</string>
<string>\bfor\b</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
Expand All @@ -2071,7 +2071,7 @@ correctly identify the "in" as a control flow keyword.
</dict>
</dict>
<key>end</key>
<string>in(?=\s)</string>
<string>\bin\b</string>
<key>endCaptures</key>
<dict>
<key>0</key>
Expand Down
4 changes: 2 additions & 2 deletions grammars/src/MagicPython.syntax.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1046,10 +1046,10 @@ repository:
comment: |
Match "for ... in" construct used in generators and for loops to
correctly identify the "in" as a control flow keyword.
begin: for(?=\s)
begin: \bfor\b
beginCaptures:
'0': {name: keyword.control.flow.python}
end: in(?=\s)
end: \bin\b
endCaptures:
'0': {name: keyword.control.flow.python}
patterns:
Expand Down
69 changes: 69 additions & 0 deletions test/atom-spec/python-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12269,6 +12269,75 @@ describe("Grammar Tests", function() {
expect(tokens[2][1].scopes).toEqual(["source.python","keyword.control.flow.python"]);
});

it("test/statements/for3.py",
function() {
tokens = grammar.tokenizeLines("for(a, b), c, invariable in[2 in q, 2 in w]:\n pass")
expect(tokens[0][0].value).toBe("for");
expect(tokens[0][0].scopes).toEqual(["source.python","keyword.control.flow.python"]);
expect(tokens[0][1].value).toBe("(");
expect(tokens[0][1].scopes).toEqual(["source.python","punctuation.parenthesis.begin.python"]);
expect(tokens[0][2].value).toBe("a");
expect(tokens[0][2].scopes).toEqual(["source.python"]);
expect(tokens[0][3].value).toBe(",");
expect(tokens[0][3].scopes).toEqual(["source.python","punctuation.separator.element.python"]);
expect(tokens[0][4].value).toBe(" ");
expect(tokens[0][4].scopes).toEqual(["source.python"]);
expect(tokens[0][5].value).toBe("b");
expect(tokens[0][5].scopes).toEqual(["source.python"]);
expect(tokens[0][6].value).toBe(")");
expect(tokens[0][6].scopes).toEqual(["source.python","punctuation.parenthesis.end.python"]);
expect(tokens[0][7].value).toBe(",");
expect(tokens[0][7].scopes).toEqual(["source.python","punctuation.separator.element.python"]);
expect(tokens[0][8].value).toBe(" ");
expect(tokens[0][8].scopes).toEqual(["source.python"]);
expect(tokens[0][9].value).toBe("c");
expect(tokens[0][9].scopes).toEqual(["source.python"]);
expect(tokens[0][10].value).toBe(",");
expect(tokens[0][10].scopes).toEqual(["source.python","punctuation.separator.element.python"]);
expect(tokens[0][11].value).toBe(" ");
expect(tokens[0][11].scopes).toEqual(["source.python"]);
expect(tokens[0][12].value).toBe("invariable");
expect(tokens[0][12].scopes).toEqual(["source.python"]);
expect(tokens[0][13].value).toBe(" ");
expect(tokens[0][13].scopes).toEqual(["source.python"]);
expect(tokens[0][14].value).toBe("in");
expect(tokens[0][14].scopes).toEqual(["source.python","keyword.control.flow.python"]);
expect(tokens[0][15].value).toBe("[");
expect(tokens[0][15].scopes).toEqual(["source.python","punctuation.definition.list.begin.python"]);
expect(tokens[0][16].value).toBe("2");
expect(tokens[0][16].scopes).toEqual(["source.python","constant.numeric.dec.python"]);
expect(tokens[0][17].value).toBe(" ");
expect(tokens[0][17].scopes).toEqual(["source.python"]);
expect(tokens[0][18].value).toBe("in");
expect(tokens[0][18].scopes).toEqual(["source.python","keyword.operator.logical.python"]);
expect(tokens[0][19].value).toBe(" ");
expect(tokens[0][19].scopes).toEqual(["source.python"]);
expect(tokens[0][20].value).toBe("q");
expect(tokens[0][20].scopes).toEqual(["source.python"]);
expect(tokens[0][21].value).toBe(",");
expect(tokens[0][21].scopes).toEqual(["source.python","punctuation.separator.element.python"]);
expect(tokens[0][22].value).toBe(" ");
expect(tokens[0][22].scopes).toEqual(["source.python"]);
expect(tokens[0][23].value).toBe("2");
expect(tokens[0][23].scopes).toEqual(["source.python","constant.numeric.dec.python"]);
expect(tokens[0][24].value).toBe(" ");
expect(tokens[0][24].scopes).toEqual(["source.python"]);
expect(tokens[0][25].value).toBe("in");
expect(tokens[0][25].scopes).toEqual(["source.python","keyword.operator.logical.python"]);
expect(tokens[0][26].value).toBe(" ");
expect(tokens[0][26].scopes).toEqual(["source.python"]);
expect(tokens[0][27].value).toBe("w");
expect(tokens[0][27].scopes).toEqual(["source.python"]);
expect(tokens[0][28].value).toBe("]");
expect(tokens[0][28].scopes).toEqual(["source.python","punctuation.definition.list.end.python"]);
expect(tokens[0][29].value).toBe(":");
expect(tokens[0][29].scopes).toEqual(["source.python","punctuation.separator.colon.python"]);
expect(tokens[1][0].value).toBe(" ");
expect(tokens[1][0].scopes).toEqual(["source.python"]);
expect(tokens[1][1].value).toBe("pass");
expect(tokens[1][1].scopes).toEqual(["source.python","keyword.control.flow.python"]);
});

it("test/statements/from1.py",
function() {
tokens = grammar.tokenizeLines("from ... import foo as bar\nraise Exception('done') from exc\nyield from foo")
Expand Down
38 changes: 38 additions & 0 deletions test/statements/for3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
for(a, b), c, invariable in[2 in q, 2 in w]:
pass




for : keyword.control.flow.python, source.python
( : punctuation.parenthesis.begin.python, source.python
a : source.python
, : punctuation.separator.element.python, source.python
: source.python
b : source.python
) : punctuation.parenthesis.end.python, source.python
, : punctuation.separator.element.python, source.python
: source.python
c : source.python
, : punctuation.separator.element.python, source.python
: source.python
invariable : source.python
: source.python
in : keyword.control.flow.python, source.python
[ : punctuation.definition.list.begin.python, source.python
2 : constant.numeric.dec.python, source.python
: source.python
in : keyword.operator.logical.python, source.python
: source.python
q : source.python
, : punctuation.separator.element.python, source.python
: source.python
2 : constant.numeric.dec.python, source.python
: source.python
in : keyword.operator.logical.python, source.python
: source.python
w : source.python
] : punctuation.definition.list.end.python, source.python
: : punctuation.separator.colon.python, source.python
: source.python
pass : keyword.control.flow.python, source.python