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