Skip to content

Commit 1ba703f

Browse files
committed
Recognize '&&' and '||' as illegal operators
1 parent 9f7e839 commit 1ba703f

File tree

7 files changed

+52
-21
lines changed

7 files changed

+52
-21
lines changed

grammars/MagicPython.cson

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ repository:
290290
{
291291
include: "#lambda"
292292
}
293+
{
294+
include: "#illegal-operator"
295+
}
293296
{
294297
include: "#operator"
295298
}
@@ -332,9 +335,6 @@ repository:
332335
{
333336
include: "#special-names"
334337
}
335-
{
336-
include: "#illegal-operator"
337-
}
338338
{
339339
include: "#illegal-names"
340340
}
@@ -1677,11 +1677,15 @@ repository:
16771677
"illegal-operator":
16781678
patterns: [
16791679
{
1680-
name: "invalid.illegal.character.python"
1680+
name: "invalid.illegal.operator.python"
1681+
match: "&&|\\|\\|"
1682+
}
1683+
{
1684+
name: "invalid.illegal.operator.python"
16811685
match: "[?$]"
16821686
}
16831687
{
1684-
name: "invalid.illegal.character.python"
1688+
name: "invalid.illegal.operator.python"
16851689
comment: "We don't want `!` to flash when we're typing `!=`"
16861690
match: "!\\b"
16871691
}

grammars/MagicPython.syntax.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ repository:
233233
- include: '#regexp'
234234
- include: '#string'
235235
- include: '#lambda'
236+
- include: '#illegal-operator'
236237
- include: '#operator'
237238
- include: '#curly-braces'
238239
- include: '#item-access'
@@ -247,7 +248,6 @@ repository:
247248
- include: '#magic-variable-names'
248249
- include: '#member-access'
249250
- include: '#special-names'
250-
- include: '#illegal-operator'
251251
- include: '#illegal-names'
252252
- include: '#special-variables'
253253
- include: '#ellipsis'
@@ -1149,9 +1149,11 @@ repository:
11491149

11501150
illegal-operator:
11511151
patterns:
1152-
- name: invalid.illegal.character.python
1152+
- name: invalid.illegal.operator.python
1153+
match: '&&|\|\|'
1154+
- name: invalid.illegal.operator.python
11531155
match: '[?$]'
1154-
- name: invalid.illegal.character.python
1156+
- name: invalid.illegal.operator.python
11551157
comment: We don't want `!` to flash when we're typing `!=`
11561158
match: '!\b'
11571159

grammars/MagicPython.tmLanguage

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@
452452
<key>include</key>
453453
<string>#lambda</string>
454454
</dict>
455+
<dict>
456+
<key>include</key>
457+
<string>#illegal-operator</string>
458+
</dict>
455459
<dict>
456460
<key>include</key>
457461
<string>#operator</string>
@@ -508,10 +512,6 @@
508512
<key>include</key>
509513
<string>#special-names</string>
510514
</dict>
511-
<dict>
512-
<key>include</key>
513-
<string>#illegal-operator</string>
514-
</dict>
515515
<dict>
516516
<key>include</key>
517517
<string>#illegal-names</string>
@@ -2640,13 +2640,19 @@ indirectly through syntactic constructs
26402640
<array>
26412641
<dict>
26422642
<key>name</key>
2643-
<string>invalid.illegal.character.python</string>
2643+
<string>invalid.illegal.operator.python</string>
2644+
<key>match</key>
2645+
<string>&amp;&amp;|\|\|</string>
2646+
</dict>
2647+
<dict>
2648+
<key>name</key>
2649+
<string>invalid.illegal.operator.python</string>
26442650
<key>match</key>
26452651
<string>[?$]</string>
26462652
</dict>
26472653
<dict>
26482654
<key>name</key>
2649-
<string>invalid.illegal.character.python</string>
2655+
<string>invalid.illegal.operator.python</string>
26502656
<key>comment</key>
26512657
<string>We don&apos;t want `!` to flash when we&apos;re typing `!=`</string>
26522658
<key>match</key>

misc/scopes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ entity.other.inherited-class.python
3030
invalid.deprecated.backtick.python
3131
invalid.deprecated.prefix.python
3232
invalid.illegal.annotation.python
33-
invalid.illegal.character.python
3433
invalid.illegal.dec.python
3534
invalid.illegal.decorator.python
3635
invalid.illegal.line.continuation.python
3736
invalid.illegal.name.python
3837
invalid.illegal.newline.python
38+
invalid.illegal.operator.python
3939
invalid.illegal.prefix.python
4040
keyword.codetag.notation.python
4141
keyword.control.flow.python

test/illegals/illegal1.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ def : meta.function.python, source.python, storage.type.function.pytho
1818
: : meta.function.python, punctuation.section.function.begin.python, source.python
1919
: source.python
2020
pass : keyword.control.flow.python, source.python
21-
$ : invalid.illegal.character.python, source.python
22-
? : invalid.illegal.character.python, source.python
21+
$ : invalid.illegal.operator.python, source.python
22+
? : invalid.illegal.operator.python, source.python
2323
a : source.python
2424
= : keyword.operator.assignment.python, source.python
25-
$ : invalid.illegal.character.python, source.python
25+
$ : invalid.illegal.operator.python, source.python
2626
( : punctuation.parenthesis.begin.python, source.python
2727
' : punctuation.definition.string.begin.python, source.python, string.quoted.single.python
2828
.class : source.python, string.quoted.single.python
@@ -40,8 +40,8 @@ def : meta.function.python, source.python, storage.type.function.pytho
4040
b : source.python
4141
= : keyword.operator.assignment.python, source.python
4242
: source.python
43-
! : invalid.illegal.character.python, source.python
43+
! : invalid.illegal.operator.python, source.python
4444
some_ruby : source.python
45-
? : invalid.illegal.character.python, source.python
45+
? : invalid.illegal.operator.python, source.python
4646
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
4747
hey ;) : comment.line.number-sign.python, source.python

test/illegals/illegal2.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
a&&b||c
2+
a &&= a
3+
b ||= c
4+
5+
6+
7+
a : source.python
8+
&& : invalid.illegal.operator.python, source.python
9+
b : source.python
10+
|| : invalid.illegal.operator.python, source.python
11+
c : source.python
12+
a : source.python
13+
&& : invalid.illegal.operator.python, source.python
14+
= : keyword.operator.assignment.python, source.python
15+
a : source.python
16+
b : source.python
17+
|| : invalid.illegal.operator.python, source.python
18+
= : keyword.operator.assignment.python, source.python
19+
c : source.python

test/regexp/python2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
: invalid.illegal.newline.python, source.python, string.regexp.quoted.single.python
1414
: source.python
1515
( : punctuation.parenthesis.begin.python, source.python
16-
? : invalid.illegal.character.python, source.python
16+
? : invalid.illegal.operator.python, source.python
1717
x : source.python
1818
) : punctuation.parenthesis.end.python, source.python
1919
foo : source.python

0 commit comments

Comments
 (0)