Skip to content

Commit 010a015

Browse files
D: Fixed strings (#2029)
* Fixed D strings * Rebuilt
1 parent 8a572af commit 010a015

File tree

6 files changed

+130
-57
lines changed

6 files changed

+130
-57
lines changed

components/prism-d.js

+49-34
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,54 @@
11
Prism.languages.d = Prism.languages.extend('clike', {
2+
'comment': [
3+
{
4+
// Shebang
5+
pattern: /^\s*#!.+/,
6+
greedy: true
7+
},
8+
{
9+
pattern: RegExp(/(^|[^\\])/.source + '(?:' + [
10+
// /+ comment +/
11+
// Allow one level of nesting
12+
/\/\+(?:\/\+[\s\S]*?\+\/|(?!\/\+)[\s\S])*?\+\//.source,
13+
// // comment
14+
/\/\/.*/.source,
15+
// /* comment */
16+
/\/\*[\s\S]*?\*\//.source
17+
].join('|') + ')'),
18+
lookbehind: true,
19+
greedy: true
20+
}
21+
],
222
'string': [
3-
// r"", x""
4-
/\b[rx]"(?:\\[\s\S]|[^\\"])*"[cwd]?/,
5-
// q"[]", q"()", q"<>", q"{}"
6-
/\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/,
7-
// q"IDENT
8-
// ...
9-
// IDENT"
10-
/\bq"([_a-zA-Z][_a-zA-Z\d]*)(?:\r?\n|\r)[\s\S]*?(?:\r?\n|\r)\1"/,
11-
// q"//", q"||", etc.
12-
/\bq"(.)[\s\S]*?\1"/,
13-
// Characters
14-
/'(?:\\'|\\?[^']+)'/,
23+
{
24+
pattern: RegExp([
25+
// r"", x""
26+
/\b[rx]"(?:\\[\s\S]|[^\\"])*"[cwd]?/.source,
27+
28+
// q"[]", q"()", q"<>", q"{}"
29+
/\bq"(?:\[[\s\S]*?\]|\([\s\S]*?\)|<[\s\S]*?>|\{[\s\S]*?\})"/.source,
30+
31+
// q"IDENT
32+
// ...
33+
// IDENT"
34+
/\bq"((?!\d)\w+)$[\s\S]*?^\1"/.source,
35+
36+
// q"//", q"||", etc.
37+
/\bq"(.)[\s\S]*?\2"/.source,
38+
39+
// Characters
40+
// 'a', '\\', '\n', '\xFF', '\377', '\uFFFF', '\U0010FFFF', '\quot'
41+
/'(?:\\(?:\W|\w+)|[^\\])'/.source,
1542

16-
/(["`])(?:\\[\s\S]|(?!\1)[^\\])*\1[cwd]?/
43+
/(["`])(?:\\[\s\S]|(?!\3)[^\\])*\3[cwd]?/.source
44+
].join('|'), 'm'),
45+
greedy: true
46+
},
47+
{
48+
pattern: /\bq\{(?:\{[^{}]*\}|[^{}])*\}/,
49+
greedy: true,
50+
alias: 'token-string'
51+
}
1752
],
1853

1954
'number': [
@@ -31,26 +66,6 @@ Prism.languages.d = Prism.languages.extend('clike', {
3166
'operator': /\|[|=]?|&[&=]?|\+[+=]?|-[-=]?|\.?\.\.|=[>=]?|!(?:i[ns]\b|<>?=?|>=?|=)?|\bi[ns]\b|(?:<[<>]?|>>?>?|\^\^|[*\/%^~])=?/
3267
});
3368

34-
35-
Prism.languages.d.comment = [
36-
// Shebang
37-
/^\s*#!.+/,
38-
// /+ +/
39-
{
40-
// Allow one level of nesting
41-
pattern: /(^|[^\\])\/\+(?:\/\+[\s\S]*?\+\/|[\s\S])*?\+\//,
42-
lookbehind: true
43-
}
44-
].concat(Prism.languages.d.comment);
45-
46-
Prism.languages.insertBefore('d', 'comment', {
47-
'token-string': {
48-
// Allow one level of nesting
49-
pattern: /\bq\{(?:\{[^}]*\}|[^}])*\}/,
50-
alias: 'string'
51-
}
52-
});
53-
5469
Prism.languages.insertBefore('d', 'keyword', {
5570
'property': /\B@\w*/
5671
});
@@ -61,4 +76,4 @@ Prism.languages.insertBefore('d', 'function', {
6176
pattern: /\b(?:[ABCD][LHX]|E[ABCD]X|E?(?:BP|SP|DI|SI)|[ECSDGF]S|CR[0234]|DR[012367]|TR[3-7]|X?MM[0-7]|R[ABCD]X|[BS]PL|R[BS]P|[DS]IL|R[DS]I|R(?:[89]|1[0-5])[BWD]?|XMM(?:[89]|1[0-5])|YMM(?:1[0-5]|\d))\b|\bST(?:\([0-7]\)|\b)/,
6277
alias: 'variable'
6378
}
64-
});
79+
});

components/prism-d.min.js

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

tests/languages/d/comment_feature.test

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ bar +/
99
baz +/
1010
// This q{is} a comment
1111
// This /* is a */ comment
12+
/*
13+
comment
14+
*/
1215

1316
----------------------------------------------------
1417

@@ -18,10 +21,11 @@ baz +/
1821
["comment", "/+ foo\r\nbar +/"],
1922
["comment", "/+ foo\r\n\t/+\r\n\tbar +/\r\nbaz +/"],
2023
["comment", "// This q{is} a comment"],
21-
["comment", "// This /* is a */ comment"]
24+
["comment", "// This /* is a */ comment"],
25+
["comment", "/*\r\ncomment\r\n*/"]
2226
]
2327

2428
----------------------------------------------------
2529

2630
Checks for shebang and nestable multi-line comments.
27-
Other comments are tested in clike.
31+
Other comments are tested in clike.

tests/languages/d/issue2027.test

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
string foo = "It's";
2+
foo = "It's";
3+
foo = "It's";
4+
5+
string bar = `It's`;
6+
bar = `It's`;
7+
bar = `It's`;
8+
bar = `It's`;
9+
10+
----------------------------------------------------
11+
12+
[
13+
["keyword", "string"],
14+
" foo ",
15+
["operator", "="],
16+
["string", "\"It's\""],
17+
["punctuation", ";"],
18+
"\r\nfoo ",
19+
["operator", "="],
20+
["string", "\"It's\""],
21+
["punctuation", ";"],
22+
"\r\nfoo ",
23+
["operator", "="],
24+
["string", "\"It's\""],
25+
["punctuation", ";"],
26+
["keyword", "string"],
27+
" bar ",
28+
["operator", "="],
29+
["string", "`It's`"],
30+
["punctuation", ";"],
31+
"\r\nbar ",
32+
["operator", "="],
33+
["string", "`It's`"],
34+
["punctuation", ";"],
35+
"\r\nbar ",
36+
["operator", "="],
37+
["string", "`It's`"],
38+
["punctuation", ";"],
39+
"\r\nbar ",
40+
["operator", "="],
41+
["string", "`It's`"],
42+
["punctuation", ";"]
43+
]
44+
45+
----------------------------------------------------
46+
47+
Checks for issue #2027 which was about strings not being matched correctly.

tests/languages/d/string_feature.test

+27-7
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,26 @@ bar/"
1919
q"|fo"o
2020
bar|"
2121

22-
'a' '\'' '\u000A'
22+
'a' '\'' '\\' '\n' '\xFF' '\377' '\uFFFF' '\U0010FFFF' '\quot'
2323

2424
""
2525
"foo"c "bar"w "baz"d
2626
"fo\"o
2727
bar"
2828
`foo`
2929

30+
q{foo}
31+
q{ q{bar} }
32+
3033
----------------------------------------------------
3134

3235
[
33-
["string", "r\"\""], ["string", "x\"\""],
34-
["string", "r\"fo\\\"o\"c"], ["string", "x\"00 FBCD\"w"], ["string", "r\"baz\"d"],
36+
["string", "r\"\""],
37+
["string", "x\"\""],
38+
39+
["string", "r\"fo\\\"o\"c"],
40+
["string", "x\"00 FBCD\"w"],
41+
["string", "r\"baz\"d"],
3542

3643
["string", "q\"[fo\"o\r\nbar]\""],
3744
["string", "q\"(fo\"o\r\nbar)\""],
@@ -43,14 +50,27 @@ bar"
4350
["string", "q\"/fo\"o\r\nbar/\""],
4451
["string", "q\"|fo\"o\r\nbar|\""],
4552

46-
["string", "'a'"], ["string", "'\\''"], ["string", "'\\u000A'"],
53+
["string", "'a'"],
54+
["string", "'\\''"],
55+
["string", "'\\\\'"],
56+
["string", "'\\n'"],
57+
["string", "'\\xFF'"],
58+
["string", "'\\377'"],
59+
["string", "'\\uFFFF'"],
60+
["string", "'\\U0010FFFF'"],
61+
["string", "'\\quot'"],
4762

4863
["string", "\"\""],
49-
["string", "\"foo\"c"], ["string", "\"bar\"w"], ["string", "\"baz\"d"],
64+
["string", "\"foo\"c"],
65+
["string", "\"bar\"w"],
66+
["string", "\"baz\"d"],
5067
["string", "\"fo\\\"o\r\nbar\""],
51-
["string", "`foo`"]
68+
["string", "`foo`"],
69+
70+
["string", "q{foo}"],
71+
["string", "q{ q{bar} }"]
5272
]
5373

5474
----------------------------------------------------
5575

56-
Checks for strings.
76+
Checks for strings and token strings.

tests/languages/d/token-string_feature.test

-13
This file was deleted.

0 commit comments

Comments
 (0)