From 0eecb2ae57a6fb0588455fe1183afd922c068014 Mon Sep 17 00:00:00 2001 From: David Neto Date: Sun, 26 Mar 2023 16:19:09 -0400 Subject: [PATCH] Add WebGPU Shading Language lexer (#776) https://w3.org/TR/WGSL Generated from the Pygments lexer I wrote, in https://github.com/pygments/pygments/pull/2386 --- lexers/embedded/wgsl.xml | 61 +++ lexers/testdata/wgsl.attribute.actual | 5 + lexers/testdata/wgsl.attribute.expected | 74 ++++ lexers/testdata/wgsl.block.comment.actual | 8 + lexers/testdata/wgsl.block.comment.expected | 11 + lexers/testdata/wgsl.const.numbers.actual | 50 +++ lexers/testdata/wgsl.const.numbers.expected | 449 ++++++++++++++++++++ lexers/testdata/wgsl.line.comment.actual | 3 + lexers/testdata/wgsl.line.comment.expected | 6 + lexers/testdata/wgsl.tiny.render.actual | 9 + lexers/testdata/wgsl.tiny.render.expected | 83 ++++ 11 files changed, 759 insertions(+) create mode 100644 lexers/embedded/wgsl.xml create mode 100644 lexers/testdata/wgsl.attribute.actual create mode 100644 lexers/testdata/wgsl.attribute.expected create mode 100644 lexers/testdata/wgsl.block.comment.actual create mode 100644 lexers/testdata/wgsl.block.comment.expected create mode 100644 lexers/testdata/wgsl.const.numbers.actual create mode 100644 lexers/testdata/wgsl.const.numbers.expected create mode 100644 lexers/testdata/wgsl.line.comment.actual create mode 100644 lexers/testdata/wgsl.line.comment.expected create mode 100644 lexers/testdata/wgsl.tiny.render.actual create mode 100644 lexers/testdata/wgsl.tiny.render.expected diff --git a/lexers/embedded/wgsl.xml b/lexers/embedded/wgsl.xml new file mode 100644 index 000000000..5f4422e5a --- /dev/null +++ b/lexers/embedded/wgsl.xml @@ -0,0 +1,61 @@ + + + + WebGPU Shading Language + wgsl + *.wgsl + text/wgsl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lexers/testdata/wgsl.attribute.actual b/lexers/testdata/wgsl.attribute.actual new file mode 100644 index 000000000..9ccdaedb0 --- /dev/null +++ b/lexers/testdata/wgsl.attribute.actual @@ -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; } diff --git a/lexers/testdata/wgsl.attribute.expected b/lexers/testdata/wgsl.attribute.expected new file mode 100644 index 000000000..881238826 --- /dev/null +++ b/lexers/testdata/wgsl.attribute.expected @@ -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"} +] diff --git a/lexers/testdata/wgsl.block.comment.actual b/lexers/testdata/wgsl.block.comment.actual new file mode 100644 index 000000000..029980451 --- /dev/null +++ b/lexers/testdata/wgsl.block.comment.actual @@ -0,0 +1,8 @@ + /**/ + /*block with newline + */ + /*block with line + ending comment// */ + /* nested /* + */ + */ diff --git a/lexers/testdata/wgsl.block.comment.expected b/lexers/testdata/wgsl.block.comment.expected new file mode 100644 index 000000000..7a0a5b396 --- /dev/null +++ b/lexers/testdata/wgsl.block.comment.expected @@ -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"} +] diff --git a/lexers/testdata/wgsl.const.numbers.actual b/lexers/testdata/wgsl.const.numbers.actual new file mode 100644 index 000000000..691f5bddd --- /dev/null +++ b/lexers/testdata/wgsl.const.numbers.actual @@ -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; diff --git a/lexers/testdata/wgsl.const.numbers.expected b/lexers/testdata/wgsl.const.numbers.expected new file mode 100644 index 000000000..0c9cfa575 --- /dev/null +++ b/lexers/testdata/wgsl.const.numbers.expected @@ -0,0 +1,449 @@ +[ + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"a"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"0"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"au"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"0u"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"ai"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"0i"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"b"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"12345"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"bu"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"12345u"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"bi"}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberInteger","value":"12345i"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"c"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberHex","value":"0x0"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"cu"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberHex","value":"0x0u"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"ci"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberHex","value":"0x0i"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"d"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberHex","value":"0x12345"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"di"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberHex","value":"0x12345i"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"du"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberHex","value":"0x12345u"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"eh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"ef"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"f"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1."}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"fh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1.h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"ff"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1.f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"g"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":".1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"gh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":".1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"gf"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":".1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"g"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1e1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"gh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1e1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"gf"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1e1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"h"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1e+1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"hh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1e+1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"hf"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1e+1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"i"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1e-1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"ih"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1e-1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Keyword","value":"if"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1e-1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"j"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1.0e+1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"jh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1.0e+1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"jf"}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1.0e+1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"k"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1.0e-1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"kh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1.0e-1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"kf"}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"1.0e-1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"l"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1p1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"lh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1p1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"lf"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1p1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"m"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1p+1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"mh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1p+1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"mf"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1p+1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"n"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1p-1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"nh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1p-1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"nf"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1p-1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"o"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1.p1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"oh"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1.p1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"KeywordReserved","value":"of"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x1.p1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"p"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x.1p1"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"ph"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x.1p1h"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"KeywordDeclaration","value":"const"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"pf"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Operator","value":"="}, + {"type":"TextWhitespace","value":" "}, + {"type":"LiteralNumberFloat","value":"0x.1p1f"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"} +] diff --git a/lexers/testdata/wgsl.line.comment.actual b/lexers/testdata/wgsl.line.comment.actual new file mode 100644 index 000000000..31f9cc626 --- /dev/null +++ b/lexers/testdata/wgsl.line.comment.actual @@ -0,0 +1,3 @@ + // this is a line-ending comment + //* embed a bock comment start, after gap of space +// /* embed a bock comment start, v2 diff --git a/lexers/testdata/wgsl.line.comment.expected b/lexers/testdata/wgsl.line.comment.expected new file mode 100644 index 000000000..e4a9759f5 --- /dev/null +++ b/lexers/testdata/wgsl.line.comment.expected @@ -0,0 +1,6 @@ +[ + {"type":"TextWhitespace","value":" "}, + {"type":"CommentSingle","value":"// this is a line-ending comment\n"}, + {"type":"TextWhitespace","value":" "}, + {"type":"CommentSingle","value":"//* embed a bock comment start, after gap of space\n// /* embed a bock comment start, v2\n"} +] diff --git a/lexers/testdata/wgsl.tiny.render.actual b/lexers/testdata/wgsl.tiny.render.actual new file mode 100644 index 000000000..4b55fe827 --- /dev/null +++ b/lexers/testdata/wgsl.tiny.render.actual @@ -0,0 +1,9 @@ +@vertex +fn vmain(@location(0) v: vec4) -> @builtin(position) vec4f { + return v; +} + +@fragment +fn fmain(@builtin(position) pos: vec4f) -> @location(0) vec4f { + return vec4f(0.25,0.25,1.0,1.0); +} diff --git a/lexers/testdata/wgsl.tiny.render.expected b/lexers/testdata/wgsl.tiny.render.expected new file mode 100644 index 000000000..bb468b617 --- /dev/null +++ b/lexers/testdata/wgsl.tiny.render.expected @@ -0,0 +1,83 @@ +[ + {"type":"NameDecorator","value":"@vertex"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Keyword","value":"fn"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"vmain"}, + {"type":"Punctuation","value":"("}, + {"type":"NameDecorator","value":"@location"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralNumberInteger","value":"0"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"v"}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameBuiltin","value":"vec4"}, + {"type":"Operator","value":"\u003c"}, + {"type":"NameBuiltin","value":"f32"}, + {"type":"Operator","value":"\u003e"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"-\u003e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameDecorator","value":"@builtin"}, + {"type":"Punctuation","value":"("}, + {"type":"NameBuiltin","value":"position"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameBuiltin","value":"vec4f"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"Keyword","value":"return"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"v"}, + {"type":"Punctuation","value":";"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n\n"}, + {"type":"NameDecorator","value":"@fragment"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Keyword","value":"fn"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"fmain"}, + {"type":"Punctuation","value":"("}, + {"type":"NameDecorator","value":"@builtin"}, + {"type":"Punctuation","value":"("}, + {"type":"NameBuiltin","value":"position"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Name","value":"pos"}, + {"type":"Punctuation","value":":"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameBuiltin","value":"vec4f"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"-\u003e"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameDecorator","value":"@location"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralNumberInteger","value":"0"}, + {"type":"Punctuation","value":")"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameBuiltin","value":"vec4f"}, + {"type":"TextWhitespace","value":" "}, + {"type":"Punctuation","value":"{"}, + {"type":"TextWhitespace","value":"\n "}, + {"type":"Keyword","value":"return"}, + {"type":"TextWhitespace","value":" "}, + {"type":"NameBuiltin","value":"vec4f"}, + {"type":"Punctuation","value":"("}, + {"type":"LiteralNumberFloat","value":"0.25"}, + {"type":"Punctuation","value":","}, + {"type":"LiteralNumberFloat","value":"0.25"}, + {"type":"Punctuation","value":","}, + {"type":"LiteralNumberFloat","value":"1.0"}, + {"type":"Punctuation","value":","}, + {"type":"LiteralNumberFloat","value":"1.0"}, + {"type":"Punctuation","value":");"}, + {"type":"TextWhitespace","value":"\n"}, + {"type":"Punctuation","value":"}"}, + {"type":"TextWhitespace","value":"\n"} +]