Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig: Fixed module comments and astral chars #3129

Merged
merged 1 commit into from Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/prism-zig.js
Expand Up @@ -32,7 +32,7 @@
Prism.languages.zig = {
'comment': [
{
pattern: /\/{3}.*/,
pattern: /\/\/[/!].*/,
alias: 'doc-comment'
},
/\/{2}.*/
Expand All @@ -52,7 +52,7 @@
},
{
// characters 'a', '\n', '\xFF', '\u{10FFFF}'
pattern: /(^|[^\\])'(?:[^'\\\r\n]|\\(?:.|x[a-fA-F\d]{2}|u\{[a-fA-F\d]{1,6}\}))'/,
pattern: /(^|[^\\])'(?:[^'\\\r\n]|[\uD800-\uDFFF]{2}|\\(?:.|x[a-fA-F\d]{2}|u\{[a-fA-F\d]{1,6}\}))'/,
lookbehind: true,
greedy: true
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-zig.min.js

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

21 changes: 21 additions & 0 deletions tests/languages/zig/comment_feature.test
@@ -0,0 +1,21 @@
// normal comment

/// A structure for storing a timestamp, with nanosecond precision (this is a
/// multiline doc comment).

//! This module provides functions for retrieving the current date and
//! time with varying degrees of precision and accuracy. It does not
//! depend on libc, but will use functions from it if available.

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

[
["comment", "// normal comment"],

["comment", "/// A structure for storing a timestamp, with nanosecond precision (this is a"],
["comment", "/// multiline doc comment)."],

["comment", "//! This module provides functions for retrieving the current date and"],
["comment", "//! time with varying degrees of precision and accuracy. It does not"],
["comment", "//! depend on libc, but will use functions from it if available."]
]
160 changes: 160 additions & 0 deletions tests/languages/zig/string_feature.test
@@ -0,0 +1,160 @@
// source: https://ziglang.org/documentation/master/#String-Literals-and-Character-Literals

const expect = @import("std").testing.expect;
const mem = @import("std").mem;

test "string literals" {
const bytes = "hello";
expect(@TypeOf(bytes) == *const [5:0]u8);
expect(bytes.len == 5);
expect(bytes[1] == 'e');
expect(bytes[5] == 0);
expect('e' == '\x65');
expect('\u{1f4a9}' == 128169);
expect('💯' == 128175);
expect(mem.eql(u8, "hello", "h\x65llo"));
}

const hello_world_in_c =
\\#include <stdio.h>
\\
\\int main(int argc, char **argv) {
\\ printf("hello world\n");
\\ return 0;
\\}
;

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

[
["comment", "// source: https://ziglang.org/documentation/master/#String-Literals-and-Character-Literals"],

["keyword", "const"],
" expect ",
["operator", "="],
["builtin", "@import"],
["punctuation", "("],
["string", "\"std\""],
["punctuation", ")"],
["punctuation", "."],
"testing",
["punctuation", "."],
"expect",
["punctuation", ";"],

["keyword", "const"],
" mem ",
["operator", "="],
["builtin", "@import"],
["punctuation", "("],
["string", "\"std\""],
["punctuation", ")"],
["punctuation", "."],
"mem",
["punctuation", ";"],

["keyword", "test"],
["string", "\"string literals\""],
["punctuation", "{"],

["keyword", "const"],
" bytes ",
["operator", "="],
["string", "\"hello\""],
["punctuation", ";"],

["function", "expect"],
["punctuation", "("],
["builtin", "@TypeOf"],
["punctuation", "("],
"bytes",
["punctuation", ")"],
["operator", "=="],
["operator", "*"],
["keyword", "const"],
["punctuation", "["],
["number", "5"],
["punctuation", ":"],
["number", "0"],
["punctuation", "]"],
["builtin-types", "u8"],
["punctuation", ")"],
["punctuation", ";"],

["function", "expect"],
["punctuation", "("],
"bytes",
["punctuation", "."],
"len ",
["operator", "=="],
["number", "5"],
["punctuation", ")"],
["punctuation", ";"],

["function", "expect"],
["punctuation", "("],
"bytes",
["punctuation", "["],
["number", "1"],
["punctuation", "]"],
["operator", "=="],
["string", "'e'"],
["punctuation", ")"],
["punctuation", ";"],

["function", "expect"],
["punctuation", "("],
"bytes",
["punctuation", "["],
["number", "5"],
["punctuation", "]"],
["operator", "=="],
["number", "0"],
["punctuation", ")"],
["punctuation", ";"],

["function", "expect"],
["punctuation", "("],
["string", "'e'"],
["operator", "=="],
["string", "'\\x65'"],
["punctuation", ")"],
["punctuation", ";"],

["function", "expect"],
["punctuation", "("],
["string", "'\\u{1f4a9}'"],
["operator", "=="],
["number", "128169"],
["punctuation", ")"],
["punctuation", ";"],

["function", "expect"],
["punctuation", "("],
["string", "'💯'"],
["operator", "=="],
["number", "128175"],
["punctuation", ")"],
["punctuation", ";"],

["function", "expect"],
["punctuation", "("],
"mem",
["punctuation", "."],
["function", "eql"],
["punctuation", "("],
["builtin-types", "u8"],
["punctuation", ","],
["string", "\"hello\""],
["punctuation", ","],
["string", "\"h\\x65llo\""],
["punctuation", ")"],
["punctuation", ")"],
["punctuation", ";"],

["punctuation", "}"],

["keyword", "const"], " hello_world_in_c ", ["operator", "="],
["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 \\\\}"],
["punctuation", ";"]
]