|
| 1 | +Prism.languages.wgsl = { |
| 2 | + 'comment': { |
| 3 | + pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/, |
| 4 | + greedy: true, |
| 5 | + }, |
| 6 | + 'builtin-attribute': { |
| 7 | + pattern: /(@)builtin\(.*?\)/, |
| 8 | + lookbehind: true, |
| 9 | + inside: { |
| 10 | + 'attribute': { |
| 11 | + pattern: /^builtin/, |
| 12 | + alias: 'attr-name', |
| 13 | + }, |
| 14 | + 'punctuation': /[(),]/, |
| 15 | + 'built-in-values': { |
| 16 | + pattern: /\b(?:frag_depth|front_facing|global_invocation_id|instance_index|local_invocation_id|local_invocation_index|num_workgroups|position|sample_index|sample_mask|vertex_index|workgroup_id)\b/, |
| 17 | + alias: 'attr-value', |
| 18 | + }, |
| 19 | + }, |
| 20 | + }, |
| 21 | + 'attributes': { |
| 22 | + pattern: /(@)(?:align|binding|compute|const|fragment|group|id|interpolate|invariant|location|size|vertex|workgroup_size)/i, |
| 23 | + lookbehind: true, |
| 24 | + alias: 'attr-name', |
| 25 | + }, |
| 26 | + 'functions': { |
| 27 | + pattern: /\b(fn\s+)[_a-zA-Z]\w*(?=[(<])/, |
| 28 | + lookbehind: true, |
| 29 | + alias: 'function', |
| 30 | + }, |
| 31 | + 'keyword': /\b(?:bitcast|break|case|const|continue|continuing|default|discard|else|enable|fallthrough|fn|for|function|if|let|loop|private|return|storage|struct|switch|type|uniform|var|while|workgroup)\b/, |
| 32 | + 'builtin': /\b(?:abs|acos|acosh|all|any|array|asin|asinh|atan|atan2|atanh|atomic|atomicAdd|atomicAnd|atomicCompareExchangeWeak|atomicExchange|atomicLoad|atomicMax|atomicMin|atomicOr|atomicStore|atomicSub|atomicXor|bool|ceil|clamp|cos|cosh|countLeadingZeros|countOneBits|countTrailingZeros|cross|degrees|determinant|distance|dot|dpdx|dpdxCoarse|dpdxFine|dpdy|dpdyCoarse|dpdyFine|exp|exp2|extractBits|f32|f64|faceForward|firstLeadingBit|floor|fma|fract|frexp|fwidth|fwidthCoarse|fwidthFine|i32|i64|insertBits|inverseSqrt|ldexp|length|log|log2|mat[2-4]x[2-4]|max|min|mix|modf|normalize|override|pack2x16float|pack2x16snorm|pack2x16unorm|pack4x8snorm|pack4x8unorm|pow|ptr|quantizeToF16|radians|reflect|refract|reverseBits|round|sampler|sampler_comparison|select|shiftLeft|shiftRight|sign|sin|sinh|smoothstep|sqrt|staticAssert|step|storageBarrier|tan|tanh|textureDimensions|textureGather|textureGatherCompare|textureLoad|textureNumLayers|textureNumLevels|textureNumSamples|textureSample|textureSampleBias|textureSampleCompare|textureSampleCompareLevel|textureSampleGrad|textureSampleLevel|textureStore|texture_1d|texture_2d|texture_2d_array|texture_3d|texture_cube|texture_cube_array|texture_depth_2d|texture_depth_2d_array|texture_depth_cube|texture_depth_cube_array|texture_depth_multisampled_2d|texture_multisampled_2d|texture_storage_1d|texture_storage_2d|texture_storage_2d_array|texture_storage_3d|transpose|trunc|u32|u64|unpack2x16float|unpack2x16snorm|unpack2x16unorm|unpack4x8snorm|unpack4x8unorm|vec[2-4]|workgroupBarrier)\b/, |
| 33 | + 'function-calls': { |
| 34 | + pattern: /\b[_a-z]\w*(?=\()/i, |
| 35 | + alias: 'function', |
| 36 | + }, |
| 37 | + 'class-name': /\b(?:[A-Z][A-Za-z0-9]*)\b/, |
| 38 | + 'bool-literal': { |
| 39 | + pattern: /\b(?:false|true)\b/, |
| 40 | + alias: 'boolean', |
| 41 | + }, |
| 42 | + 'hex-int-literal': { |
| 43 | + pattern: /\b0[xX][0-9a-fA-F]+[iu]?\b(?![.pP])/, |
| 44 | + alias: 'number', |
| 45 | + }, |
| 46 | + 'hex-float-literal': { |
| 47 | + pattern: /\b0[xX][0-9a-fA-F]*(?:\.[0-9a-fA-F]*)?(?:[pP][+-]?\d+[fh]?)?/, alias: 'number' |
| 48 | + }, |
| 49 | + 'decimal-float-literal': [ |
| 50 | + { pattern: /\d*\.\d+(?:[eE](?:\+|-)?\d+)?[fh]?/, alias: 'number' }, |
| 51 | + { pattern: /\d+\.\d*(?:[eE](?:\+|-)?\d+)?[fh]?/, alias: 'number' }, |
| 52 | + { pattern: /\d+[eE](?:\+|-)?\d+[fh]?/, alias: 'number' }, |
| 53 | + { pattern: /\b\d+[fh]\b/, alias: 'number' }, |
| 54 | + ], |
| 55 | + 'int-literal': { |
| 56 | + pattern: /\b\d+[iu]?\b/, |
| 57 | + alias: 'number', |
| 58 | + }, |
| 59 | + 'operator': [ |
| 60 | + { pattern: /(?:\^|~|\|(?!\|)|\|\||&&|<<|>>|!)(?!=)/ }, |
| 61 | + { pattern: /&(?![&=])/ }, |
| 62 | + { pattern: /(?:\+=|-=|\*=|\/=|%=|\^=|&=|\|=|<<=|>>=)/ }, |
| 63 | + { pattern: /(^|[^<>=!])=(?![=>])/, lookbehind: true }, |
| 64 | + { pattern: /(?:==|!=|<=|\+\+|--|(^|[^=])>=)/, lookbehind: true }, |
| 65 | + { pattern: /(?:(?:[+%]|(?:\*(?!\w)))(?!=))|(?:-(?!>))|(?:\/(?!\/))/ }, |
| 66 | + { pattern: /->/ }, |
| 67 | + ], |
| 68 | + 'punctuation': /[@(){}[\],;<>:.]/, |
| 69 | +}; |
0 commit comments