wgsl.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. "use strict";
  2. /*!-----------------------------------------------------------------------------
  3. * Copyright (c) Microsoft Corporation. All rights reserved.
  4. * Version: 0.38.0(0e330ae453813de4e6cf272460fb79c7117073d0)
  5. * Released under the MIT license
  6. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  7. *-----------------------------------------------------------------------------*/
  8. define("vs/basic-languages/wgsl/wgsl", ["require"],(require)=>{
  9. var moduleExports = (() => {
  10. var __defProp = Object.defineProperty;
  11. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  12. var __getOwnPropNames = Object.getOwnPropertyNames;
  13. var __hasOwnProp = Object.prototype.hasOwnProperty;
  14. var __export = (target, all) => {
  15. for (var name in all)
  16. __defProp(target, name, { get: all[name], enumerable: true });
  17. };
  18. var __copyProps = (to, from, except, desc) => {
  19. if (from && typeof from === "object" || typeof from === "function") {
  20. for (let key of __getOwnPropNames(from))
  21. if (!__hasOwnProp.call(to, key) && key !== except)
  22. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  23. }
  24. return to;
  25. };
  26. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  27. // src/basic-languages/wgsl/wgsl.ts
  28. var wgsl_exports = {};
  29. __export(wgsl_exports, {
  30. conf: () => conf,
  31. language: () => language
  32. });
  33. var conf = {
  34. comments: {
  35. lineComment: "//",
  36. blockComment: ["/*", "*/"]
  37. },
  38. brackets: [
  39. ["{", "}"],
  40. ["[", "]"],
  41. ["(", ")"]
  42. ],
  43. autoClosingPairs: [
  44. { open: "[", close: "]" },
  45. { open: "{", close: "}" },
  46. { open: "(", close: ")" }
  47. ],
  48. surroundingPairs: [
  49. { open: "{", close: "}" },
  50. { open: "[", close: "]" },
  51. { open: "(", close: ")" }
  52. ]
  53. };
  54. function qw(str) {
  55. let result = [];
  56. const words = str.split(/\t+|\r+|\n+| +/);
  57. for (let i = 0; i < words.length; ++i) {
  58. if (words[i].length > 0) {
  59. result.push(words[i]);
  60. }
  61. }
  62. return result;
  63. }
  64. var atoms = qw("true false");
  65. var keywords = qw(`
  66. alias
  67. break
  68. case
  69. const
  70. const_assert
  71. continue
  72. continuing
  73. default
  74. diagnostic
  75. discard
  76. else
  77. enable
  78. fn
  79. for
  80. if
  81. let
  82. loop
  83. override
  84. requires
  85. return
  86. struct
  87. switch
  88. var
  89. while
  90. `);
  91. var reserved = qw(`
  92. NULL
  93. Self
  94. abstract
  95. active
  96. alignas
  97. alignof
  98. as
  99. asm
  100. asm_fragment
  101. async
  102. attribute
  103. auto
  104. await
  105. become
  106. binding_array
  107. cast
  108. catch
  109. class
  110. co_await
  111. co_return
  112. co_yield
  113. coherent
  114. column_major
  115. common
  116. compile
  117. compile_fragment
  118. concept
  119. const_cast
  120. consteval
  121. constexpr
  122. constinit
  123. crate
  124. debugger
  125. decltype
  126. delete
  127. demote
  128. demote_to_helper
  129. do
  130. dynamic_cast
  131. enum
  132. explicit
  133. export
  134. extends
  135. extern
  136. external
  137. fallthrough
  138. filter
  139. final
  140. finally
  141. friend
  142. from
  143. fxgroup
  144. get
  145. goto
  146. groupshared
  147. highp
  148. impl
  149. implements
  150. import
  151. inline
  152. instanceof
  153. interface
  154. layout
  155. lowp
  156. macro
  157. macro_rules
  158. match
  159. mediump
  160. meta
  161. mod
  162. module
  163. move
  164. mut
  165. mutable
  166. namespace
  167. new
  168. nil
  169. noexcept
  170. noinline
  171. nointerpolation
  172. noperspective
  173. null
  174. nullptr
  175. of
  176. operator
  177. package
  178. packoffset
  179. partition
  180. pass
  181. patch
  182. pixelfragment
  183. precise
  184. precision
  185. premerge
  186. priv
  187. protected
  188. pub
  189. public
  190. readonly
  191. ref
  192. regardless
  193. register
  194. reinterpret_cast
  195. require
  196. resource
  197. restrict
  198. self
  199. set
  200. shared
  201. sizeof
  202. smooth
  203. snorm
  204. static
  205. static_assert
  206. static_cast
  207. std
  208. subroutine
  209. super
  210. target
  211. template
  212. this
  213. thread_local
  214. throw
  215. trait
  216. try
  217. type
  218. typedef
  219. typeid
  220. typename
  221. typeof
  222. union
  223. unless
  224. unorm
  225. unsafe
  226. unsized
  227. use
  228. using
  229. varying
  230. virtual
  231. volatile
  232. wgsl
  233. where
  234. with
  235. writeonly
  236. yield
  237. `);
  238. var predeclared_enums = qw(`
  239. read write read_write
  240. function private workgroup uniform storage
  241. perspective linear flat
  242. center centroid sample
  243. vertex_index instance_index position front_facing frag_depth
  244. local_invocation_id local_invocation_index
  245. global_invocation_id workgroup_id num_workgroups
  246. sample_index sample_mask
  247. rgba8unorm
  248. rgba8snorm
  249. rgba8uint
  250. rgba8sint
  251. rgba16uint
  252. rgba16sint
  253. rgba16float
  254. r32uint
  255. r32sint
  256. r32float
  257. rg32uint
  258. rg32sint
  259. rg32float
  260. rgba32uint
  261. rgba32sint
  262. rgba32float
  263. bgra8unorm
  264. `);
  265. var predeclared_types = qw(`
  266. bool
  267. f16
  268. f32
  269. i32
  270. sampler sampler_comparison
  271. texture_depth_2d
  272. texture_depth_2d_array
  273. texture_depth_cube
  274. texture_depth_cube_array
  275. texture_depth_multisampled_2d
  276. texture_external
  277. texture_external
  278. u32
  279. `);
  280. var predeclared_type_generators = qw(`
  281. array
  282. atomic
  283. mat2x2
  284. mat2x3
  285. mat2x4
  286. mat3x2
  287. mat3x3
  288. mat3x4
  289. mat4x2
  290. mat4x3
  291. mat4x4
  292. ptr
  293. texture_1d
  294. texture_2d
  295. texture_2d_array
  296. texture_3d
  297. texture_cube
  298. texture_cube_array
  299. texture_multisampled_2d
  300. texture_storage_1d
  301. texture_storage_2d
  302. texture_storage_2d_array
  303. texture_storage_3d
  304. vec2
  305. vec3
  306. vec4
  307. `);
  308. var predeclared_type_aliases = qw(`
  309. vec2i vec3i vec4i
  310. vec2u vec3u vec4u
  311. vec2f vec3f vec4f
  312. vec2h vec3h vec4h
  313. mat2x2f mat2x3f mat2x4f
  314. mat3x2f mat3x3f mat3x4f
  315. mat4x2f mat4x3f mat4x4f
  316. mat2x2h mat2x3h mat2x4h
  317. mat3x2h mat3x3h mat3x4h
  318. mat4x2h mat4x3h mat4x4h
  319. `);
  320. var predeclared_intrinsics = qw(`
  321. bitcast all any select arrayLength abs acos acosh asin asinh atan atanh atan2
  322. ceil clamp cos cosh countLeadingZeros countOneBits countTrailingZeros cross
  323. degrees determinant distance dot exp exp2 extractBits faceForward firstLeadingBit
  324. firstTrailingBit floor fma fract frexp inverseBits inverseSqrt ldexp length
  325. log log2 max min mix modf normalize pow quantizeToF16 radians reflect refract
  326. reverseBits round saturate sign sin sinh smoothstep sqrt step tan tanh transpose
  327. trunc dpdx dpdxCoarse dpdxFine dpdy dpdyCoarse dpdyFine fwidth fwidthCoarse fwidthFine
  328. textureDimensions textureGather textureGatherCompare textureLoad textureNumLayers
  329. textureNumLevels textureNumSamples textureSample textureSampleBias textureSampleCompare
  330. textureSampleCompareLevel textureSampleGrad textureSampleLevel textureSampleBaseClampToEdge
  331. textureStore atomicLoad atomicStore atomicAdd atomicSub atomicMax atomicMin
  332. atomicAnd atomicOr atomicXor atomicExchange atomicCompareExchangeWeak pack4x8snorm
  333. pack4x8unorm pack2x16snorm pack2x16unorm pack2x16float unpack4x8snorm unpack4x8unorm
  334. unpack2x16snorm unpack2x16unorm unpack2x16float storageBarrier workgroupBarrier
  335. workgroupUniformLoad
  336. `);
  337. var operators = qw(`
  338. &
  339. &&
  340. ->
  341. /
  342. =
  343. ==
  344. !=
  345. >
  346. >=
  347. <
  348. <=
  349. %
  350. -
  351. --
  352. +
  353. ++
  354. |
  355. ||
  356. *
  357. <<
  358. >>
  359. +=
  360. -=
  361. *=
  362. /=
  363. %=
  364. &=
  365. |=
  366. ^=
  367. >>=
  368. <<=
  369. `);
  370. var directive_re = /enable|requires|diagnostic/;
  371. var ident_re = /[_\p{XID_Start}]\p{XID_Continue}*/u;
  372. var predefined_token = "variable.predefined";
  373. var language = {
  374. tokenPostfix: ".wgsl",
  375. defaultToken: "invalid",
  376. unicode: true,
  377. atoms,
  378. keywords,
  379. reserved,
  380. predeclared_enums,
  381. predeclared_types,
  382. predeclared_type_generators,
  383. predeclared_type_aliases,
  384. predeclared_intrinsics,
  385. operators,
  386. symbols: /[!%&*+\-\.\/:;<=>^|_~]+/,
  387. tokenizer: {
  388. root: [
  389. [directive_re, "keyword", "@directive"],
  390. [
  391. ident_re,
  392. {
  393. cases: {
  394. "@atoms": predefined_token,
  395. "@keywords": "keyword",
  396. "@reserved": "invalid",
  397. "@predeclared_enums": predefined_token,
  398. "@predeclared_types": predefined_token,
  399. "@predeclared_type_generators": predefined_token,
  400. "@predeclared_type_aliases": predefined_token,
  401. "@predeclared_intrinsics": predefined_token,
  402. "@default": "identifier"
  403. }
  404. }
  405. ],
  406. { include: "@commentOrSpace" },
  407. { include: "@numbers" },
  408. [/;:\./, "delimiter"],
  409. [/,/, "delimiter"],
  410. [/[{}()\[\]]/, "@brackets"],
  411. ["@", "annotation", "@attribute"],
  412. [
  413. /@symbols/,
  414. {
  415. cases: {
  416. "@operators": "operator",
  417. "@default": "delimiter"
  418. }
  419. }
  420. ],
  421. [/./, "invalid"]
  422. ],
  423. commentOrSpace: [
  424. [/\s+/, "white"],
  425. [/\/\*/, "comment", "@blockComment"],
  426. [/\/\/.*$/, "comment"]
  427. ],
  428. blockComment: [
  429. [/[^\/*]+/, "comment"],
  430. [/\/\*/, "comment", "@push"],
  431. [/\*\//, "comment", "@pop"],
  432. [/[\/*]/, "comment"]
  433. ],
  434. attribute: [
  435. { include: "@commentOrSpace" },
  436. [/\w+/, "annotation", "@pop"]
  437. ],
  438. directive: [
  439. { include: "@commentOrSpace" },
  440. [/[()]/, "@brackets"],
  441. [/,/, "delimiter"],
  442. [ident_re, "meta.content"],
  443. [/;/, "delimiter", "@pop"]
  444. ],
  445. numbers: [
  446. [/0[fh]/, "number.float"],
  447. [/[1-9][0-9]*[fh]/, "number.float"],
  448. [/[0-9]*\.[0-9]+([eE][+-]?[0-9]+)?[fh]?/, "number.float"],
  449. [/[0-9]+\.[0-9]*([eE][+-]?[0-9]+)?[fh]?/, "number.float"],
  450. [/[0-9]+[eE][+-]?[0-9]+[fh]?/, "number.float"],
  451. [/0[xX][0-9a-fA-F]*\.[0-9a-fA-F]+(?:[pP][+-]?[0-9]+[fh]?)?/, "number.hex"],
  452. [/0[xX][0-9a-fA-F]+\.[0-9a-fA-F]*(?:[pP][+-]?[0-9]+[fh]?)?/, "number.hex"],
  453. [/0[xX][0-9a-fA-F]+[pP][+-]?[0-9]+[fh]?/, "number.hex"],
  454. [/0[xX][0-9a-fA-F]+[iu]?/, "number.hex"],
  455. [/[1-9][0-9]*[iu]?/, "number"],
  456. [/0[iu]?/, "number"]
  457. ]
  458. }
  459. };
  460. return __toCommonJS(wgsl_exports);
  461. })();
  462. return moduleExports;
  463. });