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