You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.7 KiB

7 months ago
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/5/LICENSE
  3. (function(mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"), require("../../addon/mode/simple"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror", "../../addon/mode/simple"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. var kKeywords = [
  13. "align",
  14. "block",
  15. "br(_if|_table|_on_(cast|data|func|i31|null))?",
  16. "call(_indirect|_ref)?",
  17. "current_memory",
  18. "\\bdata\\b",
  19. "catch(_all)?",
  20. "delegate",
  21. "drop",
  22. "elem",
  23. "else",
  24. "end",
  25. "export",
  26. "\\bextern\\b",
  27. "\\bfunc\\b",
  28. "global(\\.(get|set))?",
  29. "if",
  30. "import",
  31. "local(\\.(get|set|tee))?",
  32. "loop",
  33. "module",
  34. "mut",
  35. "nop",
  36. "offset",
  37. "param",
  38. "result",
  39. "rethrow",
  40. "return(_call(_indirect|_ref)?)?",
  41. "select",
  42. "start",
  43. "table(\\.(size|get|set|size|grow|fill|init|copy))?",
  44. "then",
  45. "throw",
  46. "try",
  47. "type",
  48. "unreachable",
  49. "unwind",
  50. // Numeric opcodes.
  51. "i(32|64)\\.(store(8|16)|(load(8|16)_[su]))",
  52. "i64\\.(load32_[su]|store32)",
  53. "[fi](32|64)\\.(const|load|store)",
  54. "f(32|64)\\.(abs|add|ceil|copysign|div|eq|floor|[gl][et]|max|min|mul|nearest|neg?|sqrt|sub|trunc)",
  55. "i(32|64)\\.(a[dn]d|c[lt]z|(div|rem)_[su]|eqz?|[gl][te]_[su]|mul|ne|popcnt|rot[lr]|sh(l|r_[su])|sub|x?or)",
  56. "i64\\.extend_[su]_i32",
  57. "i32\\.wrap_i64",
  58. "i(32|64)\\.trunc_f(32|64)_[su]",
  59. "f(32|64)\\.convert_i(32|64)_[su]",
  60. "f64\\.promote_f32",
  61. "f32\\.demote_f64",
  62. "f32\\.reinterpret_i32",
  63. "i32\\.reinterpret_f32",
  64. "f64\\.reinterpret_i64",
  65. "i64\\.reinterpret_f64",
  66. // Atomics.
  67. "memory(\\.((atomic\\.(notify|wait(32|64)))|grow|size))?",
  68. "i64\.atomic\\.(load32_u|store32|rmw32\\.(a[dn]d|sub|x?or|(cmp)?xchg)_u)",
  69. "i(32|64)\\.atomic\\.(load((8|16)_u)?|store(8|16)?|rmw(\\.(a[dn]d|sub|x?or|(cmp)?xchg)|(8|16)\\.(a[dn]d|sub|x?or|(cmp)?xchg)_u))",
  70. // SIMD.
  71. "v128\\.load(8x8|16x4|32x2)_[su]",
  72. "v128\\.load(8|16|32|64)_splat",
  73. "v128\\.(load|store)(8|16|32|64)_lane",
  74. "v128\\.load(32|64)_zero",
  75. "v128\.(load|store|const|not|andnot|and|or|xor|bitselect|any_true)",
  76. "i(8x16|16x8)\\.(extract_lane_[su]|(add|sub)_sat_[su]|avgr_u)",
  77. "i(8x16|16x8|32x4|64x2)\\.(neg|add|sub|abs|shl|shr_[su]|all_true|bitmask|eq|ne|[lg][te]_s)",
  78. "(i(8x16|16x8|32x4|64x2)|f(32x4|64x2))\.(splat|replace_lane)",
  79. "i(8x16|16x8|32x4)\\.(([lg][te]_u)|((min|max)_[su]))",
  80. "f(32x4|64x2)\\.(neg|add|sub|abs|nearest|eq|ne|[lg][te]|sqrt|mul|div|min|max|ceil|floor|trunc)",
  81. "[fi](32x4|64x2)\\.extract_lane",
  82. "i8x16\\.(shuffle|swizzle|popcnt|narrow_i16x8_[su])",
  83. "i16x8\\.(narrow_i32x4_[su]|mul|extadd_pairwise_i8x16_[su]|q15mulr_sat_s)",
  84. "i16x8\\.(extend|extmul)_(low|high)_i8x16_[su]",
  85. "i32x4\\.(mul|dot_i16x8_s|trunc_sat_f64x2_[su]_zero)",
  86. "i32x4\\.((extend|extmul)_(low|high)_i16x8_|trunc_sat_f32x4_|extadd_pairwise_i16x8_)[su]",
  87. "i64x2\\.(mul|(extend|extmul)_(low|high)_i32x4_[su])",
  88. "f32x4\\.(convert_i32x4_[su]|demote_f64x2_zero)",
  89. "f64x2\\.(promote_low_f32x4|convert_low_i32x4_[su])",
  90. // Reference types, function references, and GC.
  91. "\\bany\\b",
  92. "array\\.len",
  93. "(array|struct)(\\.(new_(default_)?with_rtt|get(_[su])?|set))?",
  94. "\\beq\\b",
  95. "field",
  96. "i31\\.(new|get_[su])",
  97. "\\bnull\\b",
  98. "ref(\\.(([ai]s_(data|func|i31))|cast|eq|func|(is_|as_non_)?null|test))?",
  99. "rtt(\\.(canon|sub))?",
  100. ];
  101. CodeMirror.defineSimpleMode('wast', {
  102. start: [
  103. {regex: /[+\-]?(?:nan(?::0x[0-9a-fA-F]+)?|infinity|inf|0x[0-9a-fA-F]+\.?[0-9a-fA-F]*p[+\/-]?\d+|\d+(?:\.\d*)?[eE][+\-]?\d*|\d+\.\d*|0x[0-9a-fA-F]+|\d+)/, token: "number"},
  104. {regex: new RegExp(kKeywords.join('|')), token: "keyword"},
  105. {regex: /\b((any|data|eq|extern|i31|func)ref|[fi](32|64)|i(8|16))\b/, token: "atom"},
  106. {regex: /\$([a-zA-Z0-9_`\+\-\*\/\\\^~=<>!\?@#$%&|:\.]+)/, token: "variable-2"},
  107. {regex: /"(?:[^"\\\x00-\x1f\x7f]|\\[nt\\'"]|\\[0-9a-fA-F][0-9a-fA-F])*"/, token: "string"},
  108. {regex: /\(;.*?/, token: "comment", next: "comment"},
  109. {regex: /;;.*$/, token: "comment"},
  110. {regex: /\(/, indent: true},
  111. {regex: /\)/, dedent: true},
  112. ],
  113. comment: [
  114. {regex: /.*?;\)/, token: "comment", next: "start"},
  115. {regex: /.*/, token: "comment"},
  116. ],
  117. meta: {
  118. dontIndentStates: ['comment'],
  119. },
  120. });
  121. // https://github.com/WebAssembly/design/issues/981 mentions text/webassembly,
  122. // which seems like a reasonable choice, although it's not standard right now.
  123. CodeMirror.defineMIME("text/webassembly", "wast");
  124. });