Created
March 20, 2023 00:15
-
-
Save kbjr/57e74f466ee6281ef66be57dc282f595 to your computer and use it in GitHub Desktop.
Extend PrismJS highlighting for WASM with SIMD/Vector, `table`, `memory`, `ref` instructions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { languages } from 'prismjs'; | |
const extra_keywords = [ | |
{ | |
pattern: /\b(?:memory\.(?:init|copy|fill)|data\.(?:drop)|table\.(?:init|copy|grow|size|fill|get|set)|elem\.(?:drop)|ref\.(?:null|is_null|func))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
/\b(?:funcref|externref)\b/, | |
// ===== SIMD / Vectors ===== | |
{ | |
pattern: /\b(?:v128\.(?:const|store(?:(?:8|16|32|64)_lane)?|load(?:(?:8x8|16x4|32x2)_[su]|(?:8|16|32|64)_splat|(?:8|16|32|64)_lane|(?:32|64)_zero)?|not|and|andnot|or|xor|bitselect|any_true))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
{ | |
pattern: /\b(?:i(?:8x16|16x8|32x4|64x2)\.(?:splat|replace_lane|abs|neg|all_true|bitmask|shl|eq|ne|(?:shr)_[su]))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
{ | |
pattern: /\b(?:i(?:8x16|16x8|32x4)\.(?:(?:[gl][te]|min|max)_[su]))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
{ | |
pattern: /\b(?:i8x16\.(?:shuffle|swizzle|popcnt|avgr_u|(?:add|sub)(?:_sat_[su])?|(?:extract_lane|narrow_i16x8|extadd_pairwise_(?:i8x16|i16x8))_[su]))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
{ | |
pattern: /\b(?:i16x8\.(?:mul|avgr_u|q15mulr_sat_s|(?:add|sub)(?:_sat_[su])?|(?:extract_lane|narrow_i32x4|(?:extend|extmul)_(?:low|high)_i8x16)_[su]))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
{ | |
pattern: /\b(?:i32x4\.(?:extract_lane|add|sub|mul|dot_i16x8_s|(?:(?:extend|extmul)_(?:low|high)_i16x8|trunc_sat_f32x4)_[su]|trunc_sat_f64x2_[su]_zero))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
{ | |
pattern: /\b(?:i64x2\.(?:extract_lane|add|sub|mul|[gl][te]_s|(?:extend|extmul)_(?:low|high)_i32x4_[su]))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
{ | |
pattern: /\b(?:f(?:32x4|64x2)\.(?:splat|extract_lane|replace_lane|eq|ne|[gl][te]|ceil|floor|trunc|nearest|abs|neg|sqrt|add|sub|mul|div|p?(?:min|max)))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
{ | |
pattern: /\b(?:f32x4\.(?:demote_f64x2_zero|convert_i32x4_[su]))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
{ | |
pattern: /\b(?:f64x2\.(?:promote_low_f32x4|convert_low_i32x4_[su]))\b/, | |
inside: { | |
'punctuation': /\./ | |
} | |
}, | |
/\b(?:i8x16|i16x8|i32x4|i64x2|f32x4|f64x2)\b/, | |
]; | |
if (Array.isArray(languages.wasm.keyword)) { | |
languages.wasm.keyword.unshift(...extra_keywords); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment