|
| 1 | +%YAML 1.2 |
| 2 | +--- |
| 3 | +# http://www.sublimetext.com/docs/syntax.html |
| 4 | +name: WGSL |
| 5 | +file_extensions: |
| 6 | + - wgsl |
| 7 | +scope: source.wgsl |
| 8 | +contexts: |
| 9 | + main: |
| 10 | + - include: line_comments |
| 11 | + - include: block_comments |
| 12 | + - include: keywords |
| 13 | + - include: attributes |
| 14 | + - include: functions |
| 15 | + - include: function_calls |
| 16 | + - include: constants |
| 17 | + - include: types |
| 18 | + - include: variables |
| 19 | + - include: punctuation |
| 20 | + attributes: |
| 21 | + - match: '(@)([A-Za-z_]+)' |
| 22 | + comment: attribute declaration |
| 23 | + scope: meta.attribute.wgsl |
| 24 | + captures: |
| 25 | + 1: keyword.operator.attribute.at |
| 26 | + 2: entity.name.attribute.wgsl |
| 27 | + block_comments: |
| 28 | + - match: /\*\*/ |
| 29 | + comment: empty block comments |
| 30 | + scope: comment.block.wgsl |
| 31 | + - match: /\*\* |
| 32 | + comment: block documentation comments |
| 33 | + push: |
| 34 | + - meta_scope: comment.block.documentation.wgsl |
| 35 | + - match: \*/ |
| 36 | + pop: true |
| 37 | + - include: block_comments |
| 38 | + - match: /\*(?!\*) |
| 39 | + comment: block comments |
| 40 | + push: |
| 41 | + - meta_scope: comment.block.wgsl |
| 42 | + - match: \*/ |
| 43 | + pop: true |
| 44 | + - include: block_comments |
| 45 | + constants: |
| 46 | + - match: '(-?\b[0-9][0-9]*\.[0-9][0-9]*)([eE][+-]?[0-9]+)?\b' |
| 47 | + comment: decimal float literal |
| 48 | + scope: constant.numeric.float.wgsl |
| 49 | + - match: '-?\b0x[0-9a-fA-F]+\b|\b0\b|-?\b[1-9][0-9]*\b' |
| 50 | + comment: int literal |
| 51 | + scope: constant.numeric.decimal.wgsl |
| 52 | + - match: '\b0x[0-9a-fA-F]+u\b|\b0u\b|\b[1-9][0-9]*u\b' |
| 53 | + comment: uint literal |
| 54 | + scope: constant.numeric.decimal.wgsl |
| 55 | + - match: \b(true|false)\b |
| 56 | + comment: boolean constant |
| 57 | + scope: constant.language.boolean.wgsl |
| 58 | + function_calls: |
| 59 | + - match: '([A-Za-z0-9_]+)(\()' |
| 60 | + comment: function/method calls |
| 61 | + captures: |
| 62 | + 1: entity.name.function.wgsl |
| 63 | + 2: punctuation.brackets.round.wgsl |
| 64 | + push: |
| 65 | + - meta_scope: meta.function.call.wgsl |
| 66 | + - match: \) |
| 67 | + captures: |
| 68 | + 0: punctuation.brackets.round.wgsl |
| 69 | + pop: true |
| 70 | + - include: line_comments |
| 71 | + - include: block_comments |
| 72 | + - include: keywords |
| 73 | + - include: attributes |
| 74 | + - include: function_calls |
| 75 | + - include: constants |
| 76 | + - include: types |
| 77 | + - include: variables |
| 78 | + - include: punctuation |
| 79 | + functions: |
| 80 | + - match: '\b(fn)\s+([A-Za-z0-9_]+)((\()|(<))' |
| 81 | + comment: function definition |
| 82 | + captures: |
| 83 | + 1: keyword.other.fn.wgsl |
| 84 | + 2: entity.name.function.wgsl |
| 85 | + 4: punctuation.brackets.round.wgsl |
| 86 | + push: |
| 87 | + - meta_scope: meta.function.definition.wgsl |
| 88 | + - match: '\{' |
| 89 | + captures: |
| 90 | + 0: punctuation.brackets.curly.wgsl |
| 91 | + pop: true |
| 92 | + - include: line_comments |
| 93 | + - include: block_comments |
| 94 | + - include: keywords |
| 95 | + - include: attributes |
| 96 | + - include: function_calls |
| 97 | + - include: constants |
| 98 | + - include: types |
| 99 | + - include: variables |
| 100 | + - include: punctuation |
| 101 | + keywords: |
| 102 | + - match: \b(bitcast|block|break|case|continue|continuing|default|discard|else|elseif|enable|fallthrough|for|function|if|loop|private|read|read_write|return|storage|switch|uniform|while|workgroup|write)\b |
| 103 | + comment: other keywords |
| 104 | + scope: keyword.control.wgsl |
| 105 | + - match: \b(asm|const|do|enum|handle|mat|premerge|regardless|typedef|unless|using|vec|void)\b |
| 106 | + comment: reserved keywords |
| 107 | + scope: keyword.control.wgsl |
| 108 | + - match: \b(let|var)\b |
| 109 | + comment: storage keywords |
| 110 | + scope: keyword.other.wgsl storage.type.wgsl |
| 111 | + - match: \b(type)\b |
| 112 | + comment: type keyword |
| 113 | + scope: keyword.declaration.type.wgsl storage.type.wgsl |
| 114 | + - match: \b(enum)\b |
| 115 | + comment: enum keyword |
| 116 | + scope: keyword.declaration.enum.wgsl storage.type.wgsl |
| 117 | + - match: \b(struct)\b |
| 118 | + comment: struct keyword |
| 119 | + scope: keyword.declaration.struct.wgsl storage.type.wgsl |
| 120 | + - match: \bfn\b |
| 121 | + comment: fn |
| 122 | + scope: keyword.other.fn.wgsl |
| 123 | + - match: (\^|\||\|\||&&|<<|>>|!)(?!=) |
| 124 | + comment: logical operators |
| 125 | + scope: keyword.operator.logical.wgsl |
| 126 | + - match: '&(?![&=])' |
| 127 | + comment: logical AND, borrow references |
| 128 | + scope: keyword.operator.borrow.and.wgsl |
| 129 | + - match: (\+=|-=|\*=|/=|%=|\^=|&=|\|=|<<=|>>=) |
| 130 | + comment: assignment operators |
| 131 | + scope: keyword.operator.assignment.wgsl |
| 132 | + - match: '(?<![<>])=(?!=|>)' |
| 133 | + comment: single equal |
| 134 | + scope: keyword.operator.assignment.equal.wgsl |
| 135 | + - match: (=(=)?(?!>)|!=|<=|(?<!=)>=) |
| 136 | + comment: comparison operators |
| 137 | + scope: keyword.operator.comparison.wgsl |
| 138 | + - match: '(([+%]|(\*(?!\w)))(?!=))|(-(?!>))|(/(?!/))' |
| 139 | + comment: math operators |
| 140 | + scope: keyword.operator.math.wgsl |
| 141 | + - match: \.(?!\.) |
| 142 | + comment: dot access |
| 143 | + scope: keyword.operator.access.dot.wgsl |
| 144 | + - match: '->' |
| 145 | + comment: dashrocket, skinny arrow |
| 146 | + scope: keyword.operator.arrow.skinny.wgsl |
| 147 | + line_comments: |
| 148 | + - match: \s*//.* |
| 149 | + comment: single line comment |
| 150 | + scope: comment.line.double-slash.wgsl |
| 151 | + punctuation: |
| 152 | + - match: ',' |
| 153 | + comment: comma |
| 154 | + scope: punctuation.comma.wgsl |
| 155 | + - match: '[{}]' |
| 156 | + comment: curly braces |
| 157 | + scope: punctuation.brackets.curly.wgsl |
| 158 | + - match: '[()]' |
| 159 | + comment: parentheses, round brackets |
| 160 | + scope: punctuation.brackets.round.wgsl |
| 161 | + - match: ; |
| 162 | + comment: semicolon |
| 163 | + scope: punctuation.semi.wgsl |
| 164 | + - match: '[\[\]]' |
| 165 | + comment: square brackets |
| 166 | + scope: punctuation.brackets.square.wgsl |
| 167 | + - match: '(?<![=-])[<>]' |
| 168 | + comment: angle brackets |
| 169 | + scope: punctuation.brackets.angle.wgsl |
| 170 | + types: |
| 171 | + - match: \b(bool|i32|u32|f32)\b |
| 172 | + comment: scalar Types |
| 173 | + scope: storage.type.wgsl |
| 174 | + - match: \b(i64|u64|f64)\b |
| 175 | + comment: reserved scalar Types |
| 176 | + scope: storage.type.wgsl |
| 177 | + - match: \b(vec2i|vec3i|vec4i|vec2u|vec3u|vec4u|vec2f|vec3f|vec4f|vec2h|vec3h|vec4h)\b |
| 178 | + comment: vector type aliasses |
| 179 | + scope: storage.type.wgsl |
| 180 | + - match: \b(mat2x2f|mat2x3f|mat2x4f|mat3x2f|mat3x3f|mat3x4f|mat4x2f|mat4x3f|mat4x4f|mat2x2h|mat2x3h|mat2x4h|mat3x2h|mat3x3h|mat3x4h|mat4x2h|mat4x3h|mat4x4h)\b |
| 181 | + comment: matrix type aliasses |
| 182 | + scope: storage.type.wgsl |
| 183 | + - match: '\b(vec[2-4]|mat[2-4]x[2-4])\b' |
| 184 | + comment: vector/matrix types |
| 185 | + scope: storage.type.wgsl |
| 186 | + - match: \b(atomic)\b |
| 187 | + comment: atomic types |
| 188 | + scope: storage.type.wgsl |
| 189 | + - match: \b(array)\b |
| 190 | + comment: array types |
| 191 | + scope: storage.type.wgsl |
| 192 | + - match: '\b([A-Z][A-Za-z0-9]*)\b' |
| 193 | + comment: Custom type |
| 194 | + scope: entity.name.type.wgsl |
| 195 | + variables: |
| 196 | + - match: '\b(?<!(?<!\.)\.)(?:r#(?!(crate|[Ss]elf|super)))?[a-z0-9_]+\b' |
| 197 | + comment: variables |
| 198 | + scope: variable.other.wgsl |
0 commit comments