Skip to content

Instantly share code, notes, and snippets.

@deingithub
Created October 4, 2019 17:08
Show Gist options
  • Save deingithub/f40e2f3b75a4daf471cd8847be14d966 to your computer and use it in GitHub Desktop.
Save deingithub/f40e2f3b75a4daf471cd8847be14d966 to your computer and use it in GitHub Desktop.
Zig Highlighting for GTKSourceView (gedit and a bunch of other GTK+ apps)
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Zig Syntax Highlighting for GTKSourceView components.
Author: deing <admin@15318.de>. This file is available under Creative Commons Zero.
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide.
This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
-->
<language id="zig" name="Zig" version="2.0" _section="Source">
<metadata>
<property name="globs">*.zig</property>
<property name="line-comment-start">//</property>
</metadata>
<styles>
<style id="keyword" name="Keyword" map-to="def:keyword" />
<style id="builtin-fn" name="Builtin Function" map-to="def:preprocessor" />
<style id="type" name="Type" map-to="def:type" />
<style id="escape-sequence" name="Escaped Character" map-to="def:special-char" />
<style id="comment" name="Comment" map-to="def:comment" />
<style id="boolean" name="Boolean value" map-to="def:boolean" />
<style id="string" name="String" map-to="def:string" />
<style id="number" name="Number" map-to="def:number" />
<style id="error" name="Error" map-to="def:error" />
</styles>
<definitions>
<!-- All Zig keywords as specified in the 0.5.0 PEG -->
<context id="keywords" style-ref="keyword">
<keyword>align</keyword>
<keyword>allowzero</keyword>
<keyword>and</keyword>
<keyword>asm</keyword>
<keyword>async</keyword>
<keyword>await</keyword>
<keyword>break</keyword>
<keyword>catch</keyword>
<keyword>comptime</keyword>
<keyword>const</keyword>
<keyword>continue</keyword>
<keyword>defer</keyword>
<keyword>else</keyword>
<keyword>enum</keyword>
<keyword>errdefer</keyword>
<keyword>error</keyword>
<keyword>export</keyword>
<keyword>extern</keyword>
<keyword>fn</keyword>
<keyword>for</keyword>
<keyword>if</keyword>
<keyword>inline</keyword>
<keyword>nakedcc</keyword>
<keyword>noalias</keyword>
<keyword>null</keyword>
<keyword>or</keyword>
<keyword>orelse</keyword>
<keyword>packed</keyword>
<keyword>promise</keyword>
<keyword>pub</keyword>
<keyword>resume</keyword>
<keyword>return</keyword>
<keyword>linksection</keyword>
<keyword>stdcallcc</keyword>
<keyword>struct</keyword>
<keyword>suspend</keyword>
<keyword>switch</keyword>
<keyword>test</keyword>
<keyword>threadlocal</keyword>
<keyword>try</keyword>
<keyword>undefined</keyword>
<keyword>union</keyword>
<keyword>unreachable</keyword>
<keyword>usingnamespace</keyword>
<keyword>var</keyword>
<keyword>volatile</keyword>
<keyword>while</keyword>
</context>
<define-regex id="identifier" extended="true">
[A-Za-z_][A-Za-z0-9_]*
</define-regex>
<define-regex id="hex-digit" extended="true">
[0-9a-fA-F]
</define-regex>
<define-regex id="arbitrary-integer-type" extended="true">
[ui][0-9]{1,5}
</define-regex>
<define-regex id="escape-sequence" extended="true">
\\([rnt'"\\]|u\{\%{hex-digit}+\}|x\%{hex-digit}{2})
</define-regex>
<context id="builtin-fn" style-ref="builtin-fn">
<match extended="true">
@\%{identifier}
</match>
</context>
<context id="boolean" style-ref="boolean">
<keyword>true</keyword>
<keyword>false</keyword>
</context>
<context id="type" style-ref="type">
<match extended="true">
\b(\%{arbitrary-integer-type}|isize|usize|f16|f32|f64|f128|bool|void|noreturn|type|anyerror|comptime_int|comptime_float|c_short|c_ushort|c_int|c_uint|c_long|c_ulong|c_longlong|c_ulonglong|c_longdouble|c_void)
</match>
</context>
<context id="escape-sequence" style-ref="escape-sequence">
<match extended="true">
\%{escape-sequence}
</match>
</context>
<context id="string" end-at-line-end="true" style-ref="string">
<start>c?"</start>
<end>"</end>
<include>
<context ref="escape-sequence" />
</include>
</context>
<context id="multiline-string" end-at-line-end="true" style-ref="string">
<start>c?\\\\</start>
<end>$</end>
<include>
<context ref="escape-sequence" />
</include>
</context>
<context id="char" end-at-line-end="true" style-ref="string">
<start>'</start>
<end>'</end>
<include>
<context ref="escape-sequence" />
</include>
</context>
<context id="integer" style-ref="number">
<match extended="true">
\b(0b[10]+|0o[0-7]+|0x\%{hex-digit}+|[0-9]+)
</match>
</context>
<context id="float" style-ref="number">
<match extended="true">
0x\%{hex-digit}+\.\%{hex-digit}+([pP][-+]?\%{hex-digit}+)?|[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?|0x\%{hex-digit}+\.?[pP][-+]?\%{hex-digit}+|[0-9]+\.?[eE][-+]?[0-9]+
</match>
</context>
<context id="zig" class="no-spell-check">
<include>
<context ref="keywords" />
<context ref="builtin-fn" />
<context ref="type" />
<context ref="boolean" />
<context ref="string" />
<context ref="multiline-string" />
<context ref="char" />
<context ref="float" />
<context ref="integer" />
<context ref="def:c-like-comment" style-ref="comment" />
</include>
</context>
</definitions>
</language>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment