-
Notifications
You must be signed in to change notification settings - Fork 92
/
pyfstring.inc.syntax.yaml
178 lines (167 loc) · 5.93 KB
/
pyfstring.inc.syntax.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
---
fstring-fnorm-quoted-${line}-line:
name: meta.fstring.python
begin: (\b[fF])([bBuU])?(${marker})
end: (\3)${guard}
beginCaptures:
# "storage.type.string.python" class should be the first one,
# because Atom, VSCode and GitHub don't understand scopes
# separated by whitespace, and simply use the first one
# of them. Highlighting 'f' as 'storage.type' is more
# important for us than having other scopes.
'1': {name: storage.type.string.python
string.quoted.${line}.python
string.interpolated.python}
'2': {name: invalid.illegal.prefix.python}
'3': {name: string.quoted.${line}.python
string.interpolated.python
punctuation.definition.string.begin.python}
endCaptures:
'1': {name: string.quoted.${line}.python
string.interpolated.python
punctuation.definition.string.end.python}
'2': {name: invalid.illegal.newline.python}
patterns:
- include: '#fstring-guts'
- include: '#fstring-illegal-${line}-brace'
- include: '#fstring-${line}-brace'
- include: '#fstring-${line}-core'
fstring-normf-quoted-${line}-line:
name: meta.fstring.python
begin: (\b[bBuU])([fF])(${marker})
end: (\3)${guard}
beginCaptures:
'1': {name: invalid.illegal.prefix.python}
'2': {name: storage.type.string.python
string.quoted.${line}.python
string.interpolated.python}
'3': {name: string.quoted.${line}.python
punctuation.definition.string.begin.python}
endCaptures:
'1': {name: string.quoted.${line}.python
string.interpolated.python
punctuation.definition.string.end.python}
'2': {name: invalid.illegal.newline.python}
patterns:
- include: '#fstring-guts'
- include: '#fstring-illegal-${line}-brace'
- include: '#fstring-${line}-brace'
- include: '#fstring-${line}-core'
fstring-raw-quoted-${line}-line:
name: meta.fstring.python
begin: (\b(?:[rR][fF]|[fF][rR]))(${marker})
end: (\2)${guard}
beginCaptures:
'1': {name: storage.type.string.python
string.quoted.raw.${line}.python
string.interpolated.python}
'2': {name: string.quoted.raw.${line}.python
punctuation.definition.string.begin.python}
endCaptures:
'1': {name: string.quoted.raw.${line}.python
string.interpolated.python
punctuation.definition.string.end.python}
'2': {name: invalid.illegal.newline.python}
patterns:
- include: '#fstring-raw-guts'
- include: '#fstring-illegal-${line}-brace'
- include: '#fstring-${line}-brace'
- include: '#fstring-raw-${line}-core'
fstring-${line}-core:
name: string.quoted.${line}.python string.interpolated.python
match: |
(?x)
(.+?)
(
(?# .* and .*? in multi-line match need special handling of
newlines otherwise SublimeText and Atom will match slightly
differently.
The guard for newlines has to be separate from the
lookahead because of special $ matching rule.)
($\n?)
|
(?=[\\\}\{]|${marker}${guard})
)
(?# due to how multiline regexps are matched we need a special case
for matching a newline character)
| \n
fstring-raw-${line}-core:
name: string.quoted.raw.${line}.python string.interpolated.python
match: |
(?x)
(.+?)
(
(?# .* and .*? in multi-line match need special handling of
newlines otherwise SublimeText and Atom will match slightly
differently.
The guard for newlines has to be separate from the
lookahead because of special $ matching rule.)
($\n?)
|
(?=[\\\}\{]|${marker}${guard})
)
(?# due to how multiline regexps are matched we need a special case
for matching a newline character)
| \n
fstring-${line}-brace:
comment: value interpolation using { ... }
begin: (\{)
end: |
(?x)
(\})${fguard}
beginCaptures:
'1': {name: constant.character.format.placeholder.other.python}
endCaptures:
'1': {name: constant.character.format.placeholder.other.python}
patterns:
- include: '#fstring-terminator-${line}'
- include: '#f-expression'
fstring-terminator-${line}:
patterns:
- name: storage.type.format.python
match: (=(![rsa])?)(?=})
- name: storage.type.format.python
match: (=?![rsa])(?=})
- match: |
(?x)
( (?: =?) (?: ![rsa])? )
( : \w? [<>=^]? [-+ ]? \#?
\d* ,? (\.\d+)? [bcdeEfFgGnosxX%]? )(?=})
captures:
# We use this awkward scope name instead of perhaps more
# elegant "support.other.format.python" because it appears
# that by default it gives a better visual result in various
# systems (e.g. GitHub). This is due to the fact that
# "storage.type..." is more likely to have special
# highlighting in any given color scheme than
# "support.other..."
#
'1': {name: storage.type.format.python}
'2': {name: storage.type.format.python}
- include: '#fstring-terminator-${line}-tail'
fstring-terminator-${line}-tail:
begin: ((?:=?)(?:![rsa])?)(:)(?=.*?{)
end: (?=})${fguard}
beginCaptures:
'1': {name: storage.type.format.python}
'2': {name: storage.type.format.python}
patterns:
- include: '#fstring-illegal-${line}-brace'
- include: '#fstring-${line}-brace'
- name: storage.type.format.python
match: ([bcdeEfFgGnosxX%])(?=})
- name: storage.type.format.python
match: (\.\d+)
- name: storage.type.format.python
match: (,)
- name: storage.type.format.python
match: (\d+)
- name: storage.type.format.python
match: (\#)
- name: storage.type.format.python
match: ([-+ ])
- name: storage.type.format.python
match: ([<>=^])
- name: storage.type.format.python
match: (\w)
...