Skip to content

Commit 422f27a

Browse files
committed
Add support for WGSL
1 parent 69c326f commit 422f27a

File tree

10 files changed

+249
-0
lines changed

10 files changed

+249
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,6 @@
257257
[submodule "assets/syntaxes/02_Extra/NSIS"]
258258
path = assets/syntaxes/02_Extra/NSIS
259259
url = https://github.com/SublimeText/NSIS
260+
[submodule "assets/syntaxes/02_Extra/vscode-wgsl"]
261+
path = assets/syntaxes/02_Extra/vscode-wgsl
262+
url = https://github.com/PolyMeilex/vscode-wgsl.git

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- Replaced quotes with double quotes so fzf integration example script works on windows and linux. see #2095 (@johnmatthiggins)
2323
- Associate `ksh` files with `bash` syntax, see #2633 (@johnmatthiggins)
2424
- Associate `ron` files with `rust` syntax, see #2427 (@YeungOnion)
25+
- Add support for [WebGPU Shader Language](https://www.w3.org/TR/WGSL/), see #2692 (@rhysd)
2526

2627
## Themes
2728

assets/acknowledgements.bin

-28 Bytes
Binary file not shown.

assets/syntaxes.bin

11.7 KB
Binary file not shown.
Submodule vscode-wgsl added at acf2671
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
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

doc/assets.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ The following files have been manually modified after converting from a `.tmLang
8484
* `Org mode.sublime-syntax` => removed `task` file type.
8585
* `Robot.sublime_syntax` => changed name to "Robot Framework", added `.resource` extension.
8686
* `SML.sublime_syntax` => removed `ml` file type.
87+
* `wgsl.sublime-syntax` => added `wgsl` file extension.
8788
8889
### Non-submodule additions
8990
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
struct VertexOut {
2+
 @builtin(position) position : vec4f,
3+
 @location(0) color : vec4f
4+
}
5+
6+
@vertex
7+
fn vertex_main(@location(0) position: vec4f,
8+
 @location(1) color: vec4f) -> VertexOut
9+
{
10+
 var output : VertexOut;
11+
 output.position = position;
12+
 output.color = color;
13+
 return output;
14+
}
15+
16+
@fragment
17+
fn fragment_main(fragData: VertexOut) -> @location(0) vec4f
18+
{
19+
 return fragData.color;
20+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The `test.wgsl` file has been added from https://developer.mozilla.org/en-US/docs/Web/API/WebGPU_API under the following license:
2+
3+
```
4+
Any copyright is dedicated to the Public Domain: https://creativecommons.org/publicdomain/zero/1.0/
5+
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
struct VertexOut {
2+
@builtin(position) position : vec4f,
3+
@location(0) color : vec4f
4+
}
5+
6+
@vertex
7+
fn vertex_main(@location(0) position: vec4f,
8+
@location(1) color: vec4f) -> VertexOut
9+
{
10+
var output : VertexOut;
11+
output.position = position;
12+
output.color = color;
13+
return output;
14+
}
15+
16+
@fragment
17+
fn fragment_main(fragData: VertexOut) -> @location(0) vec4f
18+
{
19+
return fragData.color;
20+
}

0 commit comments

Comments
 (0)