Skip to content

Commit 2dbc8f3

Browse files
committed
Make ! and ? illegal operators; highlight backticks in lambda context
1 parent 0d99e7a commit 2dbc8f3

File tree

5 files changed

+102
-50
lines changed

5 files changed

+102
-50
lines changed

MagicPython.YAML-tmLanguage

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ repository:
5454
name: meta.expression.python
5555
comment: All valid Python expressions
5656
patterns:
57-
- include: '#error'
57+
- include: '#backticks'
58+
- include: '#illegal-anno'
5859
- include: '#comments'
5960
- include: '#literal'
6061
- include: '#string'
@@ -73,6 +74,7 @@ repository:
7374
- include: '#magic-variable-names'
7475
- include: '#member-access'
7576
- include: '#special-names'
77+
- include: '#invalid-chars'
7678

7779
special-names:
7880
name: constant.other.caps.python
@@ -144,7 +146,7 @@ repository:
144146
| != | == | >= | <= | << | >> | @=
145147
| && | \|\| | \*\* | //
146148
| > | < | \+ | - | \* | % | \| | & | \^
147-
| ~ | \? | ! | / | @
149+
| ~ | / | @
148150
149151
literal:
150152
patterns:
@@ -566,9 +568,11 @@ repository:
566568
'2': {name: punctuation.separator.parameters.python}
567569

568570
- include: '#comments'
569-
- include: '#error'
571+
- include: '#backticks'
572+
- include: '#illegal-anno'
570573
- include: '#lambda-parameter-with-default'
571574
- include: '#line-continuation'
575+
- include: '#invalid-chars'
572576

573577
lambda-incomplete:
574578
name: storage.type.function.lambda.python
@@ -949,15 +953,22 @@ repository:
949953
- include: '#illegal-names'
950954
- include: '#special-names'
951955

952-
error:
956+
backticks:
957+
name: invalid.deprecated.backtick.python
958+
begin: \`
959+
end: (?:\`|(?<!\\)(\n))
960+
patterns:
961+
- include: '#expression'
962+
963+
invalid-chars:
953964
patterns:
954965
- name: invalid.illegal.character.python
955966
match: '[?$]'
956-
- name: invalid.illegal.annotation.python
957-
match: '->'
958-
- name: invalid.deprecated.backtick.python
959-
begin: \`
960-
end: (?:\`|(?<!\\)(\n))
961-
patterns:
962-
- include: '#expression'
967+
- name: invalid.illegal.character.python
968+
comment: We don't want `!` to flash when we're typing `!=`
969+
match: '!\b'
970+
971+
illegal-anno:
972+
name: invalid.illegal.annotation.python
973+
match: '->'
963974
...

MagicPython.tmLanguage

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@
9292
</dict>
9393
</array>
9494
</dict>
95+
<key>backticks</key>
96+
<dict>
97+
<key>begin</key>
98+
<string>\`</string>
99+
<key>end</key>
100+
<string>(?:\`|(?&lt;!\\)(\n))</string>
101+
<key>name</key>
102+
<string>invalid.deprecated.backtick.python</string>
103+
<key>patterns</key>
104+
<array>
105+
<dict>
106+
<key>include</key>
107+
<string>#expression</string>
108+
</dict>
109+
</array>
110+
</dict>
95111
<key>builtin-callables</key>
96112
<dict>
97113
<key>patterns</key>
@@ -546,39 +562,6 @@
546562
</dict>
547563
</array>
548564
</dict>
549-
<key>error</key>
550-
<dict>
551-
<key>patterns</key>
552-
<array>
553-
<dict>
554-
<key>match</key>
555-
<string>[?$]</string>
556-
<key>name</key>
557-
<string>invalid.illegal.character.python</string>
558-
</dict>
559-
<dict>
560-
<key>match</key>
561-
<string>-&gt;</string>
562-
<key>name</key>
563-
<string>invalid.illegal.annotation.python</string>
564-
</dict>
565-
<dict>
566-
<key>begin</key>
567-
<string>\`</string>
568-
<key>end</key>
569-
<string>(?:\`|(?&lt;!\\)(\n))</string>
570-
<key>name</key>
571-
<string>invalid.deprecated.backtick.python</string>
572-
<key>patterns</key>
573-
<array>
574-
<dict>
575-
<key>include</key>
576-
<string>#expression</string>
577-
</dict>
578-
</array>
579-
</dict>
580-
</array>
581-
</dict>
582565
<key>escape-sequence</key>
583566
<dict>
584567
<key>match</key>
@@ -624,7 +607,11 @@
624607
<array>
625608
<dict>
626609
<key>include</key>
627-
<string>#error</string>
610+
<string>#backticks</string>
611+
</dict>
612+
<dict>
613+
<key>include</key>
614+
<string>#illegal-anno</string>
628615
</dict>
629616
<dict>
630617
<key>include</key>
@@ -698,6 +685,10 @@
698685
<key>include</key>
699686
<string>#special-names</string>
700687
</dict>
688+
<dict>
689+
<key>include</key>
690+
<string>#invalid-chars</string>
691+
</dict>
701692
</array>
702693
</dict>
703694
<key>function-arguments</key>
@@ -878,6 +869,13 @@
878869
</dict>
879870
</array>
880871
</dict>
872+
<key>illegal-anno</key>
873+
<dict>
874+
<key>match</key>
875+
<string>-&gt;</string>
876+
<key>name</key>
877+
<string>invalid.illegal.annotation.python</string>
878+
</dict>
881879
<key>illegal-names</key>
882880
<dict>
883881
<key>match</key>
@@ -921,6 +919,26 @@
921919
</dict>
922920
</array>
923921
</dict>
922+
<key>invalid-chars</key>
923+
<dict>
924+
<key>patterns</key>
925+
<array>
926+
<dict>
927+
<key>match</key>
928+
<string>[?$]</string>
929+
<key>name</key>
930+
<string>invalid.illegal.character.python</string>
931+
</dict>
932+
<dict>
933+
<key>comment</key>
934+
<string>this rule exists to highlight errors</string>
935+
<key>match</key>
936+
<string>!\b</string>
937+
<key>name</key>
938+
<string>invalid.illegal.character.python</string>
939+
</dict>
940+
</array>
941+
</dict>
924942
<key>item-access</key>
925943
<dict>
926944
<key>patterns</key>
@@ -1054,7 +1072,11 @@
10541072
</dict>
10551073
<dict>
10561074
<key>include</key>
1057-
<string>#error</string>
1075+
<string>#backticks</string>
1076+
</dict>
1077+
<dict>
1078+
<key>include</key>
1079+
<string>#illegal-anno</string>
10581080
</dict>
10591081
<dict>
10601082
<key>include</key>
@@ -1064,6 +1086,10 @@
10641086
<key>include</key>
10651087
<string>#line-continuation</string>
10661088
</dict>
1089+
<dict>
1090+
<key>include</key>
1091+
<string>#invalid-chars</string>
1092+
</dict>
10671093
</array>
10681094
</dict>
10691095
</array>
@@ -1466,7 +1492,7 @@ indirectly through syntactic constructs
14661492
| != | == | &gt;= | &lt;= | &lt;&lt; | &gt;&gt; | @=
14671493
| &amp;&amp; | \|\| | \*\* | //
14681494
| &gt; | &lt; | \+ | - | \* | % | \| | &amp; | \^
1469-
| ~ | \? | ! | / | @
1495+
| ~ | / | @
14701496
</string>
14711497
<key>name</key>
14721498
<string>keyword.operator.python</string>

test/expressions/expr1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
!a + b @ c ^ d // e % f & e and not g or h
1+
~a + b @ c ^ d // e % f & e and not g or h
22

33

4-
! : keyword.operator.python, source.python
4+
~ : keyword.operator.python, source.python
55
a : source.python
66
+ : keyword.operator.python, source.python
77
b : source.python

test/illegals/backticks3.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
a = lambda `123`
2+
3+
4+
5+
a : source.python
6+
= : keyword.operator.assignment.python, source.python
7+
: source.python
8+
lambda : meta.lambda-function.python, source.python, storage.type.function.lambda.python
9+
: meta.function.lambda.parameters.python, meta.lambda-function.python, source.python
10+
` : invalid.deprecated.backtick.python, meta.function.lambda.parameters.python, meta.lambda-function.python, source.python
11+
123 : constant.numeric.dec.python, invalid.deprecated.backtick.python, meta.function.lambda.parameters.python, meta.lambda-function.python, source.python
12+
` : invalid.deprecated.backtick.python, meta.function.lambda.parameters.python, meta.lambda-function.python, source.python
13+
: meta.lambda-function.python, source.python

test/illegals/illegal1.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
->
22
def f(): pass
33
$
4+
?
45
a=$('.class').fuuuu(baz=1)
56
# we recover just fine
67
b = !some_ruby?
@@ -17,6 +18,7 @@ def : source.python, storage.type.function.python
1718
: : source.python
1819
pass : keyword.control.flow.python, source.python
1920
$ : invalid.illegal.character.python, source.python
21+
? : invalid.illegal.character.python, source.python
2022
a : source.python
2123
= : keyword.operator.assignment.python, source.python
2224
$ : invalid.illegal.character.python, source.python
@@ -37,7 +39,7 @@ def : source.python, storage.type.function.python
3739
b : source.python
3840
= : keyword.operator.assignment.python, source.python
3941
: source.python
40-
! : keyword.operator.python, source.python
42+
! : invalid.illegal.character.python, source.python
4143
some_ruby : source.python
4244
? : invalid.illegal.character.python, source.python
4345
# : comment.line.number-sign.python, punctuation.definition.comment.python, source.python

0 commit comments

Comments
 (0)