wast.vim 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. " 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. if exists("b:current_syntax")
  7. finish
  8. endif
  9. let s:cpo_save = &cpo
  10. set cpo&vim
  11. syn cluster wastCluster contains=wastModule,wastInstWithType,wastInstGeneral,wastParamInst,wastControlInst,wastString,wastNamedVar,wastUnnamedVar,wastFloat,wastNumber,wastComment,wastList,wastType
  12. " Instructions
  13. " https://webassembly.github.io/spec/core/text/instructions.html
  14. " Note: memarg (align=,offset=) can be added to memory instructions
  15. syn match wastInstWithType "\%((\s*\)\@<=\<\%(i32\|i64\|f32\|f64\|memory\)\.[[:alnum:]_]\+\%(/\%(i32\|i64\|f32\|f64\)\)\=\>\%(\s\+\%(align\|offset\)=\)\=" contained display
  16. syn match wastInstGeneral "\%((\s*\)\@<=\<[[:alnum:]_]\+\>" contained display
  17. " https://webassembly.github.io/spec/core/text/instructions.html#control-instructions
  18. syn match wastControlInst "\%((\s*\)\@<=\<\%(block\|end\|loop\|if\|else\|unreachable\|nop\|br\|br_if\|br_table\|return\|call\|call_indirect\)\>" contained display
  19. " https://webassembly.github.io/spec/core/text/instructions.html#parametric-instructions
  20. syn match wastParamInst "\%((\s*\)\@<=\<\%(drop\|select\)\>" contained display
  21. " Identifiers
  22. " https://webassembly.github.io/spec/core/text/values.html#text-id
  23. syn match wastNamedVar "$\+[[:alnum:]!#$%&'∗./:=><?@\\^_`~+-]*" contained display
  24. syn match wastUnnamedVar "$\+\d\+[[:alnum:]!#$%&'∗./:=><?@\\^_`~+-]\@!" contained display
  25. " String literals
  26. " https://webassembly.github.io/spec/core/text/values.html#strings
  27. syn region wastString start=+"+ skip=+\\\\\|\\"+ end=+"+ contained contains=wastStringSpecial
  28. syn match wastStringSpecial "\\\x\x\|\\[tnr'\\\"]\|\\u\x\+" contained containedin=wastString
  29. " Float literals
  30. " https://webassembly.github.io/spec/core/text/values.html#floating-point
  31. syn match wastFloat "\<-\=\d\%(_\=\d\)*\%(\.\d\%(_\=\d\)*\)\=\%([eE][-+]\=\d\%(_\=\d\)*\)\=" display contained
  32. syn match wastFloat "\<-\=0x\x\%(_\=\d\)*\%(\.\x\%(_\=\x\)*\)\=\%([pP][-+]\=\d\%(_\=\d\)*\)\=" display contained
  33. syn keyword wastFloat inf nan contained
  34. " Integer literals
  35. " https://webassembly.github.io/spec/core/text/values.html#integers
  36. syn match wastNumber "\<-\=\d\%(_\=\d\)*\>" display contained
  37. syn match wastNumber "\<-\=0x\x\%(_\=\x\)*\>" display contained
  38. " Comments
  39. " https://webassembly.github.io/spec/core/text/lexical.html#comments
  40. syn region wastComment start=";;" end="$" display
  41. syn region wastComment start="(;;\@!" end=";)"
  42. syn region wastList matchgroup=wastListDelimiter start="(;\@!" matchgroup=wastListDelimiter end=";\@<!)" contains=@wastCluster
  43. " Types
  44. " https://webassembly.github.io/spec/core/text/types.html
  45. syn keyword wastType i64 i32 f64 f32 param result anyfunc mut contained
  46. syn match wastType "\%((\_s*\)\@<=func\%(\_s*[()]\)\@=" display contained
  47. " Modules
  48. " https://webassembly.github.io/spec/core/text/modules.html
  49. syn keyword wastModule module type export import table memory global data elem contained
  50. syn match wastModule "\%((\_s*\)\@<=func\%(\_s\+\$\)\@=" display contained
  51. syn sync lines=100
  52. hi def link wastModule PreProc
  53. hi def link wastListDelimiter Delimiter
  54. hi def link wastInstWithType Operator
  55. hi def link wastInstGeneral Operator
  56. hi def link wastControlInst Statement
  57. hi def link wastParamInst Conditional
  58. hi def link wastString String
  59. hi def link wastStringSpecial Special
  60. hi def link wastNamedVar Identifier
  61. hi def link wastUnnamedVar PreProc
  62. hi def link wastFloat Float
  63. hi def link wastNumber Number
  64. hi def link wastComment Comment
  65. hi def link wastType Type
  66. let b:current_syntax = "wast"
  67. let &cpo = s:cpo_save
  68. unlet s:cpo_save