Skip to content
Permalink
Browse files
Zig: Fixed module comments and astral chars (#3129)
  • Loading branch information
RunDevelopment committed Oct 5, 2021
1 parent 599e30e commit 09a0e2ba1bf44036ff86a8e3f87f4a1ddf1d93f5
Showing with 184 additions and 3 deletions.
  1. +2 −2 components/prism-zig.js
  2. +1 −1 components/prism-zig.min.js
  3. +21 −0 tests/languages/zig/comment_feature.test
  4. +160 −0 tests/languages/zig/string_feature.test
@@ -32,7 +32,7 @@
Prism.languages.zig = {
'comment': [
{
pattern: /\/{3}.*/,
pattern: /\/\/[/!].*/,
alias: 'doc-comment'
},
/\/{2}.*/
@@ -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
}

Some generated files are not rendered by default. Learn more.

@@ -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."]
]
@@ -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", ";"]
]

0 comments on commit 09a0e2b

Please sign in to comment.