%YAML 1.2
---
name: Zig
file_extensions:
- zig
- zon
scope: source.zig
variables:
identifier: '[A-Za-z_][A-Za-z0-9_]*'
contexts:
main:
- include: comments
- include: strings
- include: characters
- include: numbers
- include: keywords
- include: builtins
- include: types
- include: operators
- include: punctuation
comments:
- match: '///.*$'
scope: comment.line.documentation.zig
- match: '//.*$'
scope: comment.line.double-slash.zig
strings:
- match: '\\\\'
scope: punctuation.definition.string.begin.zig
push:
- meta_scope: string.quoted.other.zig
- match: '$'
pop: true
- match: '"'
scope: punctuation.definition.string.begin.zig
push:
- meta_scope: string.quoted.double.zig
- match: '"'
scope: punctuation.definition.string.end.zig
pop: true
- include: string-escapes
string-escapes:
- match: '\\[nrt\\''"]'
scope: constant.character.escape.zig
- match: '\\x[0-9a-fA-F]{2}'
scope: constant.character.escape.hex.zig
- match: '\\u\{[0-9a-fA-F]+\}'
scope: constant.character.escape.unicode.zig
characters:
- match: "'.'"
scope: string.quoted.single.zig
- match: "'\\\\[nrt\\\\'\"]'"
scope: string.quoted.single.zig
- match: "'\\\\x[0-9a-fA-F]{2}'"
scope: string.quoted.single.zig
- match: "'\\\\u\\{[0-9a-fA-F]+\\}'"
scope: string.quoted.single.zig
numbers:
- match: '\b0b[01_]+\b'
scope: constant.numeric.binary.zig
- match: '\b0o[0-7_]+\b'
scope: constant.numeric.octal.zig
- match: '\b0x[0-9a-fA-F_]+(\.[0-9a-fA-F_]+)?([pP][+-]?[0-9_]+)?\b'
scope: constant.numeric.hex.zig
- match: '\b[0-9][0-9_]*\.[0-9][0-9_]*([eE][+-]?[0-9_]+)?\b'
scope: constant.numeric.float.zig
- match: '\b[0-9][0-9_]*[eE][+-]?[0-9_]+\b'
scope: constant.numeric.float.zig
- match: '\b[0-9][0-9_]*\b'
scope: constant.numeric.integer.zig
keywords:
- match: '\b(if|else|switch|while|for|break|continue|return|unreachable)\b'
scope: keyword.control.zig
- match: '\b(try|catch|orelse)\b'
scope: keyword.control.zig
- match: '\b(async|await|suspend|resume|nosuspend)\b'
scope: keyword.control.zig
- match: '\b(defer|errdefer)\b'
scope: keyword.control.zig
- match: '\b(const|var|fn|pub|extern|export|inline|noinline|threadlocal|allowzero)\b'
scope: keyword.declaration.zig
- match: '\b(struct|enum|union|error|opaque|packed|align)\b'
scope: keyword.declaration.type.zig
- match: '\b(comptime|test|usingnamespace)\b'
scope: keyword.other.zig
- match: '\b(and|or)\b'
scope: keyword.operator.logical.zig
- match: '\b(true|false|null|undefined)\b'
scope: constant.language.zig
- match: '\b_\b'
scope: variable.language.blank.zig
builtins:
- match: '@{{identifier}}'
scope: support.function.builtin.zig
types:
- match: '\b(i8|i16|i32|i64|i128|isize)\b'
scope: storage.type.zig
- match: '\b(u8|u16|u32|u64|u128|usize)\b'
scope: storage.type.zig
- match: '\b(f16|f32|f64|f80|f128)\b'
scope: storage.type.zig
- match: '\b(bool|void|noreturn|type|anyerror|anytype|anyframe|anyopaque)\b'
scope: storage.type.zig
- match: '\b(c_short|c_ushort|c_int|c_uint|c_long|c_ulong|c_longlong|c_ulonglong|c_longdouble|c_void)\b'
scope: storage.type.zig
operators:
- match: '(\+\+|--|\+%|-%)|\+|-|\*%|\*|/|%'
scope: keyword.operator.arithmetic.zig
- match: '(==|!=|<=|>=|<|>)'
scope: keyword.operator.comparison.zig
- match: '(&|\\||\\^|~|<<|>>)'
scope: keyword.operator.bitwise.zig
- match: '(\+=|-=|\*=|/=|%=|&=|\|=|\^=|<<=|>>=|=)'
scope: keyword.operator.assignment.zig
- match: '(\.\.\.|\.\.|\.\*|\.|\?|\*\*)'
scope: keyword.operator.other.zig
punctuation:
- match: '(\(|\)|\{|\}|\[|\]|,|;|:)'
scope: punctuation.zig