Skip to content

Commit e437325

Browse files
authoredDec 10, 2021
V: Use standard char token (#3260)
1 parent 2069ab0 commit e437325

File tree

4 files changed

+40
-34
lines changed

4 files changed

+40
-34
lines changed
 

‎components/prism-v.js

+26-25
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,28 @@
55
};
66

77
Prism.languages.v = Prism.languages.extend('clike', {
8-
'string': [
9-
{
10-
pattern: /`(?:\\`|\\?[^`]{1,2})`/, // using {1,2} instead of `u` flag for compatibility
11-
alias: 'rune'
12-
},
13-
{
14-
pattern: /r?(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
15-
alias: 'quoted-string',
16-
greedy: true,
17-
inside: {
18-
'interpolation': {
19-
pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\{[^{}]*\}|\w+(?:\.\w+(?:\([^\(\)]*\))?|\[[^\[\]]+\])*)/,
20-
lookbehind: true,
21-
inside: {
22-
'interpolation-variable': {
23-
pattern: /^\$\w[\s\S]*$/,
24-
alias: 'variable'
25-
},
26-
'interpolation-punctuation': {
27-
pattern: /^\$\{|\}$/,
28-
alias: 'punctuation'
29-
},
30-
'interpolation-expression': interpolationExpr
31-
}
8+
'string': {
9+
pattern: /r?(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
10+
alias: 'quoted-string',
11+
greedy: true,
12+
inside: {
13+
'interpolation': {
14+
pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\{[^{}]*\}|\w+(?:\.\w+(?:\([^\(\)]*\))?|\[[^\[\]]+\])*)/,
15+
lookbehind: true,
16+
inside: {
17+
'interpolation-variable': {
18+
pattern: /^\$\w[\s\S]*$/,
19+
alias: 'variable'
20+
},
21+
'interpolation-punctuation': {
22+
pattern: /^\$\{|\}$/,
23+
alias: 'punctuation'
24+
},
25+
'interpolation-expression': interpolationExpr
3226
}
3327
}
3428
}
35-
],
29+
},
3630
'class-name': {
3731
pattern: /(\b(?:enum|interface|struct|type)\s+)(?:C\.)?\w+/,
3832
lookbehind: true
@@ -45,6 +39,13 @@
4539

4640
interpolationExpr.inside = Prism.languages.v;
4741

42+
Prism.languages.insertBefore('v', 'string', {
43+
'char': {
44+
pattern: /`(?:\\`|\\?[^`]{1,2})`/, // using {1,2} instead of `u` flag for compatibility
45+
alias: 'rune'
46+
}
47+
});
48+
4849
Prism.languages.insertBefore('v', 'operator', {
4950
'attribute': {
5051
pattern: /(^[\t ]*)\[(?:deprecated|direct_array_access|flag|inline|live|ref_only|typedef|unsafe_fn|windows_stdcall)\]/m,

‎components/prism-v.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/languages/v/char_feature.test

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
`🚀`
2+
`\``
3+
`Not a Rune`
4+
5+
----------------------------------------------------
6+
7+
[
8+
["char", "`🚀`"],
9+
["char", "`\\``"],
10+
"\r\n`Not a Rune`"
11+
]

‎tests/languages/v/string_feature.test

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
'age = $user.age'
44
'[${int(x):-10}]'
55
r'hello\nworld'
6-
`🚀`
7-
`\``
8-
`Not a Rune`
96

107
----------------------------------------------------
118

@@ -36,12 +33,9 @@ r'hello\nworld'
3633
]],
3734
"]'"
3835
]],
39-
["string", ["r'hello\\nworld'"]],
40-
["string", "`🚀`"],
41-
["string", "`\\``"],
42-
"\r\n`Not a Rune`"
36+
["string", ["r'hello\\nworld'"]]
4337
]
4438

4539
----------------------------------------------------
4640

47-
Check for strings and string interpolation
41+
Check for strings and string interpolation

0 commit comments

Comments
 (0)
Please sign in to comment.