-
-
Save flyx/d59c5cad0499aead823d578154d8154b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<syntax name="zig"> | |
<meta> | |
<name>zig</name> | |
<type>structured</type> | |
<preferred-file-extension>zig</preferred-file-extension> | |
</meta> | |
<detectors> | |
<extension priority="1.0">zig</extension> | |
</detectors> | |
<indentation> | |
<increase> | |
<expression>(\{[^}\"']*$)|(\[[^\]\"']*$)|(\([^)\"']*$)</expression> | |
</increase> | |
<decrease> | |
<expression>^\s*[\}\]\)\\]</expression> | |
</decrease> | |
</indentation> | |
<comments> | |
<single> | |
<expression>//</expression> | |
</single> | |
</comments> | |
<brackets> | |
<pair open="(" close=")" /> | |
<pair open="[" close="]" /> | |
<pair open="{" close="}" /> | |
</brackets> | |
<surrounding-pairs> | |
<pair open=""" close=""" /> | |
<pair open="'" close="'" /> | |
</surrounding-pairs> | |
<scopes> | |
<include syntax="self" collection="global-var-decl"/> | |
<include syntax="self" collection="non-var-container-content"/> | |
</scopes> | |
<collections> | |
<collection name="non-var-container-content"> | |
<include syntax="self" collection="named-type-decl"/> | |
<include syntax="self" collection="fn-decl"/> | |
<scope name="zig.test-decl"> | |
<symbol type="block" scope="local" anonymous="true"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>\b(test)[\s\n]+("([^"\n]|\\.)*["\n])?[\s\n]*\{</expression> | |
<capture number="1" name="zig.keyword.construct"/> | |
<capture number="2" name="zig.string.key.name"/> | |
</starts-with> | |
<ends-with> | |
<expression>\}</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="statements" optional="true" repeat="true"/> | |
</subscopes> | |
</scope> | |
<include syntax="self" collection="comment"/> | |
</collection> | |
<collection name="comment"> | |
<scope name="zig.comment" spell-check="true"> | |
<expression>//[^\n]*(\n[\s\n]*//[^\n]*)*</expression> | |
</scope> | |
</collection> | |
<collection name="field-decl"> | |
<scope name="zig.field-decl"> | |
<symbol type="property" scope="global"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>([a-zA-Z_][0-9a-zA-Z_]*)[\s\n]*(?=[:=])</expression> | |
<capture number="0" name="zig.identifier.property"/> | |
<capture number="1" name="name"/> | |
</starts-with> | |
<ends-with>,</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="explicit-type" optional="true"/> | |
<include syntax="self" collection="assignment" optional="true"/> | |
<cut-off> | |
<expression>(?=[\};])</expression> | |
</cut-off> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="named-type-decl"> | |
<scope name="zig.named-type-decl"> | |
<symbol type="struct" scope="global"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>\b(const)[\s\n]+([a-zA-Z_][0-9a-zA-Z_]*(?=[\s\n])|@"([^"\\]|\\.)*")[\s\n]*=[\s\n]*(?=(struct|opaque)[\s\n]*\{)</expression> | |
<capture number="1" name="zig.keyword.construct"/> | |
<capture number="2" name="zig.identifier.type.name"/> | |
</starts-with> | |
<ends-with> | |
<expression>;</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="type-decl"/> | |
</subscopes> | |
</scope> | |
<scope name="zig.type-decl"> | |
<symbol type="enum" scope="global"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>\b(const)[\s\n]+([a-zA-Z_][0-9a-zA-Z_]*(?=[\s\n])|@"([^"\\]|\\.)*")[\s\n]*=[\s\n]*(?=enum[\s\n]*\{)</expression> | |
<capture number="1" name="zig.keyword.construct"/> | |
<capture number="2" name="zig.identifier.type.name"/> | |
</starts-with> | |
<ends-with> | |
<expression>;</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="type-decl"/> | |
</subscopes> | |
</scope> | |
<scope name="zig.type-decl"> | |
<symbol type="union" scope="global"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>\b(const)[\s\n]+([a-zA-Z_][0-9a-zA-Z_]*(?=[\s\n])|@"([^"\\]|\\.)*")[\s\n]*=[\s\n]*(?=union[\s\n]*\{)</expression> | |
<capture number="1" name="zig.keyword.construct"/> | |
<capture number="2" name="zig.identifier.type.name"/> | |
</starts-with> | |
<ends-with> | |
<expression>;</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="type-decl"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="var-decl"> | |
<scope name="zig.const-decl"> | |
<symbol type="constant" scope="local"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>\bconst\b</expression> | |
<capture number="0" name="zig.keyword.construct"/> | |
</starts-with> | |
<ends-with> | |
<expression>;</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<scope name="zig.identifier.constant.name"> | |
<starts-with> | |
<expression>(?=[a-zA-Z_]|@)</expression> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="identifier"/> | |
</subscopes> | |
</scope> | |
<include syntax="self" collection="explicit-type" optional="true"/> | |
<include syntax="self" collection="assignment" optional="true"/> | |
</subscopes> | |
</scope> | |
<scope name="zig.var-decl"> | |
<symbol type="variable" scope="local"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>\bvar\b</expression> | |
<capture number="0" name="zig.keyword.construct"/> | |
</starts-with> | |
<ends-with> | |
<expression>;</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<scope name="zig.identifier.variable.name"> | |
<starts-with> | |
<expression>(?=[a-zA-Z_]|@)</expression> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="identifier"/> | |
</subscopes> | |
</scope> | |
<include syntax="self" collection="explicit-type" optional="true"/> | |
<include syntax="self" collection="assignment" optional="true"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="global-var-decl"> | |
<scope name="zig.const-decl"> | |
<symbol type="constant" scope="global"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>\bconst[\s\n]+</expression> | |
<capture number="0" name="zig.keyword.construct"/> | |
</starts-with> | |
<ends-with> | |
<expression>;</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<scope name="zig.identifier.constant.name"> | |
<starts-with> | |
<expression>(?=[a-zA-Z_]|@)</expression> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="identifier"/> | |
</subscopes> | |
</scope> | |
<include syntax="self" collection="explicit-type" optional="true"/> | |
<include syntax="self" collection="assignment" optional="true"/> | |
</subscopes> | |
</scope> | |
<scope name="zig.var-decl"> | |
<symbol type="variable" scope="global"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>\bvar[\s\n]+</expression> | |
<capture number="0" name="zig.keyword.construct"/> | |
</starts-with> | |
<ends-with> | |
<expression>;</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<scope name="zig.identifier.variable.name"> | |
<starts-with> | |
<expression>(?=[a-zA-Z_]|@)</expression> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="identifier"/> | |
</subscopes> | |
</scope> | |
<include syntax="self" collection="explicit-type" optional="true"/> | |
<include syntax="self" collection="assignment" optional="true"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="identifier"> | |
<scope name="zig.identifier"> | |
<expression>[a-zA-Z_][0-9a-zA-Z_]*</expression> | |
</scope> | |
<scope name="zig.identifier"> | |
<starts-with> | |
<expression>@"</expression> | |
</starts-with> | |
<ends-with> | |
<expression>"</expression> | |
</ends-with> | |
<subscopes> | |
<scope name="zig.value.entity"> | |
<expression>\\(x[0-9a-fA-F][0-9a-fA-F]|u\{[0-9a-fA-F]+\}|[nr\\t'"])</expression> | |
</scope> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="assignment"> | |
<scope name="zig.assignment"> | |
<starts-with> | |
<expression>=</expression> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="complex-expression"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="explicit-type"> | |
<scope name="zig.explicit-type"> | |
<starts-with> | |
<expression>:</expression> | |
</starts-with> | |
<ends-with> | |
<expression>(?=[=,;])</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="complex-expression"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="statements"> | |
<include syntax="self" collection="var-decl"/> | |
<scope name="zig.statement"> | |
<starts-with> | |
<expression>(?![\s\n\};])(?!\b(const|var)\b)</expression> | |
</starts-with> | |
<ends-with>;</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="complex-expression"/> | |
<cut-off> | |
<expression>(?=\})</expression> | |
</cut-off> | |
</subscopes> | |
</scope> | |
<include syntax="self" name="comment"/> | |
</collection> | |
<collection name="complex-expression"> | |
<scope name="zig.complex-expression"> | |
<starts-with> | |
<expression>(?=\.\{|[A-Za-z0-9@"\\])</expression> <!-- TODO: could be empty (?) --> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="non-infix-expression"/> | |
<include syntax="self" collection="expr-continuation" optional="true" repeat="true"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="non-infix-expression"> | |
<scope name="zig.anonymous-literal"> | |
<starts-with> | |
<expression>\.\{</expression> | |
</starts-with> | |
<ends-with> | |
<expression>\}</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="init-item" optional="true" repeat="true"/> | |
</subscopes> | |
</scope> | |
<scope name="zig.non-infix-expression"> | |
<starts-with> | |
<expression>(?=[A-Za-z0-9@"\\])</expression> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="modifier" optional="true" repeat="true"/> | |
<include syntax="self" collection="simple-expression"/> | |
<!--<scope name="init-suffix" optional="true"> | |
<starts-with> | |
<expression>\{</expression> | |
</starts-with> | |
<ends-with> | |
<expression>\}</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="init-item" optional="true" repeat="true"/> | |
</subscopes> | |
</scope>--> | |
<!--<include syntax="self" collection="modifier" optional="true" repeat="true"/>--> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="init-item"> | |
<scope name="zig.init-item"> | |
<starts-with> | |
<expression>\.\{</expression> | |
</starts-with> | |
<ends-with> | |
<expression>,?</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="identifier"/> | |
<scope name="zig.operator.equals"> | |
<expression>=</expression> | |
</scope> | |
<include syntax="self" collection="complex-expression"/> | |
</subscopes> | |
</scope> | |
<!--<scope name="zig.invalid"> | |
<expression>[^,\}]+</expression> | |
</scope>--> | |
</collection> | |
<!-- TODO: proper syntax for each of those --> | |
<collection name="modifier"> | |
<scope name="zig.keyword.modifier"> | |
<strings> | |
<string>align</string> | |
<string>allowzero</string> | |
<string>async</string> | |
<string>comptime</string> | |
<string>packed</string> | |
<string>pub</string> | |
<string>callconv</string> | |
<string>export</string> | |
<string>extern</string> | |
<string>inline</string> | |
<string>noalias</string> | |
<string>nosuspend</string> | |
<string>noinline</string> | |
<string>linksection</string> | |
<string>threadlocal</string> | |
<string>volatile</string> | |
</strings> | |
</scope> | |
</collection> | |
<collection name="expr-continuation"> | |
<scope name="zig.continue-with-keyword"> | |
<starts-with> | |
<expression>\b(and|or|orelse|catch)\b</expression> | |
<capture number="1" name="zig.keyword.operator"/> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="non-infix-expression"/> | |
</subscopes> | |
</scope> | |
<scope name="zig.continue-with-operator"> | |
<starts-with> | |
<expression>\+\+|\|\||\*\*|!=|([\*\+\-]%?|[/%&^|=]|<<?|>>?)=?</expression> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="non-infix-expression"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="simple-expression"> | |
<scope name="zig.string"> | |
<starts-with> | |
<expression>"</expression> | |
</starts-with> | |
<ends-with> | |
<expression>["\n]</expression> | |
</ends-with> | |
<subscopes> | |
<scope name="zig.value.entity"> | |
<expression>\\(x[0-9a-fA-F][0-9a-fA-F]|u\{[0-9a-fA-F]+\}|[nr\\t'"])</expression> | |
</scope> | |
</subscopes> | |
</scope> | |
<scope name="zig.string"> | |
<starts-with> | |
<expression>\\\\</expression> | |
</starts-with> | |
<ends-with> | |
<expression>\n</expression> | |
</ends-with> | |
</scope> | |
<include syntax="self" collection="type-decl"/> | |
<scope name="zig.keyword.condition"> | |
<strings> | |
<string>else</string> | |
<string>for</string> | |
<string>if</string> | |
<string>orelse</string> | |
<string>switch</string> | |
<string>try</string> | |
<string>while</string> | |
</strings> | |
</scope> | |
<scope name="zig.keyword.statement"> | |
<strings> | |
<string>await</string> | |
<string>break</string> | |
<string>continue</string> | |
<string>defer</string> | |
<string>errdefer</string> | |
<string>return</string> | |
<string>resume</string> | |
<string>suspend</string> | |
<string>usingnamespace</string> | |
</strings> | |
</scope> | |
<scope name="zig.value.boolean"> | |
<strings> | |
<string>false</string> | |
<string>true</string> | |
</strings> | |
</scope> | |
<scope name="zig.value.null"> | |
<strings> | |
<string>null</string> | |
<string>undefined</string> | |
<string>unreachable</string> | |
</strings> | |
</scope> | |
<scope name="zig.identifier.core.type"> | |
<strings> | |
<string>anyframe</string> | |
<string>anytype</string> | |
<string>bool</string> | |
</strings> | |
</scope> | |
<scope name="zig.identifier.core.type"> | |
<expression>[iu][0-9]+</expression> | |
</scope> | |
<include syntax="self" collection="identifier"/> | |
</collection> | |
<collection name="type-decl"> | |
<scope name="zig.type-decl"> | |
<starts-with> | |
<expression>\b(enum|error|opaque|struct|union)[\s\n]*\{</expression> | |
<capture number="1" name="zig.keyword.construct"/> | |
</starts-with> | |
<ends-with> | |
<expression>\}</expression> | |
</ends-with> | |
<subscopes> | |
<include syntax="self" collection="field-decl"/> | |
<include syntax="self" collection="var-decl"/> | |
<include syntax="self" collection="non-var-container-content"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="fn-decl"> | |
<scope name="fn-decl"> | |
<symbol type="function" scope="global"> | |
<context behavior="subtree"/> | |
</symbol> | |
<starts-with> | |
<expression>\b(fn)\b[\s\n]*([a-zA-Z_][0-9a-zA-Z_]*|@"([^"\\]|\\.)*")</expression> | |
<capture number="1" name="zig.keyword.construct"/> | |
<capture number="2" name="zig.identifier.function.name"/> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="fn-after-name"/> | |
<include syntax="self" collection="fn-suffix"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="fn-proto"> | |
<scope name="zig.fn-proto"> | |
<starts-with> | |
<expression>\bfn\b</expression> | |
<capture number="0" name="zig.keyword.construct"/> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<scope name="zig.identifier.function.name" optional="true"> | |
<starts-with> | |
<expression>(?=[a-zA-Z_@])</expression> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="identifier"/> | |
</subscopes> | |
</scope> | |
<include syntax="self" collection="fn-after-name"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="fn-after-name"> | |
<scope name="zig.fn-after-name"> | |
<starts-with> | |
<expression>\(</expression> | |
</starts-with> | |
<ends-with/> | |
<subscopes anchored="true"> | |
<scope name="zig.param-decl" optional="true" repeat="true"> | |
<starts-with> | |
<expression>[\s\n]*(?!\))</expression> | |
</starts-with> | |
<ends-with> | |
<expression>,|(?=\))</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="comment" optional="true"/> | |
<scope name="zig.keyword.modifier" optional="true"> | |
<expression>\b(noalias|comptime)\b</expression> | |
</scope> | |
<scope name="zig.named-param" optional="true"> | |
<expression>([a-zA-Z_][0-9a-zA-Z_]*|@"([^"\\]|\\.)*")[\s\n]*:</expression> | |
<capture number="1" name="zig.identifier.argument.name"/> | |
</scope> | |
<include syntax="self" collection="complex-expression"/> | |
</subscopes> | |
</scope> | |
<scope name="zig.paren-close"> | |
<expression>\)</expression> | |
</scope> | |
<include syntax="self" collection="modifier" optional="true" repeat="true"/> | |
<scope name="zig.excl" optional="true"> | |
<expression>!</expression> | |
</scope> | |
<include syntax="self" collection="complex-expression"/> | |
</subscopes> | |
</scope> | |
</collection> | |
<collection name="fn-suffix"> | |
<scope name="fn-semi"> | |
<expression>;</expression> | |
</scope> | |
<scope name="fn-body"> | |
<starts-with> | |
<expression>\{</expression> | |
</starts-with> | |
<ends-with> | |
<expression>\}</expression> | |
</ends-with> | |
<subscopes anchored="true"> | |
<include syntax="self" collection="statements" optional="true" repeat="true"/> | |
</subscopes> | |
</scope> | |
</collection> | |
</collections> | |
</syntax> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment