Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,4 @@ Contributors:
- G8t Guy <g8tguy@g8tguy.com>
- Samia Ali <samiaab1990@gmail.com>
- Alexandre Grison <a.grison@gmail.com>
- sksat <sksat@sksat.net>
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down
104 changes: 104 additions & 0 deletions src/languages/zig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Language: Zig
Author: sksat <sksat@sksat.net>
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]
},
]
};
}
5 changes: 5 additions & 0 deletions test/detect/zig/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const std = @import("std");

pub fn main() anyerror!void {
std.debug.warn("All your base are belong to us.\n");
}