Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
V: Use standard char token (#3260)
  • Loading branch information
RunDevelopment committed Dec 10, 2021
1 parent 2069ab0 commit e437325
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
51 changes: 26 additions & 25 deletions components/prism-v.js
Expand Up @@ -5,34 +5,28 @@
};

Prism.languages.v = Prism.languages.extend('clike', {
'string': [
{
pattern: /`(?:\\`|\\?[^`]{1,2})`/, // using {1,2} instead of `u` flag for compatibility
alias: 'rune'
},
{
pattern: /r?(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
alias: 'quoted-string',
greedy: true,
inside: {
'interpolation': {
pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\{[^{}]*\}|\w+(?:\.\w+(?:\([^\(\)]*\))?|\[[^\[\]]+\])*)/,
lookbehind: true,
inside: {
'interpolation-variable': {
pattern: /^\$\w[\s\S]*$/,
alias: 'variable'
},
'interpolation-punctuation': {
pattern: /^\$\{|\}$/,
alias: 'punctuation'
},
'interpolation-expression': interpolationExpr
}
'string': {
pattern: /r?(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
alias: 'quoted-string',
greedy: true,
inside: {
'interpolation': {
pattern: /((?:^|[^\\])(?:\\{2})*)\$(?:\{[^{}]*\}|\w+(?:\.\w+(?:\([^\(\)]*\))?|\[[^\[\]]+\])*)/,
lookbehind: true,
inside: {
'interpolation-variable': {
pattern: /^\$\w[\s\S]*$/,
alias: 'variable'
},
'interpolation-punctuation': {
pattern: /^\$\{|\}$/,
alias: 'punctuation'
},
'interpolation-expression': interpolationExpr
}
}
}
],
},
'class-name': {
pattern: /(\b(?:enum|interface|struct|type)\s+)(?:C\.)?\w+/,
lookbehind: true
Expand All @@ -45,6 +39,13 @@

interpolationExpr.inside = Prism.languages.v;

Prism.languages.insertBefore('v', 'string', {
'char': {
pattern: /`(?:\\`|\\?[^`]{1,2})`/, // using {1,2} instead of `u` flag for compatibility
alias: 'rune'
}
});

Prism.languages.insertBefore('v', 'operator', {
'attribute': {
pattern: /(^[\t ]*)\[(?:deprecated|direct_array_access|flag|inline|live|ref_only|typedef|unsafe_fn|windows_stdcall)\]/m,
Expand Down
2 changes: 1 addition & 1 deletion components/prism-v.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/languages/v/char_feature.test
@@ -0,0 +1,11 @@
`🚀`
`\``
`Not a Rune`

----------------------------------------------------

[
["char", "`🚀`"],
["char", "`\\``"],
"\r\n`Not a Rune`"
]
10 changes: 2 additions & 8 deletions tests/languages/v/string_feature.test
Expand Up @@ -3,9 +3,6 @@
'age = $user.age'
'[${int(x):-10}]'
r'hello\nworld'
`🚀`
`\``
`Not a Rune`

----------------------------------------------------

Expand Down Expand Up @@ -36,12 +33,9 @@ r'hello\nworld'
]],
"]'"
]],
["string", ["r'hello\\nworld'"]],
["string", "`🚀`"],
["string", "`\\``"],
"\r\n`Not a Rune`"
["string", ["r'hello\\nworld'"]]
]

----------------------------------------------------

Check for strings and string interpolation
Check for strings and string interpolation

0 comments on commit e437325

Please sign in to comment.