Skip to content

Commit 09a0e2b

Browse files
authoredOct 5, 2021
Zig: Fixed module comments and astral chars (#3129)
1 parent 599e30e commit 09a0e2b

File tree

4 files changed

+184
-3
lines changed

4 files changed

+184
-3
lines changed
 

‎components/prism-zig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
Prism.languages.zig = {
3333
'comment': [
3434
{
35-
pattern: /\/{3}.*/,
35+
pattern: /\/\/[/!].*/,
3636
alias: 'doc-comment'
3737
},
3838
/\/{2}.*/
@@ -52,7 +52,7 @@
5252
},
5353
{
5454
// characters 'a', '\n', '\xFF', '\u{10FFFF}'
55-
pattern: /(^|[^\\])'(?:[^'\\\r\n]|\\(?:.|x[a-fA-F\d]{2}|u\{[a-fA-F\d]{1,6}\}))'/,
55+
pattern: /(^|[^\\])'(?:[^'\\\r\n]|[\uD800-\uDFFF]{2}|\\(?:.|x[a-fA-F\d]{2}|u\{[a-fA-F\d]{1,6}\}))'/,
5656
lookbehind: true,
5757
greedy: true
5858
}

‎components/prism-zig.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// normal comment
2+
3+
/// A structure for storing a timestamp, with nanosecond precision (this is a
4+
/// multiline doc comment).
5+
6+
//! This module provides functions for retrieving the current date and
7+
//! time with varying degrees of precision and accuracy. It does not
8+
//! depend on libc, but will use functions from it if available.
9+
10+
----------------------------------------------------
11+
12+
[
13+
["comment", "// normal comment"],
14+
15+
["comment", "/// A structure for storing a timestamp, with nanosecond precision (this is a"],
16+
["comment", "/// multiline doc comment)."],
17+
18+
["comment", "//! This module provides functions for retrieving the current date and"],
19+
["comment", "//! time with varying degrees of precision and accuracy. It does not"],
20+
["comment", "//! depend on libc, but will use functions from it if available."]
21+
]
+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// source: https://ziglang.org/documentation/master/#String-Literals-and-Character-Literals
2+
3+
const expect = @import("std").testing.expect;
4+
const mem = @import("std").mem;
5+
6+
test "string literals" {
7+
const bytes = "hello";
8+
expect(@TypeOf(bytes) == *const [5:0]u8);
9+
expect(bytes.len == 5);
10+
expect(bytes[1] == 'e');
11+
expect(bytes[5] == 0);
12+
expect('e' == '\x65');
13+
expect('\u{1f4a9}' == 128169);
14+
expect('💯' == 128175);
15+
expect(mem.eql(u8, "hello", "h\x65llo"));
16+
}
17+
18+
const hello_world_in_c =
19+
\\#include <stdio.h>
20+
\\
21+
\\int main(int argc, char **argv) {
22+
\\ printf("hello world\n");
23+
\\ return 0;
24+
\\}
25+
;
26+
27+
----------------------------------------------------
28+
29+
[
30+
["comment", "// source: https://ziglang.org/documentation/master/#String-Literals-and-Character-Literals"],
31+
32+
["keyword", "const"],
33+
" expect ",
34+
["operator", "="],
35+
["builtin", "@import"],
36+
["punctuation", "("],
37+
["string", "\"std\""],
38+
["punctuation", ")"],
39+
["punctuation", "."],
40+
"testing",
41+
["punctuation", "."],
42+
"expect",
43+
["punctuation", ";"],
44+
45+
["keyword", "const"],
46+
" mem ",
47+
["operator", "="],
48+
["builtin", "@import"],
49+
["punctuation", "("],
50+
["string", "\"std\""],
51+
["punctuation", ")"],
52+
["punctuation", "."],
53+
"mem",
54+
["punctuation", ";"],
55+
56+
["keyword", "test"],
57+
["string", "\"string literals\""],
58+
["punctuation", "{"],
59+
60+
["keyword", "const"],
61+
" bytes ",
62+
["operator", "="],
63+
["string", "\"hello\""],
64+
["punctuation", ";"],
65+
66+
["function", "expect"],
67+
["punctuation", "("],
68+
["builtin", "@TypeOf"],
69+
["punctuation", "("],
70+
"bytes",
71+
["punctuation", ")"],
72+
["operator", "=="],
73+
["operator", "*"],
74+
["keyword", "const"],
75+
["punctuation", "["],
76+
["number", "5"],
77+
["punctuation", ":"],
78+
["number", "0"],
79+
["punctuation", "]"],
80+
["builtin-types", "u8"],
81+
["punctuation", ")"],
82+
["punctuation", ";"],
83+
84+
["function", "expect"],
85+
["punctuation", "("],
86+
"bytes",
87+
["punctuation", "."],
88+
"len ",
89+
["operator", "=="],
90+
["number", "5"],
91+
["punctuation", ")"],
92+
["punctuation", ";"],
93+
94+
["function", "expect"],
95+
["punctuation", "("],
96+
"bytes",
97+
["punctuation", "["],
98+
["number", "1"],
99+
["punctuation", "]"],
100+
["operator", "=="],
101+
["string", "'e'"],
102+
["punctuation", ")"],
103+
["punctuation", ";"],
104+
105+
["function", "expect"],
106+
["punctuation", "("],
107+
"bytes",
108+
["punctuation", "["],
109+
["number", "5"],
110+
["punctuation", "]"],
111+
["operator", "=="],
112+
["number", "0"],
113+
["punctuation", ")"],
114+
["punctuation", ";"],
115+
116+
["function", "expect"],
117+
["punctuation", "("],
118+
["string", "'e'"],
119+
["operator", "=="],
120+
["string", "'\\x65'"],
121+
["punctuation", ")"],
122+
["punctuation", ";"],
123+
124+
["function", "expect"],
125+
["punctuation", "("],
126+
["string", "'\\u{1f4a9}'"],
127+
["operator", "=="],
128+
["number", "128169"],
129+
["punctuation", ")"],
130+
["punctuation", ";"],
131+
132+
["function", "expect"],
133+
["punctuation", "("],
134+
["string", "'💯'"],
135+
["operator", "=="],
136+
["number", "128175"],
137+
["punctuation", ")"],
138+
["punctuation", ";"],
139+
140+
["function", "expect"],
141+
["punctuation", "("],
142+
"mem",
143+
["punctuation", "."],
144+
["function", "eql"],
145+
["punctuation", "("],
146+
["builtin-types", "u8"],
147+
["punctuation", ","],
148+
["string", "\"hello\""],
149+
["punctuation", ","],
150+
["string", "\"h\\x65llo\""],
151+
["punctuation", ")"],
152+
["punctuation", ")"],
153+
["punctuation", ";"],
154+
155+
["punctuation", "}"],
156+
157+
["keyword", "const"], " hello_world_in_c ", ["operator", "="],
158+
["string", " \\\\#include <stdio.h>\r\n \\\\\r\n \\\\int main(int argc, char **argv) {\r\n \\\\ printf(\"hello world\\n\");\r\n \\\\ return 0;\r\n \\\\}"],
159+
["punctuation", ";"]
160+
]

0 commit comments

Comments
 (0)
Please sign in to comment.