Skip to content

Instantly share code, notes, and snippets.

@LizzyFleckenstein03
Created February 25, 2023 17:04
Show Gist options
  • Save LizzyFleckenstein03/0bac0be94ad67f6032ea586dbffc02b0 to your computer and use it in GitHub Desktop.
Save LizzyFleckenstein03/0bac0be94ad67f6032ea586dbffc02b0 to your computer and use it in GitHub Desktop.
Micro Syntax file for WGSL
wgsl
\.wgsl$
filetype: wgsl
detect:
filename: "\\.wgsl$"
rules:
# custom functions
- identifier: "fn [a-z0-9_]+"
# builtin functions
- identifier: "\\b(all|all|any|any|select|select|arrayLength|abs|acos|acosh|asin|asinh|atan|atanh|atan2|ceil|clamp|cos|cosh|countLeadingZeros|countOneBits|countTrailingZeros|cross|degrees|determinant|distance|dot|exp|exp2|extractBits|extractBits|faceForward|firstLeadingBit|firstLeadingBit|firstTrailingBit|floor|fma|fract|frexp|frexp|frexp|frexp|frexp|frexp|insertBits|inverseSqrt|ldexp|length|log|log2|max|min|mix|mix|modf|modf|modf|modf|modf|modf|normalize|pow|quantizeToF16|radians|reflect|refract|reverseBits|round|saturate|sign|sin|sinh|smoothstep|sqrt|step|tan|tanh|transpose|trunc|dpdx|dpdxCoarse|dpdxFine|dpdy|dpdyCoarse|dpdyFine|fwidth|fwidthCoarse|fwidthFine|textureDimensions|textureDimensions|textureDimensions|textureDimensions|textureDimensions|textureDimensions|textureGather|textureGather|textureGather|textureGather|textureGather|textureGather|textureGather|textureGather|textureGather|textureGather|textureGather|textureGather|gather_x_components|gather_y_components|gather_z_components|gather_depth_components|textureGatherCompare|textureGatherCompare|textureGatherCompare|textureGatherCompare|textureGatherCompare|textureGatherCompare|gather_depth_compare|textureLoad|textureLoad|textureLoad|textureLoad|textureLoad|textureLoad|textureLoad|textureLoad|textureLoad|textureNumLayers|textureNumLevels|textureNumSamples|textureSample|textureSample|textureSample|textureSample|textureSample|textureSample|textureSample|textureSample|textureSample|textureSample|textureSample|textureSample|textureSample|textureSample|textureSampleBias|textureSampleBias|textureSampleBias|textureSampleBias|textureSampleBias|textureSampleBias|textureSampleBias|textureSampleCompare|textureSampleCompare|textureSampleCompare|textureSampleCompare|textureSampleCompare|textureSampleCompare|textureSampleCompareLevel|textureSampleCompareLevel|textureSampleCompareLevel|textureSampleCompareLevel|textureSampleCompareLevel|textureSampleCompareLevel|textureSampleGrad|textureSampleGrad|textureSampleGrad|textureSampleGrad|textureSampleGrad|textureSampleGrad|textureSampleGrad|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleLevel|textureSampleBaseClampToEdge|textureStore|textureStore|textureStore|textureStore|atomicLoad|atomicStore|atomicAdd|atomicSub|atomicMax|atomicMin|atomicAnd|atomicOr|atomicXor|atomicExchange|atomicCompareExchangeWeak|pack4x8snorm|pack4x8unorm|pack2x16snorm|pack2x16unorm|pack2x16float|unpack4x8snorm|unpack4x8unorm|unpack2x16snorm|unpack2x16unorm|unpack2x16float|storageBarrier|workgroupBarrier|workgroupUniformLoad)\\b"
# keywords
- statement: "\\b(alias|bitcast|break|case|const|const_assert|continue|continuing|default|discard|else|enable|fn|for|if|let|loop|override|return|struct|switch|var|while)\\b"
# reserved words
- statement: "\\b(Hullshader|NULL|Self|abstract|active|alignas|alignof|as|asm|asm_fragment|async|attribute|auto|await|become|binding_array|cast|catch|class|co_await|co_return|co_yield|coherent|column_major|common|compile|compile_fragment|concept|const_cast|consteval|constexpr|constinit|crate|debugger|decltype|delete|demote|demote_to_helper|do|dynamic_cast|enum|explicit|export|extends|extern|external|fallthrough|filter|final|finally|friend|from|fxgroup|get|goto|groupshared|highp|impl|implements|import|inline|instanceof|interface|layout|lowp|macro|macro_rules|match|mediump|meta|mod|module|move|mut|mutable|namespace|new|nil|noexcept|noinline|nointerpolation|noperspective|null|nullptr|of|operator|package|packoffset|partition|pass|patch|pixelfragment|precise|precision|premerge|priv|protected|pub|public|readonly|ref|regardless|register|reinterpret_cast|requires|resource|restrict|self|set|shared|sizeof|smooth|snorm|static|static_assert|static_cast|std|subroutine|super|target|template|this|thread_local|throw|trait|try|type|typedef|typeid|typename|typeof|union|unless|unorm|unsafe|unsized|use|using|varying|virtual|volatile|wgsl|where|with|writeonly|yield)\\b"
# constants
- constant: "\\b(read|write|read_write|private|workgroup|uniform|storage|perspective|linear|flat|center|centroid|sample|vertex_index|instance_index|position|front_facing|frag_depth|local_invocation_id|local_invocation_index|global_invocation_id|workgroup_id|num_workgroups|sample_index|sample_mask|rgba8unorm|rgba8snorm|rgba8uint|rgba8sint|rgba16uint|rgba16sint|rgba16float|r32uint|r32sint|r32float|rg32uint|rg32sint|rg32float|rgba32uint|rgba32sint|rgba32float|bgra8unorm)\\b"
- constant.bool: "\\b(true|false)\\b"
- constant.number: "\\b([0-9]+|0x[0-9a-fA-F]*)\\b"
# operators
- symbol.operator: "[<>\\[\\]\\(\\){}&@:,=!%|\\+\\-;*~^]"
# attributes
#- special: "@\\b(align|binding|builtin|compute|const|fragment|group|id|interpolate|invariant|location|must_use|size|vertex|workgroup_size)\\b"
- special: "@[a-z_]+"
# builtin types
- type: "\\b(bool|f16|f32|i32|u32)\\b"
- type: "\\b(array|atomic|ptr)\\b"
- type: "\\b(sampler|sampler_comparison)\\b"
- type: "\\b(texture_depth_2d|texture_depth_2d_array|texture_depth_cube|texture_depth_cube_array|texture_depth_multisampled_2d|texture_external|texture_1d|texture_2d|texture_2d_array|texture_3d|texture_cube|texture_cube_array|texture_multisampled_2d|texture_storage_1d|texture_storage_2d|texture_storage_2d_array|texture_storage_3d)\\b"
- type: "\\b(vec(2|3|4)(i|u|f|h)?)\\b"
- type: "\\b(mat(2|3|4)x(2|3|4)(f|h)?)\\b"
# custom types
- type: "\\b[A-Z]+[a-zA-Z_0-9]*[a-z]+[a-zA-Z_0-9]*\\b"
# line comments
- comment:
start: "//"
end: "$"
rules:
- todo: "(TODO|XXX|FIXME):?"
# block comments
- comment:
start: "/\\*"
end: "\\*/"
rules:
- todo: "(TODO|XXX|FIXME):?"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment