toml.vim 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. " Language: TOML
  2. " Maintainer: Caleb Spare <cespare@gmail.com>
  3. " URL: https://github.com/cespare/vim-toml
  4. " LICENSE: MIT
  5. if exists("b:current_syntax")
  6. finish
  7. endif
  8. syn match tomlEscape /\\[btnfr"/\\]/ display contained
  9. syn match tomlEscape /\\u\x\{4}/ contained
  10. syn match tomlEscape /\\U\x\{8}/ contained
  11. hi def link tomlEscape SpecialChar
  12. syn match tomlLineEscape /\\$/ contained
  13. hi def link tomlLineEscape SpecialChar
  14. " Basic strings
  15. syn region tomlString oneline start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=tomlEscape
  16. " Multi-line basic strings
  17. syn region tomlString start=/"""/ end=/"""/ contains=tomlEscape,tomlLineEscape
  18. " Literal strings
  19. syn region tomlString oneline start=/'/ end=/'/
  20. " Multi-line literal strings
  21. syn region tomlString start=/'''/ end=/'''/
  22. hi def link tomlString String
  23. syn match tomlInteger /[+-]\=\<[1-9]\(_\=\d\)*\>/ display
  24. syn match tomlInteger /[+-]\=\<0\>/ display
  25. syn match tomlInteger /[+-]\=\<0x[[:xdigit:]]\(_\=[[:xdigit:]]\)*\>/ display
  26. syn match tomlInteger /[+-]\=\<0o[0-7]\(_\=[0-7]\)*\>/ display
  27. syn match tomlInteger /[+-]\=\<0b[01]\(_\=[01]\)*\>/ display
  28. syn match tomlInteger /[+-]\=\<\(inf\|nan\)\>/ display
  29. hi def link tomlInteger Number
  30. syn match tomlFloat /[+-]\=\<\d\(_\=\d\)*\.\d\+\>/ display
  31. syn match tomlFloat /[+-]\=\<\d\(_\=\d\)*\(\.\d\(_\=\d\)*\)\=[eE][+-]\=\d\(_\=\d\)*\>/ display
  32. hi def link tomlFloat Float
  33. syn match tomlBoolean /\<\%(true\|false\)\>/ display
  34. hi def link tomlBoolean Boolean
  35. " https://tools.ietf.org/html/rfc3339
  36. syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}/ display
  37. syn match tomlDate /\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?/ display
  38. syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}[T ]\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?\%(Z\|[+-]\d\{2\}:\d\{2\}\)\?/ display
  39. hi def link tomlDate Constant
  40. syn match tomlKey /\v(^|[{,])\s*\zs[[:alnum:]._-]+\ze\s*\=/ display
  41. hi def link tomlKey Identifier
  42. syn region tomlKeyDq oneline start=/\v(^|[{,])\s*\zs"/ end=/"\ze\s*=/ contains=tomlEscape
  43. hi def link tomlKeyDq Identifier
  44. syn region tomlKeySq oneline start=/\v(^|[{,])\s*\zs'/ end=/'\ze\s*=/
  45. hi def link tomlKeySq Identifier
  46. syn region tomlTable oneline start=/^\s*\[[^\[]/ end=/\]/ contains=tomlKey,tomlKeyDq,tomlKeySq
  47. hi def link tomlTable Title
  48. syn region tomlTableArray oneline start=/^\s*\[\[/ end=/\]\]/ contains=tomlKey,tomlKeyDq,tomlKeySq
  49. hi def link tomlTableArray Title
  50. syn cluster tomlValue contains=tomlArray,tomlString,tomlInteger,tomlFloat,tomlBoolean,tomlDate,tomlComment
  51. syn region tomlKeyValueArray start=/=\s*\[\zs/ end=/\]/ contains=@tomlValue
  52. syn region tomlArray start=/\[/ end=/\]/ contains=@tomlValue contained
  53. syn keyword tomlTodo TODO FIXME XXX BUG contained
  54. hi def link tomlTodo Todo
  55. syn match tomlComment /#.*/ contains=@Spell,tomlTodo
  56. hi def link tomlComment Comment
  57. syn sync minlines=500
  58. let b:current_syntax = "toml"