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