Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for WGSL #3455

Merged
merged 31 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c0c8166
Added files for language WGSL
Dr4gonthree May 15, 2022
215cc01
Rebuild for WGSL
Dr4gonthree May 15, 2022
c180f22
Replaced Unicode patterns with ASCII versions
Dr4gonthree May 16, 2022
f878424
Removed empty insides
Dr4gonthree May 16, 2022
48e028b
Removed wrong use of variable token
Dr4gonthree May 16, 2022
9d08847
Simplified the punctuation pattern
Dr4gonthree May 16, 2022
6e88afa
Changed attribute alias from symbol to important
Dr4gonthree May 16, 2022
0f2ad3c
Replaced wrong usage of namespace token, and categorized built-in values
Dr4gonthree May 16, 2022
b5ea50f
Combined and updated keyword patterns
Dr4gonthree May 16, 2022
27dd0de
Combined builtin types and seperated class-names
Dr4gonthree May 16, 2022
97626d1
Collapsed keywords and built-in-values
Dr4gonthree May 16, 2022
3a3a5b6
Simplified number literals
Dr4gonthree May 16, 2022
e2994e2
Collapsed hex-int-literal
Dr4gonthree May 16, 2022
7ee4e6a
Replaced [0-9] with \d
Dr4gonthree May 16, 2022
1a740f2
Fixed: hex-float-literal matching in words, decimal-float-literal mat…
Dr4gonthree May 17, 2022
c89f102
Attributes now match only defined attributes, and alias changed to at…
Dr4gonthree May 17, 2022
8b54135
Updated test cases
Dr4gonthree May 17, 2022
3fec709
Rebuild
Dr4gonthree May 17, 2022
bcb8f4f
Match built-ins before function calls
Dr4gonthree May 17, 2022
0832006
Add missing function-calls test in function feature test
Dr4gonthree May 17, 2022
47a34c5
Move struct from builtins to keywords
Dr4gonthree May 17, 2022
60e4468
Added missing built-in functions
Dr4gonthree May 17, 2022
541976e
Treat '@', ':' and '.' and punctuation
Dr4gonthree May 17, 2022
5fc8a40
Add '++' and '--' operators
Dr4gonthree May 17, 2022
f804f5b
Updated test cases
Dr4gonthree May 17, 2022
732be46
Replace lookbehinds
Dr4gonthree May 17, 2022
0252621
Math built-in-values only in the 'builtin' attribute and update test …
Dr4gonthree May 17, 2022
e94b883
Renamed builtin_types_feature test to builtin_feature
Dr4gonthree May 17, 2022
e073914
Updated tests and rebuild
Dr4gonthree May 17, 2022
37d2592
Fix lint
Dr4gonthree May 18, 2022
8bb57f7
Moved the builtin attribute and built-in-values to helper token. Upda…
Dr4gonthree May 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,10 @@
"alias": "webidl",
"owner": "RunDevelopment"
},
"wgsl": {
"title": "WGSL",
"owner": "Dr4gonthree"
},
"wiki": {
"title": "Wiki markup",
"require": "markup",
Expand Down
94 changes: 94 additions & 0 deletions components/prism-wgsl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Prism.languages.wgsl = {
'comment': {
pattern: /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
greedy: true,
},
'attributes': {
pattern: /(@)(?:(?:[_\p{XID_Start}][\p{XID_Continue}]+)|(?:[\p{XID_Start}]))/u,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
lookbehind: true,
alias: 'symbol',
},
'functions': {
pattern: /\b(fn)\s+(?:(?:[_\p{XID_Start}][\p{XID_Continue}]+)|(?:[\p{XID_Start}]))(?=(?:\()|(?:<))/u,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
lookbehind: true,
alias: 'function',
inside: {},
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
},
'keyword': [
{ pattern: /\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|workgroup|write)\b/ },
{ pattern: /\b(?:asm|const|do|enum|handle|mat|premerge|regardless|typedef|unless|using|vec|void|while)\b/ },
{ pattern: /\b(?:let|var)\b/ },
{ pattern: /\b(?:type)\b/ },
{ pattern: /\b(?:enum)\b/ },
{ pattern: /\bfn\b/ },
],
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
'function-calls': {
pattern: /(?:(?:[_\p{XID_Start}][\p{XID_Continue}]+)|(?:[\p{XID_Start}]))(?=\()/u,
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
alias: 'function',
inside: {},
},
'types': [
{ pattern: /\b(?:bool|i32|u32|f32)\b/, alias: 'builtin' },
{ pattern: /\b(?:i64|u64|f64)\b/, alias: 'builtin' },
{ pattern: /\b(?:vec[2-4]|mat[2-4]x[2-4])\b/, alias: 'builtin' },
{ pattern: /\b(?:atomic)\b/, alias: 'builtin' },
{ pattern: /\b(?:array)\b/, alias: 'builtin' },
{ pattern: /\b(?:override|ptr|sampler|sampler_comparison|staticAssert|struct)\b/, alias: 'builtin' },
{ pattern: /\b(?:texture_1d|texture_2d|texture_2d_array|texture_3d|texture_cube|texture_cube_array|texture_multisampled_2d)\b/, alias: 'builtin' },
{ pattern: /\b(?:texture_storage_1d|texture_storage_2d|texture_storage_2d_array|texture_storage_3d|texture_depth_2d)\b/, alias: 'builtin' },
{ pattern: /\b(?:texture_depth_2d_array|texture_depth_cube|texture_depth_cube_array|texture_depth_multisampled_2d)\b/, alias: 'builtin' },
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
{ pattern: /\b(?:[A-Z][A-Za-z0-9]*)\b/, alias: 'class-name' },
],
'built-in-values': [
{ pattern: /\b(?:vertex_index|instance_index|position)\b/, alias: 'namespace' },
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
{ pattern: /\b(?:front_facing|frag_depth|sample_index|sample_mask)\b/, alias: 'namespace' },
{ pattern: /\b(?:local_invocation_id|local_invocation_index|global_invocation_id|workgroup_id|num_workgroups)\b/, alias: 'namespace' },
],
'bool-literal': {
pattern: /\b(?:true|false)\b/,
alias: 'boolean',
},
'hex-int-literal': [
{ pattern: /\b0[xX][0-9a-fA-F]+[iu]?(?!(?:\.|p|P))\b/, alias:'number' },
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
],
'hex-float-literal': [
{ pattern: /0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+(?:[pP](?:\+|-)?[0-9]+[fh]?)?/, alias:'number' },
{ pattern: /0[xX][0-9a-fA-F]+\.[0-9a-fA-F]*(?:[pP](?:\+|-)?[0-9]+[fh]?)?/, alias:'number' },
{ pattern: /0[xX][0-9a-fA-F]+[pP](?:\+|-)?[0-9]+[fh]?/, alias:'number' },
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
],
'decimal-float-literal-a': [
{ pattern: /[0-9]*\.[0-9]+(?:[eE](?:\+|-)?[0-9]+)?[fh]?/, alias:'number' },
{ pattern: /[0-9]+\.[0-9]*(?:[eE](?:\+|-)?[0-9]+)?[fh]?/, alias:'number' },
{ pattern: /[0-9]+[eE](?:\+|-)?[0-9]+[fh]?/, alias:'number' },
],
'variables': {
pattern: /\b(?:(?:[_\p{XID_Start}][\p{XID_Continue}]+)|(?:[\p{XID_Start}]))\b/u,
alias: 'variable',
},
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
'decimal-float-literal-b': [
{ pattern: /0[fh]/, alias:'number' },
{ pattern: /[1-9][0-9]*[fh]/, alias:'number' },
],
'int-literal': [
{ pattern: /0[iu]?/, alias:'number' },
{ pattern: /[1-9][0-9]*[iu]?/, alias:'number' },
],
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
'operator': [
{ pattern: /(?:\^|~|\||\|\||&&|<<|>>|!)(?!=)/ },
{ pattern: /&(?![&=])/ },
{ pattern: /(?:\+=|-=|\*=|\/=|%=|\^=|&=|\|=|<<=|>>=)/},
{ pattern: /(?<![<>])=(?!=|>)/ },
{ pattern: /(?:=(?:=)?(?!>)|!=|<=|(?<!=)>=)/ },
{ pattern: /(?:(?:[+%]|(?:\*(?!\w)))(?!=))|(?:-(?!>))|(?:\/(?!\/))/ },
{ pattern: /\.(?!\.)/ },
{ pattern: /->/ },
],
'punctuation': [
{ pattern: /,/ },
{ pattern: /[{}]/ },
{ pattern: /[\(\)]/ },
{ pattern: /;/ },
{ pattern: /[\[\]]/ },
{ pattern: /(?<!=)[<>]/ },
],
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
};
1 change: 1 addition & 0 deletions components/prism-wgsl.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions examples/prism-wgsl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<h2>Full example</h2>
<pre><code>// Vertex shader
struct CameraUniform {
view_proj: mat4x4&lt;f32&gt;;
};
[[group(1), binding(0)]]
var&lt;uniform&gt; camera: CameraUniform;

struct InstanceInput {
[[location(5)]] model_matrix_0: vec4&lt;f32&gt;;
[[location(6)]] model_matrix_1: vec4&lt;f32&gt;;
[[location(7)]] model_matrix_2: vec4&lt;f32&gt;;
[[location(8)]] model_matrix_3: vec4&lt;f32&gt;;
};

struct VertexInput {
[[location(0)]] position: vec3&lt;f32&gt;;
[[location(1)]] tex_coords: vec2&lt;f32&gt;;
};

struct VertexOutput {
[[builtin(position)]] clip_position: vec4&lt;f32&gt;;
[[location(0)]] tex_coords: vec2&lt;f32&gt;;
};

@vertex
[[stage(vertex)]]
fn vs_main(
model: VertexInput,
instance: InstanceInput,
) -&gt; VertexOutput {
let model_matrix = mat4x4&lt;f32&gt;(
instance.model_matrix_0,
instance.model_matrix_1,
instance.model_matrix_2,
instance.model_matrix_3,
);

bool mybool1 = true;
bool mybool2 = false;

var out: VertexOutput;
out.tex_coords = model.tex_coords;
out.clip_position = camera.view_proj * model_matrix * vec4&lt;f32&gt;(model.position, 1.0);
return out;
}

// Fragment shader

[[group(0), binding(0)]]
var t_diffuse: texture_2d&lt;f32&gt;;
[[group(0), binding(1)]]
var s_diffuse: sampler;

@fragment
[[stage(fragment)]]
fn fs_main(in: VertexOutput) -&gt; [[location(0)]] vec4&lt;f32&gt; {
return textureSample(t_diffuse, s_diffuse, in.tex_coords);
}
</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
"wasm": "WebAssembly",
"web-idl": "Web IDL",
"webidl": "Web IDL",
"wgsl": "WGSL",
"wiki": "Wiki markup",
"wolfram": "Wolfram language",
"nb": "Mathematica Notebook",
Expand Down
Loading