Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 1 | " Vim syntax file |
| 2 | " Language: WebAssembly |
| 3 | " Maintainer: rhysd <lin90162@yahoo.co.jp> |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 4 | " Last Change: Aug 7, 2023 |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 5 | " For bugs, patches and license go to https://github.com/rhysd/vim-wasm |
| 6 | |
| 7 | if exists("b:current_syntax") |
| 8 | finish |
| 9 | endif |
| 10 | |
| 11 | let s:cpo_save = &cpo |
| 12 | set cpo&vim |
| 13 | |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 14 | syn cluster wastNotTop contains=wastModule,wastInstWithType,wastInstGetSet,wastInstGeneral,wastParamInst,wastControlInst,wastSimdInst,wastString,wastNamedVar,wastUnnamedVar,wastFloat,wastNumber,wastComment,wastList,wastType |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 15 | |
| 16 | " Instructions |
| 17 | " https://webassembly.github.io/spec/core/text/instructions.html |
| 18 | " Note: memarg (align=,offset=) can be added to memory instructions |
| 19 | syn match wastInstWithType "\%((\s*\)\@<=\<\%(i32\|i64\|f32\|f64\|memory\)\.[[:alnum:]_]\+\%(/\%(i32\|i64\|f32\|f64\)\)\=\>\%(\s\+\%(align\|offset\)=\)\=" contained display |
| 20 | syn match wastInstGeneral "\%((\s*\)\@<=\<[[:alnum:]_]\+\>" contained display |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 21 | syn match wastInstGetSet "\%((\s*\)\@<=\<\%(local\|global\)\.\%(get\|set\)\>" contained display |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 22 | " https://webassembly.github.io/spec/core/text/instructions.html#control-instructions |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 23 | syn match wastControlInst "\%((\s*\)\@<=\<\%(block\|end\|loop\|if\|then\|else\|unreachable\|nop\|br\|br_if\|br_table\|return\|call\|call_indirect\)\>" contained display |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 24 | " https://webassembly.github.io/spec/core/text/instructions.html#parametric-instructions |
| 25 | syn match wastParamInst "\%((\s*\)\@<=\<\%(drop\|select\)\>" contained display |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 26 | " SIMD instructions |
| 27 | " https://webassembly.github.io/simd/core/text/instructions.html#simd-instructions |
| 28 | syn match wastSimdInst "\<\%(v128\|i8x16\|i16x8\|i32x4\|i64x2\|f32x4\|f64x2)\)\.[[:alnum:]_]\+\%(\s\+\%(i8x16\|i16x8\|i32x4\|i64x2\|f32x4\|f64x2\)\)\=\>" contained display |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 29 | |
| 30 | " Identifiers |
| 31 | " https://webassembly.github.io/spec/core/text/values.html#text-id |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 32 | syn match wastNamedVar "$\+[[:alnum:]!#$%&'∗./:=><?@\\^_`~+-]*" contained contains=wastEscapeUtf8 |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 33 | syn match wastUnnamedVar "$\+\d\+[[:alnum:]!#$%&'∗./:=><?@\\^_`~+-]\@!" contained display |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 34 | " Presuming the source text is itself encoded correctly, strings that do not |
| 35 | " contain any uses of hexadecimal byte escapes are always valid names. |
| 36 | " https://webassembly.github.io/spec/core/text/values.html#names |
| 37 | syn match wastEscapedUtf8 "\\\x\{1,6}" contained containedin=wastNamedVar display |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 38 | |
| 39 | " String literals |
| 40 | " https://webassembly.github.io/spec/core/text/values.html#strings |
| 41 | syn region wastString start=+"+ skip=+\\\\\|\\"+ end=+"+ contained contains=wastStringSpecial |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 42 | syn match wastStringSpecial "\\\x\x\|\\[tnr'\\\"]\|\\u\x\+" contained containedin=wastString display |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 43 | |
| 44 | " Float literals |
| 45 | " https://webassembly.github.io/spec/core/text/values.html#floating-point |
| 46 | syn match wastFloat "\<-\=\d\%(_\=\d\)*\%(\.\d\%(_\=\d\)*\)\=\%([eE][-+]\=\d\%(_\=\d\)*\)\=" display contained |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 47 | syn match wastFloat "\<-\=0x\x\%(_\=\x\)*\%(\.\x\%(_\=\x\)*\)\=\%([pP][-+]\=\d\%(_\=\d\)*\)\=" display contained |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 48 | syn keyword wastFloat inf nan contained |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 49 | syn match wastFloat "nan:0x\x\%(_\=\x\)*" display contained |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 50 | |
| 51 | " Integer literals |
| 52 | " https://webassembly.github.io/spec/core/text/values.html#integers |
| 53 | syn match wastNumber "\<-\=\d\%(_\=\d\)*\>" display contained |
| 54 | syn match wastNumber "\<-\=0x\x\%(_\=\x\)*\>" display contained |
| 55 | |
| 56 | " Comments |
| 57 | " https://webassembly.github.io/spec/core/text/lexical.html#comments |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 58 | syn region wastComment start=";;" end="$" |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 59 | syn region wastComment start="(;;\@!" end=";)" |
| 60 | |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 61 | syn region wastList matchgroup=wastListDelimiter start="(;\@!" matchgroup=wastListDelimiter end=";\@<!)" contains=@wastNotTop |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 62 | |
| 63 | " Types |
| 64 | " https://webassembly.github.io/spec/core/text/types.html |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 65 | " Note: `mut` was changed to `const`/`var` at Wasm 2.0 |
| 66 | syn keyword wastType i64 i32 f64 f32 param result funcref func externref extern mut v128 const var contained |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 67 | syn match wastType "\%((\_s*\)\@<=func\%(\_s*[()]\)\@=" display contained |
| 68 | |
| 69 | " Modules |
| 70 | " https://webassembly.github.io/spec/core/text/modules.html |
| 71 | syn keyword wastModule module type export import table memory global data elem contained |
| 72 | syn match wastModule "\%((\_s*\)\@<=func\%(\_s\+\$\)\@=" display contained |
| 73 | |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 74 | syn sync maxlines=100 |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 75 | |
| 76 | hi def link wastModule PreProc |
| 77 | hi def link wastListDelimiter Delimiter |
| 78 | hi def link wastInstWithType Operator |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 79 | hi def link wastInstGetSet Operator |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 80 | hi def link wastInstGeneral Operator |
| 81 | hi def link wastControlInst Statement |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 82 | hi def link wastSimdInst Operator |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 83 | hi def link wastParamInst Conditional |
| 84 | hi def link wastString String |
| 85 | hi def link wastStringSpecial Special |
| 86 | hi def link wastNamedVar Identifier |
| 87 | hi def link wastUnnamedVar PreProc |
| 88 | hi def link wastFloat Float |
| 89 | hi def link wastNumber Number |
| 90 | hi def link wastComment Comment |
| 91 | hi def link wastType Type |
Linda_pp | 8f566fd | 2023-08-09 23:45:52 +0900 | [diff] [blame] | 92 | hi def link wastEscapedUtf8 Special |
Bram Moolenaar | d2855f5 | 2018-07-31 22:23:58 +0200 | [diff] [blame] | 93 | |
| 94 | let b:current_syntax = "wast" |
| 95 | |
| 96 | let &cpo = s:cpo_save |
| 97 | unlet s:cpo_save |