From 0620864740a71e798e2084cde81cc5607a5bc166 Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 29 Feb 2020 22:16:28 +0900 Subject: [PATCH 1/3] Add Zig programming language --- src/languages/zig.js | 104 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/languages/zig.js diff --git a/src/languages/zig.js b/src/languages/zig.js new file mode 100644 index 0000000000..6c86cea89d --- /dev/null +++ b/src/languages/zig.js @@ -0,0 +1,104 @@ +/* +Language: Zig +Author: sksat +Description: Zig is a general-purpose programming language designed for robustness, optimality, and maintainability. +Website: https://ziglang.org +Category: system +*/ + +export default function(hljs) { + var ZIG_KEYWORDS = + 'fn usingnamespace test ' + + // storage + 'const var extern packed export pub noalias inline noinline comptime ' + + 'callconv volatile allowzero align linksection threadlocal ' + + // structure + 'struct enum union error ' + + // statement + 'break return continue asm defer errdefer unreachable try catch ' + + 'async noasync await suspend resume ' + + // conditional + 'if else switch and or orelse ' + + // repeat + 'while for ' + + // constant + 'true false null undefined'; + var ZIG_BUILTINS = + // type + 'noreturn type anyerror anyframe ' + + 'void comptime_int comptime_float ' + + 'bool isize usize ' + + 'f16 f32 f64 f128 ' + + // C type + 'c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong c_longdouble c_void'; + + var ZIG_BUILTIN_FUNC = + 'addWithOverflow ArgType atomicLoad atomicStore bitCast breakpoint ' + + 'alignCast alignOf cDefine cImport cInclude ' + + 'cUndef canImplicitCast clz cmpxchgWeak cmpxchgStrong compileError ' + + 'compileLog ctz popCount divExact divFloor divTrunc ' + + 'embedFile export tagName TagType errorName call ' + + 'errorReturnTrace fence fieldParentPtr field unionInit ' + + 'frameAddress import newStackCall asyncCall intToPtr IntType ' + + 'memberCount memberName memberType as ' + + 'memcpy memset mod mulWithOverflow splat ' + + 'bitOffsetOf byteOffsetOf OpaqueType panic ptrCast ' + + 'ptrToInt rem returnAddress setCold Type shuffle ' + + 'setRuntimeSafety setEvalBranchQuota setFloatMode ' + + 'setGlobalLinkage setGlobalSection shlExact This hasDecl hasField ' + + 'shlWithOverflow shrExact sizeOf bitSizeOf sqrt byteSwap subWithOverflow intCast floatCast intToFloat floatToInt boolToInt errSetCast ' + + 'truncate typeId typeInfo typeName TypeOf atomicRmw bytesToSlice sliceToBytes ' + + 'intToError errorToInt intToEnum enumToInt setAlignStack frame Frame frameSize bitReverse Vector ' + + 'sin cos exp exp2 log log2 log10 fabs floor ceil trunc round'; + + return { + name: 'Zig', + aliases: ['zig', 'ziglang'], + keywords: { + keyword: + ZIG_KEYWORDS, + literal: + 'true false null undefined', + built_in: + ZIG_BUILTINS, + }, + + contains: [ + hljs.C_LINE_COMMENT_MODE, + hljs.C_BLOCK_COMMENT_MODE, + { + className: 'string', + variants: [ + hljs.QUOTE_STRING_MODE, + ] + }, + { + className: 'number', + variants: [ + hljs.C_NUMBER_MODE, + ] + }, + { + className: 'type', + begin: /(i|u)(\d{3}|\d{2}|\d{1})/ + }, + { + className: 'meta', + begin: /@\s*[a-zA-Z]+\b/, + keywords: {'meta-keyword': ZIG_BUILTIN_FUNC}, + contains: [ + hljs.QUOTE_STRING_MODE, + ] + }, + { + className: 'symbol', + begin: /'[a-zA-Z_][a-zA-Z0-9_]*/ + }, + { + className: 'function', + beginKeywords: 'fn', end: '(\\(|<)', excludeEnd: true, + contains: [hljs.TITLE_MODE] + }, + ] + }; +} From 40fc97da6f3f2cdd940fb36d4f9ea9e1a2996366 Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 29 Feb 2020 22:16:56 +0900 Subject: [PATCH 2/3] Add Zig example --- test/detect/zig/default.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test/detect/zig/default.txt diff --git a/test/detect/zig/default.txt b/test/detect/zig/default.txt new file mode 100644 index 0000000000..128820d3ee --- /dev/null +++ b/test/detect/zig/default.txt @@ -0,0 +1,5 @@ +const std = @import("std"); + +pub fn main() anyerror!void { + std.debug.warn("All your base are belong to us.\n"); +} From 0d05693d007ca7039067ad4ef56d8294caa0952c Mon Sep 17 00:00:00 2001 From: sksat Date: Sat, 29 Feb 2020 22:22:52 +0900 Subject: [PATCH 3/3] Update authors list --- AUTHORS.txt | 1 + CHANGES.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index 799acc064a..275548bb3d 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -286,3 +286,4 @@ Contributors: - G8t Guy - Samia Ali - Alexandre Grison +- sksat diff --git a/CHANGES.md b/CHANGES.md index 67631e65a2..9f93fb70fd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,7 @@ New languages: - (php-template) Explicit language to detect PHP templates (vs xml) [Josh Goebel][] - enh(python) Added `python-repl` for Python REPL sessions +- *Zig* by [sksat][] New themes: @@ -54,6 +55,7 @@ Developer Tools: [Taufik Nurrohman]: https://github.com/taufik-nurrohman [Josh Goebel]: https://github.com/yyyc514 [Sean Williams]: https://github.com/hmmwhatsthisdo +[sksat]: https://github.com/sk2sat ## Version 9.18.1