Skip to content

Commit 361a496

Browse files
authored
Clean-up the grammar so that MagicRegExp does not have missing rules. (#100)
Thanks to @stoivo for noticing this issue.
1 parent d39070f commit 361a496

8 files changed

+187
-88
lines changed

Diff for: grammars/MagicPython.cson

+23-23
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,6 @@ repository:
252252
captures:
253253
"1":
254254
name: "keyword.control.flow.python"
255-
codetags:
256-
match: "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)"
257-
captures:
258-
"1":
259-
name: "keyword.codetag.notation.python"
260255
"statement-keyword":
261256
patterns: [
262257
{
@@ -988,24 +983,6 @@ repository:
988983
include: "#fstring-formatting-singe-brace"
989984
}
990985
]
991-
"fstring-formatting-braces":
992-
patterns: [
993-
{
994-
comment: "empty braces are illegal"
995-
match: "({)(\\s*?)(})"
996-
captures:
997-
"1":
998-
name: "constant.character.format.placeholder.other.python"
999-
"2":
1000-
name: "invalid.illegal.brace.python"
1001-
"3":
1002-
name: "constant.character.format.placeholder.other.python"
1003-
}
1004-
{
1005-
name: "constant.character.escape.python"
1006-
match: "({{|}})"
1007-
}
1008-
]
1009986
"fstring-formatting-singe-brace":
1010987
name: "invalid.illegal.brace.python"
1011988
match: "(}(?!}))"
@@ -1931,6 +1908,24 @@ repository:
19311908
include: "#regexp-base-common"
19321909
}
19331910
]
1911+
"fstring-formatting-braces":
1912+
patterns: [
1913+
{
1914+
comment: "empty braces are illegal"
1915+
match: "({)(\\s*?)(})"
1916+
captures:
1917+
"1":
1918+
name: "constant.character.format.placeholder.other.python"
1919+
"2":
1920+
name: "invalid.illegal.brace.python"
1921+
"3":
1922+
name: "constant.character.format.placeholder.other.python"
1923+
}
1924+
{
1925+
name: "constant.character.escape.python"
1926+
match: "({{|}})"
1927+
}
1928+
]
19341929
"regexp-base-common":
19351930
patterns: [
19361931
{
@@ -2066,6 +2061,11 @@ repository:
20662061
include: "#regexp-escape-catchall"
20672062
}
20682063
]
2064+
codetags:
2065+
match: "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)"
2066+
captures:
2067+
"1":
2068+
name: "keyword.codetag.notation.python"
20692069
"comments-base":
20702070
name: "comment.line.number-sign.python"
20712071
begin: "(\\#)"

Diff for: grammars/MagicPython.tmLanguage

+49-49
Original file line numberDiff line numberDiff line change
@@ -404,19 +404,6 @@
404404
</dict>
405405
</dict>
406406
</dict>
407-
<key>codetags</key>
408-
<dict>
409-
<key>match</key>
410-
<string>(?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b)</string>
411-
<key>captures</key>
412-
<dict>
413-
<key>1</key>
414-
<dict>
415-
<key>name</key>
416-
<string>keyword.codetag.notation.python</string>
417-
</dict>
418-
</dict>
419-
</dict>
420407
<key>statement-keyword</key>
421408
<dict>
422409
<key>patterns</key>
@@ -1509,42 +1496,6 @@
15091496
</dict>
15101497
</array>
15111498
</dict>
1512-
<key>fstring-formatting-braces</key>
1513-
<dict>
1514-
<key>patterns</key>
1515-
<array>
1516-
<dict>
1517-
<key>comment</key>
1518-
<string>empty braces are illegal</string>
1519-
<key>match</key>
1520-
<string>({)(\s*?)(})</string>
1521-
<key>captures</key>
1522-
<dict>
1523-
<key>1</key>
1524-
<dict>
1525-
<key>name</key>
1526-
<string>constant.character.format.placeholder.other.python</string>
1527-
</dict>
1528-
<key>2</key>
1529-
<dict>
1530-
<key>name</key>
1531-
<string>invalid.illegal.brace.python</string>
1532-
</dict>
1533-
<key>3</key>
1534-
<dict>
1535-
<key>name</key>
1536-
<string>constant.character.format.placeholder.other.python</string>
1537-
</dict>
1538-
</dict>
1539-
</dict>
1540-
<dict>
1541-
<key>name</key>
1542-
<string>constant.character.escape.python</string>
1543-
<key>match</key>
1544-
<string>({{|}})</string>
1545-
</dict>
1546-
</array>
1547-
</dict>
15481499
<key>fstring-formatting-singe-brace</key>
15491500
<dict>
15501501
<key>name</key>
@@ -2978,6 +2929,42 @@ indirectly through syntactic constructs
29782929
</dict>
29792930
</array>
29802931
</dict>
2932+
<key>fstring-formatting-braces</key>
2933+
<dict>
2934+
<key>patterns</key>
2935+
<array>
2936+
<dict>
2937+
<key>comment</key>
2938+
<string>empty braces are illegal</string>
2939+
<key>match</key>
2940+
<string>({)(\s*?)(})</string>
2941+
<key>captures</key>
2942+
<dict>
2943+
<key>1</key>
2944+
<dict>
2945+
<key>name</key>
2946+
<string>constant.character.format.placeholder.other.python</string>
2947+
</dict>
2948+
<key>2</key>
2949+
<dict>
2950+
<key>name</key>
2951+
<string>invalid.illegal.brace.python</string>
2952+
</dict>
2953+
<key>3</key>
2954+
<dict>
2955+
<key>name</key>
2956+
<string>constant.character.format.placeholder.other.python</string>
2957+
</dict>
2958+
</dict>
2959+
</dict>
2960+
<dict>
2961+
<key>name</key>
2962+
<string>constant.character.escape.python</string>
2963+
<key>match</key>
2964+
<string>({{|}})</string>
2965+
</dict>
2966+
</array>
2967+
</dict>
29812968
<key>regexp-base-common</key>
29822969
<dict>
29832970
<key>patterns</key>
@@ -3188,6 +3175,19 @@ indirectly through syntactic constructs
31883175
</dict>
31893176
</array>
31903177
</dict>
3178+
<key>codetags</key>
3179+
<dict>
3180+
<key>match</key>
3181+
<string>(?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b)</string>
3182+
<key>captures</key>
3183+
<dict>
3184+
<key>1</key>
3185+
<dict>
3186+
<key>name</key>
3187+
<string>keyword.codetag.notation.python</string>
3188+
</dict>
3189+
</dict>
3190+
</dict>
31913191
<key>comments-base</key>
31923192
<dict>
31933193
<key>name</key>

Diff for: grammars/MagicRegExp.cson

+23
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ repository:
3535
include: "#regexp-base-common"
3636
}
3737
]
38+
"fstring-formatting-braces":
39+
patterns: [
40+
{
41+
comment: "empty braces are illegal"
42+
match: "({)(\\s*?)(})"
43+
captures:
44+
"1":
45+
name: "constant.character.format.placeholder.other.python"
46+
"2":
47+
name: "invalid.illegal.brace.python"
48+
"3":
49+
name: "constant.character.format.placeholder.other.python"
50+
}
51+
{
52+
name: "constant.character.escape.python"
53+
match: "({{|}})"
54+
}
55+
]
3856
"regexp-base-common":
3957
patterns: [
4058
{
@@ -170,6 +188,11 @@ repository:
170188
include: "#regexp-escape-catchall"
171189
}
172190
]
191+
codetags:
192+
match: "(?:\\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\\b)"
193+
captures:
194+
"1":
195+
name: "keyword.codetag.notation.python"
173196
"regexp-expression":
174197
patterns: [
175198
{

Diff for: grammars/MagicRegExp.tmLanguage

+49
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,42 @@
5858
</dict>
5959
</array>
6060
</dict>
61+
<key>fstring-formatting-braces</key>
62+
<dict>
63+
<key>patterns</key>
64+
<array>
65+
<dict>
66+
<key>comment</key>
67+
<string>empty braces are illegal</string>
68+
<key>match</key>
69+
<string>({)(\s*?)(})</string>
70+
<key>captures</key>
71+
<dict>
72+
<key>1</key>
73+
<dict>
74+
<key>name</key>
75+
<string>constant.character.format.placeholder.other.python</string>
76+
</dict>
77+
<key>2</key>
78+
<dict>
79+
<key>name</key>
80+
<string>invalid.illegal.brace.python</string>
81+
</dict>
82+
<key>3</key>
83+
<dict>
84+
<key>name</key>
85+
<string>constant.character.format.placeholder.other.python</string>
86+
</dict>
87+
</dict>
88+
</dict>
89+
<dict>
90+
<key>name</key>
91+
<string>constant.character.escape.python</string>
92+
<key>match</key>
93+
<string>({{|}})</string>
94+
</dict>
95+
</array>
96+
</dict>
6197
<key>regexp-base-common</key>
6298
<dict>
6399
<key>patterns</key>
@@ -268,6 +304,19 @@
268304
</dict>
269305
</array>
270306
</dict>
307+
<key>codetags</key>
308+
<dict>
309+
<key>match</key>
310+
<string>(?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b)</string>
311+
<key>captures</key>
312+
<dict>
313+
<key>1</key>
314+
<dict>
315+
<key>name</key>
316+
<string>keyword.codetag.notation.python</string>
317+
</dict>
318+
</dict>
319+
</dict>
271320
<key>regexp-expression</key>
272321
<dict>
273322
<key>patterns</key>

Diff for: grammars/src/MagicPython.syntax.yaml

-16
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,6 @@ repository:
351351
captures:
352352
'1': {name: keyword.control.flow.python}
353353

354-
codetags:
355-
match: (?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b)
356-
captures:
357-
'1': {name: keyword.codetag.notation.python}
358-
359354
statement-keyword:
360355
patterns:
361356
- name: storage.type.function.python
@@ -824,17 +819,6 @@ repository:
824819
- include: '#fstring-formatting-braces'
825820
- include: '#fstring-formatting-singe-brace'
826821

827-
fstring-formatting-braces:
828-
patterns:
829-
- comment: empty braces are illegal
830-
match: ({)(\s*?)(})
831-
captures:
832-
'1': {name: constant.character.format.placeholder.other.python}
833-
'2': {name: invalid.illegal.brace.python}
834-
'3': {name: constant.character.format.placeholder.other.python}
835-
- name: constant.character.escape.python
836-
match: ({{|}})
837-
838822
fstring-formatting-singe-brace:
839823
name: invalid.illegal.brace.python
840824
match: (}(?!}))

Diff for: grammars/src/regexp-common.inc.syntax.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ repository:
1212
- match: \{.*?\}
1313
- include: '#regexp-base-common'
1414

15+
fstring-formatting-braces:
16+
patterns:
17+
- comment: empty braces are illegal
18+
match: ({)(\s*?)(})
19+
captures:
20+
'1': {name: constant.character.format.placeholder.other.python}
21+
'2': {name: invalid.illegal.brace.python}
22+
'3': {name: constant.character.format.placeholder.other.python}
23+
- name: constant.character.escape.python
24+
match: ({{|}})
25+
1526
regexp-base-common:
1627
patterns:
1728
- name: support.other.match.any.regexp
@@ -109,4 +120,9 @@ repository:
109120
- include: '#regexp-escape-character'
110121
- include: '#regexp-escape-unicode'
111122
- include: '#regexp-escape-catchall'
123+
124+
codetags:
125+
match: (?:\b(NOTE|XXX|HACK|FIXME|BUG|TODO)\b)
126+
captures:
127+
'1': {name: keyword.codetag.notation.python}
112128
...

Diff for: test/atom-spec/python-re-spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ describe("Grammar Tests", function() {
5656
expect(tokens[4][3].scopes).toEqual(["source.regexp.python","comment.regexp","punctuation.comment.end.regexp"]);
5757
});
5858

59+
it("test/regexp/comments3.re",
60+
function() {
61+
tokens = grammar.tokenizeLines("foo(?#NOTE:comment)bar")
62+
expect(tokens[0][0].value).toBe("foo");
63+
expect(tokens[0][0].scopes).toEqual(["source.regexp.python"]);
64+
expect(tokens[0][1].value).toBe("(?#");
65+
expect(tokens[0][1].scopes).toEqual(["source.regexp.python","comment.regexp","punctuation.comment.begin.regexp"]);
66+
expect(tokens[0][2].value).toBe("NOTE");
67+
expect(tokens[0][2].scopes).toEqual(["source.regexp.python","comment.regexp","keyword.codetag.notation.python"]);
68+
expect(tokens[0][3].value).toBe(":comment");
69+
expect(tokens[0][3].scopes).toEqual(["source.regexp.python","comment.regexp"]);
70+
expect(tokens[0][4].value).toBe(")");
71+
expect(tokens[0][4].scopes).toEqual(["source.regexp.python","comment.regexp","punctuation.comment.end.regexp"]);
72+
expect(tokens[0][5].value).toBe("bar");
73+
expect(tokens[0][5].scopes).toEqual(["source.regexp.python"]);
74+
});
75+
5976
it("test/regexp/conditional1.re",
6077
function() {
6178
tokens = grammar.tokenizeLines("(<)?(\\w+@\\w+(?:\\.\\w+)+)(?(1)>|$)")

Diff for: test/regexp/comments3.re

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
foo(?#NOTE:comment)bar
2+
3+
4+
5+
foo : source.regexp.python
6+
(?# : comment.regexp, punctuation.comment.begin.regexp, source.regexp.python
7+
NOTE : comment.regexp, keyword.codetag.notation.python, source.regexp.python
8+
:comment : comment.regexp, source.regexp.python
9+
) : comment.regexp, punctuation.comment.end.regexp, source.regexp.python
10+
bar : source.regexp.python

0 commit comments

Comments
 (0)