blob: 113d65c5a1735cc8978159ccdfb0eb8030fc433c [file] [log] [blame]
Bram Moolenaard2855f52018-07-31 22:23:58 +02001" Vim syntax file
2" Language: WebAssembly
3" Maintainer: rhysd <lin90162@yahoo.co.jp>
Linda_pp8f566fd2023-08-09 23:45:52 +09004" Last Change: Aug 7, 2023
Bram Moolenaard2855f52018-07-31 22:23:58 +02005" For bugs, patches and license go to https://github.com/rhysd/vim-wasm
6
7if exists("b:current_syntax")
8 finish
9endif
10
11let s:cpo_save = &cpo
12set cpo&vim
13
Linda_pp8f566fd2023-08-09 23:45:52 +090014syn cluster wastNotTop contains=wastModule,wastInstWithType,wastInstGetSet,wastInstGeneral,wastParamInst,wastControlInst,wastSimdInst,wastString,wastNamedVar,wastUnnamedVar,wastFloat,wastNumber,wastComment,wastList,wastType
Bram Moolenaard2855f52018-07-31 22:23:58 +020015
16" Instructions
17" https://webassembly.github.io/spec/core/text/instructions.html
18" Note: memarg (align=,offset=) can be added to memory instructions
19syn match wastInstWithType "\%((\s*\)\@<=\<\%(i32\|i64\|f32\|f64\|memory\)\.[[:alnum:]_]\+\%(/\%(i32\|i64\|f32\|f64\)\)\=\>\%(\s\+\%(align\|offset\)=\)\=" contained display
20syn match wastInstGeneral "\%((\s*\)\@<=\<[[:alnum:]_]\+\>" contained display
Linda_pp8f566fd2023-08-09 23:45:52 +090021syn match wastInstGetSet "\%((\s*\)\@<=\<\%(local\|global\)\.\%(get\|set\)\>" contained display
Bram Moolenaard2855f52018-07-31 22:23:58 +020022" https://webassembly.github.io/spec/core/text/instructions.html#control-instructions
Linda_pp8f566fd2023-08-09 23:45:52 +090023syn match wastControlInst "\%((\s*\)\@<=\<\%(block\|end\|loop\|if\|then\|else\|unreachable\|nop\|br\|br_if\|br_table\|return\|call\|call_indirect\)\>" contained display
Bram Moolenaard2855f52018-07-31 22:23:58 +020024" https://webassembly.github.io/spec/core/text/instructions.html#parametric-instructions
25syn match wastParamInst "\%((\s*\)\@<=\<\%(drop\|select\)\>" contained display
Linda_pp8f566fd2023-08-09 23:45:52 +090026" SIMD instructions
27" https://webassembly.github.io/simd/core/text/instructions.html#simd-instructions
28syn match wastSimdInst "\<\%(v128\|i8x16\|i16x8\|i32x4\|i64x2\|f32x4\|f64x2)\)\.[[:alnum:]_]\+\%(\s\+\%(i8x16\|i16x8\|i32x4\|i64x2\|f32x4\|f64x2\)\)\=\>" contained display
Bram Moolenaard2855f52018-07-31 22:23:58 +020029
30" Identifiers
31" https://webassembly.github.io/spec/core/text/values.html#text-id
Linda_pp8f566fd2023-08-09 23:45:52 +090032syn match wastNamedVar "$\+[[:alnum:]!#$%&'∗./:=><?@\\^_`~+-]*" contained contains=wastEscapeUtf8
Bram Moolenaard2855f52018-07-31 22:23:58 +020033syn match wastUnnamedVar "$\+\d\+[[:alnum:]!#$%&'∗./:=><?@\\^_`~+-]\@!" contained display
Linda_pp8f566fd2023-08-09 23:45:52 +090034" 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
37syn match wastEscapedUtf8 "\\\x\{1,6}" contained containedin=wastNamedVar display
Bram Moolenaard2855f52018-07-31 22:23:58 +020038
39" String literals
40" https://webassembly.github.io/spec/core/text/values.html#strings
41syn region wastString start=+"+ skip=+\\\\\|\\"+ end=+"+ contained contains=wastStringSpecial
Linda_pp8f566fd2023-08-09 23:45:52 +090042syn match wastStringSpecial "\\\x\x\|\\[tnr'\\\"]\|\\u\x\+" contained containedin=wastString display
Bram Moolenaard2855f52018-07-31 22:23:58 +020043
44" Float literals
45" https://webassembly.github.io/spec/core/text/values.html#floating-point
46syn match wastFloat "\<-\=\d\%(_\=\d\)*\%(\.\d\%(_\=\d\)*\)\=\%([eE][-+]\=\d\%(_\=\d\)*\)\=" display contained
Linda_pp8f566fd2023-08-09 23:45:52 +090047syn match wastFloat "\<-\=0x\x\%(_\=\x\)*\%(\.\x\%(_\=\x\)*\)\=\%([pP][-+]\=\d\%(_\=\d\)*\)\=" display contained
Bram Moolenaard2855f52018-07-31 22:23:58 +020048syn keyword wastFloat inf nan contained
Linda_pp8f566fd2023-08-09 23:45:52 +090049syn match wastFloat "nan:0x\x\%(_\=\x\)*" display contained
Bram Moolenaard2855f52018-07-31 22:23:58 +020050
51" Integer literals
52" https://webassembly.github.io/spec/core/text/values.html#integers
53syn match wastNumber "\<-\=\d\%(_\=\d\)*\>" display contained
54syn match wastNumber "\<-\=0x\x\%(_\=\x\)*\>" display contained
55
56" Comments
57" https://webassembly.github.io/spec/core/text/lexical.html#comments
Linda_pp8f566fd2023-08-09 23:45:52 +090058syn region wastComment start=";;" end="$"
Bram Moolenaard2855f52018-07-31 22:23:58 +020059syn region wastComment start="(;;\@!" end=";)"
60
Linda_pp8f566fd2023-08-09 23:45:52 +090061syn region wastList matchgroup=wastListDelimiter start="(;\@!" matchgroup=wastListDelimiter end=";\@<!)" contains=@wastNotTop
Bram Moolenaard2855f52018-07-31 22:23:58 +020062
63" Types
64" https://webassembly.github.io/spec/core/text/types.html
Linda_pp8f566fd2023-08-09 23:45:52 +090065" Note: `mut` was changed to `const`/`var` at Wasm 2.0
66syn keyword wastType i64 i32 f64 f32 param result funcref func externref extern mut v128 const var contained
Bram Moolenaard2855f52018-07-31 22:23:58 +020067syn match wastType "\%((\_s*\)\@<=func\%(\_s*[()]\)\@=" display contained
68
69" Modules
70" https://webassembly.github.io/spec/core/text/modules.html
71syn keyword wastModule module type export import table memory global data elem contained
72syn match wastModule "\%((\_s*\)\@<=func\%(\_s\+\$\)\@=" display contained
73
Linda_pp8f566fd2023-08-09 23:45:52 +090074syn sync maxlines=100
Bram Moolenaard2855f52018-07-31 22:23:58 +020075
76hi def link wastModule PreProc
77hi def link wastListDelimiter Delimiter
78hi def link wastInstWithType Operator
Linda_pp8f566fd2023-08-09 23:45:52 +090079hi def link wastInstGetSet Operator
Bram Moolenaard2855f52018-07-31 22:23:58 +020080hi def link wastInstGeneral Operator
81hi def link wastControlInst Statement
Linda_pp8f566fd2023-08-09 23:45:52 +090082hi def link wastSimdInst Operator
Bram Moolenaard2855f52018-07-31 22:23:58 +020083hi def link wastParamInst Conditional
84hi def link wastString String
85hi def link wastStringSpecial Special
86hi def link wastNamedVar Identifier
87hi def link wastUnnamedVar PreProc
88hi def link wastFloat Float
89hi def link wastNumber Number
90hi def link wastComment Comment
91hi def link wastType Type
Linda_pp8f566fd2023-08-09 23:45:52 +090092hi def link wastEscapedUtf8 Special
Bram Moolenaard2855f52018-07-31 22:23:58 +020093
94let b:current_syntax = "wast"
95
96let &cpo = s:cpo_save
97unlet s:cpo_save