@@ -11,13 +11,7 @@ export default function(hljs) {
11
11
const regex = hljs . regex ;
12
12
const RUBY_METHOD_RE = '([a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?)' ;
13
13
// TODO: move concepts like CAMEL_CASE into `modes.js`
14
- const CLASS_NAME_RE = regex . either (
15
- / \b ( [ A - Z ] + [ a - z 0 - 9 ] + ) + / ,
16
- // ends in caps
17
- / \b ( [ A - Z ] + [ a - z 0 - 9 ] + ) + [ A - Z ] + / ,
18
- )
19
- ;
20
- const CLASS_NAME_WITH_NAMESPACE_RE = regex . concat ( CLASS_NAME_RE , / ( : : \w + ) * / )
14
+ const CLASS_NAME_RE = / \b ( [ A - Z ] + [ a - z 0 - 9 _ ] + ) + [ A - Z ] * / ;
21
15
// very popular ruby built-ins that one might even assume
22
16
// are actual keywords (despite that not being the case)
23
17
const PSEUDO_KWS = [
@@ -122,17 +116,13 @@ export default function(hljs) {
122
116
end : / \} / ,
123
117
keywords : RUBY_KEYWORDS
124
118
} ;
125
- const STRING = {
119
+ const STRING_INTERPOLABLE = {
126
120
className : 'string' ,
127
121
contains : [
128
122
hljs . BACKSLASH_ESCAPE ,
129
123
SUBST
130
124
] ,
131
125
variants : [
132
- {
133
- begin : / ' / ,
134
- end : / ' /
135
- } ,
136
126
{
137
127
begin : / " / ,
138
128
end : / " /
@@ -142,45 +132,37 @@ export default function(hljs) {
142
132
end : / ` /
143
133
} ,
144
134
{
145
- begin : / % [ q Q w W x ] ? \( / ,
135
+ begin : / % [ Q W x ] ? \( / ,
146
136
end : / \) /
147
137
} ,
148
138
{
149
- begin : / % [ q Q w W x ] ? \[ / ,
139
+ begin : / % [ Q W x ] ? \[ / ,
150
140
end : / \] /
151
141
} ,
152
142
{
153
- begin : / % [ q Q w W x ] ? \{ / ,
143
+ begin : / % [ Q W x ] ? \{ / ,
154
144
end : / \} /
155
145
} ,
156
146
{
157
- begin : / % [ q Q w W x ] ? < / ,
147
+ begin : / % [ Q W x ] ? < / ,
158
148
end : / > /
159
149
} ,
160
150
{
161
- begin : / % [ q Q w W x ] ? \/ / ,
151
+ begin : / % [ Q W x ] ? \/ / ,
162
152
end : / \/ /
163
153
} ,
164
154
{
165
- begin : / % [ q Q w W x ] ? % / ,
155
+ begin : / % [ Q W x ] ? % / ,
166
156
end : / % /
167
157
} ,
168
158
{
169
- begin : / % [ q Q w W x ] ? - / ,
159
+ begin : / % [ Q W x ] ? - / ,
170
160
end : / - /
171
161
} ,
172
162
{
173
- begin : / % [ q Q w W x ] ? \| / ,
163
+ begin : / % [ Q W x ] ? \| / ,
174
164
end : / \| /
175
165
} ,
176
- // in the following expressions, \B in the beginning suppresses recognition of ?-sequences
177
- // where ? is the last character of a preceding identifier, as in: `func?4`
178
- { begin : / \B \? ( \\ \d { 1 , 3 } ) / } ,
179
- { begin : / \B \? ( \\ x [ A - F a - f 0 - 9 ] { 1 , 2 } ) / } ,
180
- { begin : / \B \? ( \\ u \{ ? [ A - F a - f 0 - 9 ] { 1 , 6 } \} ? ) / } ,
181
- { begin : / \B \? ( \\ M - \\ C - | \\ M - \\ c | \\ c \\ M - | \\ M - | \\ C - \\ M - ) [ \x20 - \x7e ] / } ,
182
- { begin : / \B \? \\ ( c | C - ) [ \x20 - \x7e ] / } ,
183
- { begin : / \B \? \\ ? \S / } ,
184
166
// heredocs
185
167
{
186
168
// this guard makes sure that we have an entire heredoc and not a false
@@ -202,6 +184,55 @@ export default function(hljs) {
202
184
}
203
185
]
204
186
} ;
187
+ const STRING_NONINTERPOLABLE = {
188
+ className : 'string' ,
189
+ variants : [
190
+ {
191
+ begin : / ' / ,
192
+ end : / ' /
193
+ } ,
194
+ {
195
+ begin : / % [ q w ] ? \( / ,
196
+ end : / \) /
197
+ } ,
198
+ {
199
+ begin : / % [ q w ] ? \[ / ,
200
+ end : / \] /
201
+ } ,
202
+ {
203
+ begin : / % [ q w ] ? \{ / ,
204
+ end : / \} /
205
+ } ,
206
+ {
207
+ begin : / % [ q w ] ? < / ,
208
+ end : / > /
209
+ } ,
210
+ {
211
+ begin : / % [ q w ] ? \/ / ,
212
+ end : / \/ /
213
+ } ,
214
+ {
215
+ begin : / % [ q w ] ? % / ,
216
+ end : / % /
217
+ } ,
218
+ {
219
+ begin : / % [ q w ] ? - / ,
220
+ end : / - /
221
+ } ,
222
+ {
223
+ begin : / % [ q w ] ? \| / ,
224
+ end : / \| /
225
+ } ,
226
+ // in the following expressions, \B in the beginning suppresses recognition of ?-sequences
227
+ // where ? is the last character of a preceding identifier, as in: `func?4`
228
+ { begin : / \B \? ( \\ \d { 1 , 3 } ) / } ,
229
+ { begin : / \B \? ( \\ x [ A - F a - f 0 - 9 ] { 1 , 2 } ) / } ,
230
+ { begin : / \B \? ( \\ u \{ ? [ A - F a - f 0 - 9 ] { 1 , 6 } \} ? ) / } ,
231
+ { begin : / \B \? ( \\ M - \\ C - | \\ M - \\ c | \\ c \\ M - | \\ M - | \\ C - \\ M - ) [ \x20 - \x7e ] / } ,
232
+ { begin : / \B \? \\ ( c | C - ) [ \x20 - \x7e ] / } ,
233
+ { begin : / \B \? \\ ? \S / }
234
+ ]
235
+ } ;
205
236
206
237
// Ruby syntax is underdocumented, but this grammar seems to be accurate
207
238
// as of version 2.7.2 (confirmed with (irb and `Ripper.sexp(...)`)
@@ -246,7 +277,7 @@ export default function(hljs) {
246
277
const INCLUDE_EXTEND = {
247
278
match : [
248
279
/ ( i n c l u d e | e x t e n d ) \s + / ,
249
- CLASS_NAME_WITH_NAMESPACE_RE
280
+ CLASS_NAME_RE
250
281
] ,
251
282
scope : {
252
283
2 : "title.class"
@@ -259,15 +290,15 @@ export default function(hljs) {
259
290
{
260
291
match : [
261
292
/ c l a s s \s + / ,
262
- CLASS_NAME_WITH_NAMESPACE_RE ,
293
+ CLASS_NAME_RE ,
263
294
/ \s + < \s + / ,
264
- CLASS_NAME_WITH_NAMESPACE_RE
295
+ CLASS_NAME_RE
265
296
]
266
297
} ,
267
298
{
268
299
match : [
269
300
/ \b ( c l a s s | m o d u l e ) \s + / ,
270
- CLASS_NAME_WITH_NAMESPACE_RE
301
+ CLASS_NAME_RE
271
302
]
272
303
}
273
304
] ,
@@ -301,7 +332,7 @@ export default function(hljs) {
301
332
const OBJECT_CREATION = {
302
333
relevance : 0 ,
303
334
match : [
304
- CLASS_NAME_WITH_NAMESPACE_RE ,
335
+ CLASS_NAME_RE ,
305
336
/ \. n e w [ . ( ] /
306
337
] ,
307
338
scope : {
@@ -317,7 +348,8 @@ export default function(hljs) {
317
348
} ;
318
349
319
350
const RUBY_DEFAULT_CONTAINS = [
320
- STRING ,
351
+ STRING_INTERPOLABLE ,
352
+ STRING_NONINTERPOLABLE ,
321
353
CLASS_DEFINITION ,
322
354
INCLUDE_EXTEND ,
323
355
OBJECT_CREATION ,
@@ -326,20 +358,28 @@ export default function(hljs) {
326
358
METHOD_DEFINITION ,
327
359
{
328
360
// swallow namespace qualifiers before symbols
329
- begin : hljs . IDENT_RE + '::' } ,
361
+ begin : hljs . IDENT_RE + '::'
362
+ } ,
330
363
{
331
364
className : 'symbol' ,
332
365
begin : hljs . UNDERSCORE_IDENT_RE + '(!|\\?)?:' ,
333
366
relevance : 0
334
367
} ,
335
368
{
336
369
className : 'symbol' ,
337
- begin : ': (?!\\s)' ,
370
+ begin : '(?<!:): (?!\\s|: )' ,
338
371
contains : [
339
- STRING ,
340
- { begin : RUBY_METHOD_RE }
372
+ { begin : / ' / , end : / ' / } ,
373
+ {
374
+ begin : / " / , end : / " / ,
375
+ contains : [
376
+ hljs . BACKSLASH_ESCAPE ,
377
+ SUBST
378
+ ]
379
+ } ,
380
+ { begin : hljs . UNDERSCORE_IDENT_RE }
341
381
] ,
342
- relevance : 0
382
+ relevance : 1
343
383
} ,
344
384
NUMBER ,
345
385
{
0 commit comments