Skip to content

Commit

Permalink
Recognize '&&' and '||' as illegal operators
Browse files Browse the repository at this point in the history
  • Loading branch information
1st1 committed Oct 24, 2015
1 parent 9f7e839 commit 1ba703f
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 21 deletions.
14 changes: 9 additions & 5 deletions grammars/MagicPython.cson
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ repository:
{
include: "#lambda"
}
{
include: "#illegal-operator"
}
{
include: "#operator"
}
Expand Down Expand Up @@ -332,9 +335,6 @@ repository:
{
include: "#special-names"
}
{
include: "#illegal-operator"
}
{
include: "#illegal-names"
}
Expand Down Expand Up @@ -1677,11 +1677,15 @@ repository:
"illegal-operator":
patterns: [
{
name: "invalid.illegal.character.python"
name: "invalid.illegal.operator.python"
match: "&&|\\|\\|"
}
{
name: "invalid.illegal.operator.python"
match: "[?$]"
}
{
name: "invalid.illegal.character.python"
name: "invalid.illegal.operator.python"
comment: "We don't want `!` to flash when we're typing `!=`"
match: "!\\b"
}
Expand Down
8 changes: 5 additions & 3 deletions grammars/MagicPython.syntax.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ repository:
- include: '#regexp'
- include: '#string'
- include: '#lambda'
- include: '#illegal-operator'
- include: '#operator'
- include: '#curly-braces'
- include: '#item-access'
Expand All @@ -247,7 +248,6 @@ repository:
- include: '#magic-variable-names'
- include: '#member-access'
- include: '#special-names'
- include: '#illegal-operator'
- include: '#illegal-names'
- include: '#special-variables'
- include: '#ellipsis'
Expand Down Expand Up @@ -1149,9 +1149,11 @@ repository:

illegal-operator:
patterns:
- name: invalid.illegal.character.python
- name: invalid.illegal.operator.python
match: '&&|\|\|'
- name: invalid.illegal.operator.python
match: '[?$]'
- name: invalid.illegal.character.python
- name: invalid.illegal.operator.python
comment: We don't want `!` to flash when we're typing `!=`
match: '!\b'

Expand Down
18 changes: 12 additions & 6 deletions grammars/MagicPython.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@
<key>include</key>
<string>#lambda</string>
</dict>
<dict>
<key>include</key>
<string>#illegal-operator</string>
</dict>
<dict>
<key>include</key>
<string>#operator</string>
Expand Down Expand Up @@ -508,10 +512,6 @@
<key>include</key>
<string>#special-names</string>
</dict>
<dict>
<key>include</key>
<string>#illegal-operator</string>
</dict>
<dict>
<key>include</key>
<string>#illegal-names</string>
Expand Down Expand Up @@ -2640,13 +2640,19 @@ indirectly through syntactic constructs
<array>
<dict>
<key>name</key>
<string>invalid.illegal.character.python</string>
<string>invalid.illegal.operator.python</string>
<key>match</key>
<string>&amp;&amp;|\|\|</string>
</dict>
<dict>
<key>name</key>
<string>invalid.illegal.operator.python</string>
<key>match</key>
<string>[?$]</string>
</dict>
<dict>
<key>name</key>
<string>invalid.illegal.character.python</string>
<string>invalid.illegal.operator.python</string>
<key>comment</key>
<string>We don&apos;t want `!` to flash when we&apos;re typing `!=`</string>
<key>match</key>
Expand Down
2 changes: 1 addition & 1 deletion misc/scopes
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ entity.other.inherited-class.python
invalid.deprecated.backtick.python
invalid.deprecated.prefix.python
invalid.illegal.annotation.python
invalid.illegal.character.python
invalid.illegal.dec.python
invalid.illegal.decorator.python
invalid.illegal.line.continuation.python
invalid.illegal.name.python
invalid.illegal.newline.python
invalid.illegal.operator.python
invalid.illegal.prefix.python
keyword.codetag.notation.python
keyword.control.flow.python
Expand Down
10 changes: 5 additions & 5 deletions test/illegals/illegal1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def : meta.function.python, source.python, storage.type.function.pytho
: : meta.function.python, punctuation.section.function.begin.python, source.python
: source.python
pass : keyword.control.flow.python, source.python
$ : invalid.illegal.character.python, source.python
? : invalid.illegal.character.python, source.python
$ : invalid.illegal.operator.python, source.python
? : invalid.illegal.operator.python, source.python
a : source.python
= : keyword.operator.assignment.python, source.python
$ : invalid.illegal.character.python, source.python
$ : invalid.illegal.operator.python, source.python
( : punctuation.parenthesis.begin.python, source.python
' : punctuation.definition.string.begin.python, source.python, string.quoted.single.python
.class : source.python, string.quoted.single.python
Expand All @@ -40,8 +40,8 @@ def : meta.function.python, source.python, storage.type.function.pytho
b : source.python
= : keyword.operator.assignment.python, source.python
: source.python
! : invalid.illegal.character.python, source.python
! : invalid.illegal.operator.python, source.python
some_ruby : source.python
? : invalid.illegal.character.python, source.python
? : invalid.illegal.operator.python, source.python
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python
hey ;) : comment.line.number-sign.python, source.python
19 changes: 19 additions & 0 deletions test/illegals/illegal2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
a&&b||c
a &&= a
b ||= c



a : source.python
&& : invalid.illegal.operator.python, source.python
b : source.python
|| : invalid.illegal.operator.python, source.python
c : source.python
a : source.python
&& : invalid.illegal.operator.python, source.python
= : keyword.operator.assignment.python, source.python
a : source.python
b : source.python
|| : invalid.illegal.operator.python, source.python
= : keyword.operator.assignment.python, source.python
c : source.python
2 changes: 1 addition & 1 deletion test/regexp/python2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
: invalid.illegal.newline.python, source.python, string.regexp.quoted.single.python
: source.python
( : punctuation.parenthesis.begin.python, source.python
? : invalid.illegal.character.python, source.python
? : invalid.illegal.operator.python, source.python
x : source.python
) : punctuation.parenthesis.end.python, source.python
foo : source.python
Expand Down

0 comments on commit 1ba703f

Please sign in to comment.