Skip to content

Commit

Permalink
Add WebGPU Shading Language lexer (#776)
Browse files Browse the repository at this point in the history
https://w3.org/TR/WGSL

Generated from the Pygments lexer I wrote, in
pygments/pygments#2386
  • Loading branch information
dneto0 authored Mar 26, 2023
1 parent 4f02bc5 commit 0eecb2a
Show file tree
Hide file tree
Showing 11 changed files with 759 additions and 0 deletions.
61 changes: 61 additions & 0 deletions lexers/embedded/wgsl.xml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions lexers/testdata/wgsl.attribute.actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@id(0) override x:i32 = 1;
@ id(1) override y:i32 = 2;
@//comment
id(1) override z:i32 = 3;
@must_use fn foo() -> i32 { return 32; }
74 changes: 74 additions & 0 deletions lexers/testdata/wgsl.attribute.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{"type":"NameDecorator","value":"@id"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"0"},
{"type":"Punctuation","value":")"},
{"type":"TextWhitespace","value":" "},
{"type":"KeywordDeclaration","value":"override"},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"x"},
{"type":"Punctuation","value":":"},
{"type":"NameBuiltin","value":"i32"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":";"},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameDecorator","value":"@"},
{"type":"TextWhitespace","value":" "},
{"type":"NameDecorator","value":"id"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":")"},
{"type":"TextWhitespace","value":" "},
{"type":"KeywordDeclaration","value":"override"},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"y"},
{"type":"Punctuation","value":":"},
{"type":"NameBuiltin","value":"i32"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumberInteger","value":"2"},
{"type":"Punctuation","value":";"},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameDecorator","value":"@"},
{"type":"CommentSingle","value":"//comment\n"},
{"type":"NameDecorator","value":"id"},
{"type":"Punctuation","value":"("},
{"type":"LiteralNumberInteger","value":"1"},
{"type":"Punctuation","value":")"},
{"type":"TextWhitespace","value":" "},
{"type":"KeywordDeclaration","value":"override"},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"z"},
{"type":"Punctuation","value":":"},
{"type":"NameBuiltin","value":"i32"},
{"type":"TextWhitespace","value":" "},
{"type":"Operator","value":"="},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumberInteger","value":"3"},
{"type":"Punctuation","value":";"},
{"type":"TextWhitespace","value":"\n"},
{"type":"NameDecorator","value":"@must_use"},
{"type":"TextWhitespace","value":" "},
{"type":"Keyword","value":"fn"},
{"type":"TextWhitespace","value":" "},
{"type":"Name","value":"foo"},
{"type":"Punctuation","value":"()"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"-\u003e"},
{"type":"TextWhitespace","value":" "},
{"type":"NameBuiltin","value":"i32"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"{"},
{"type":"TextWhitespace","value":" "},
{"type":"Keyword","value":"return"},
{"type":"TextWhitespace","value":" "},
{"type":"LiteralNumberInteger","value":"32"},
{"type":"Punctuation","value":";"},
{"type":"TextWhitespace","value":" "},
{"type":"Punctuation","value":"}"},
{"type":"TextWhitespace","value":"\n"}
]
8 changes: 8 additions & 0 deletions lexers/testdata/wgsl.block.comment.actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**/
/*block with newline
*/
/*block with line
ending comment// */
/* nested /*
*/
*/
11 changes: 11 additions & 0 deletions lexers/testdata/wgsl.block.comment.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{"type":"TextWhitespace","value":" "},
{"type":"CommentMultiline","value":"/**/"},
{"type":"TextWhitespace","value":"\n "},
{"type":"CommentMultiline","value":"/*block with newline\n */"},
{"type":"TextWhitespace","value":"\n "},
{"type":"CommentMultiline","value":"/*block with line\n ending comment// */"},
{"type":"TextWhitespace","value":"\n "},
{"type":"CommentMultiline","value":"/* nested /*\n */\n */"},
{"type":"TextWhitespace","value":"\n"}
]
50 changes: 50 additions & 0 deletions lexers/testdata/wgsl.const.numbers.actual
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const a = 0;
const au = 0u;
const ai = 0i;
const b = 12345;
const bu = 12345u;
const bi= 12345i;
const c = 0x0;
const cu = 0x0u;
const ci = 0x0i;
const d = 0x12345;
const di = 0x12345i;
const du = 0x12345u;
const eh = 0h;
const ef = 0f;
const f = 1.;
const fh = 1.h;
const ff = 1.f;
const g = .1;
const gh = .1h;
const gf = .1f;
const g = 1e1;
const gh = 1e1h;
const gf = 1e1f;
const h = 1e+1;
const hh = 1e+1h;
const hf = 1e+1f;
const i = 1e-1;
const ih = 1e-1h;
const if = 1e-1f;
const j = 1.0e+1;
const jh = 1.0e+1h;
const jf= 1.0e+1f;
const k = 1.0e-1;
const kh = 1.0e-1h;
const kf= 1.0e-1f;
const l = 0x1p1;
const lh = 0x1p1h;
const lf = 0x1p1f;
const m = 0x1p+1;
const mh = 0x1p+1h;
const mf = 0x1p+1f;
const n = 0x1p-1;
const nh = 0x1p-1h;
const nf = 0x1p-1f;
const o = 0x1.p1;
const oh = 0x1.p1h;
const of = 0x1.p1f;
const p = 0x.1p1;
const ph = 0x.1p1h;
const pf = 0x.1p1f;
Loading

0 comments on commit 0eecb2a

Please sign in to comment.