blob: 245d5f6f19ba8322e74929102f6592210fa60825 [file] [log] [blame]
Bram Moolenaard2855f52018-07-31 22:23:58 +02001" Vim syntax file
2" Language: WebAssembly
3" Maintainer: rhysd <lin90162@yahoo.co.jp>
4" Last Change: Jul 29, 2018
5" 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
14syn cluster wastCluster contains=wastModule,wastInstWithType,wastInstGeneral,wastParamInst,wastControlInst,wastString,wastNamedVar,wastUnnamedVar,wastFloat,wastNumber,wastComment,wastList,wastType
15
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
21" https://webassembly.github.io/spec/core/text/instructions.html#control-instructions
22syn match wastControlInst "\%((\s*\)\@<=\<\%(block\|end\|loop\|if\|else\|unreachable\|nop\|br\|br_if\|br_table\|return\|call\|call_indirect\)\>" contained display
23" https://webassembly.github.io/spec/core/text/instructions.html#parametric-instructions
24syn match wastParamInst "\%((\s*\)\@<=\<\%(drop\|select\)\>" contained display
25
26" Identifiers
27" https://webassembly.github.io/spec/core/text/values.html#text-id
28syn match wastNamedVar "$\+[[:alnum:]!#$%&'∗./:=><?@\\^_`~+-]*" contained display
29syn match wastUnnamedVar "$\+\d\+[[:alnum:]!#$%&'∗./:=><?@\\^_`~+-]\@!" contained display
30
31" String literals
32" https://webassembly.github.io/spec/core/text/values.html#strings
33syn region wastString start=+"+ skip=+\\\\\|\\"+ end=+"+ contained contains=wastStringSpecial
34syn match wastStringSpecial "\\\x\x\|\\[tnr'\\\"]\|\\u\x\+" contained containedin=wastString
35
36" Float literals
37" https://webassembly.github.io/spec/core/text/values.html#floating-point
38syn match wastFloat "\<-\=\d\%(_\=\d\)*\%(\.\d\%(_\=\d\)*\)\=\%([eE][-+]\=\d\%(_\=\d\)*\)\=" display contained
39syn match wastFloat "\<-\=0x\x\%(_\=\d\)*\%(\.\x\%(_\=\x\)*\)\=\%([pP][-+]\=\d\%(_\=\d\)*\)\=" display contained
40syn keyword wastFloat inf nan contained
41
42" Integer literals
43" https://webassembly.github.io/spec/core/text/values.html#integers
44syn match wastNumber "\<-\=\d\%(_\=\d\)*\>" display contained
45syn match wastNumber "\<-\=0x\x\%(_\=\x\)*\>" display contained
46
47" Comments
48" https://webassembly.github.io/spec/core/text/lexical.html#comments
49syn region wastComment start=";;" end="$" display
50syn region wastComment start="(;;\@!" end=";)"
51
52syn region wastList matchgroup=wastListDelimiter start="(;\@!" matchgroup=wastListDelimiter end=";\@<!)" contains=@wastCluster
53
54" Types
55" https://webassembly.github.io/spec/core/text/types.html
56syn keyword wastType i64 i32 f64 f32 param result anyfunc mut contained
57syn match wastType "\%((\_s*\)\@<=func\%(\_s*[()]\)\@=" display contained
58
59" Modules
60" https://webassembly.github.io/spec/core/text/modules.html
61syn keyword wastModule module type export import table memory global data elem contained
62syn match wastModule "\%((\_s*\)\@<=func\%(\_s\+\$\)\@=" display contained
63
64syn sync lines=100
65
66hi def link wastModule PreProc
67hi def link wastListDelimiter Delimiter
68hi def link wastInstWithType Operator
69hi def link wastInstGeneral Operator
70hi def link wastControlInst Statement
71hi def link wastParamInst Conditional
72hi def link wastString String
73hi def link wastStringSpecial Special
74hi def link wastNamedVar Identifier
75hi def link wastUnnamedVar PreProc
76hi def link wastFloat Float
77hi def link wastNumber Number
78hi def link wastComment Comment
79hi def link wastType Type
80
81let b:current_syntax = "wast"
82
83let &cpo = s:cpo_save
84unlet s:cpo_save