toml.vim 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. " Vim syntax file
  2. " Language: TOML
  3. " Homepage: https://github.com/cespare/vim-toml
  4. " Maintainer: Aman Verma
  5. " Previous Maintainer: Caleb Spare <cespare@gmail.com>
  6. " Last Change: Oct 8, 2021
  7. if exists('b:current_syntax')
  8. finish
  9. endif
  10. syn match tomlEscape /\\[btnfr"/\\]/ display contained
  11. syn match tomlEscape /\\u\x\{4}/ contained
  12. syn match tomlEscape /\\U\x\{8}/ contained
  13. syn match tomlLineEscape /\\$/ contained
  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. syn match tomlInteger /[+-]\=\<[1-9]\(_\=\d\)*\>/ display
  23. syn match tomlInteger /[+-]\=\<0\>/ display
  24. syn match tomlInteger /[+-]\=\<0x[[:xdigit:]]\(_\=[[:xdigit:]]\)*\>/ display
  25. syn match tomlInteger /[+-]\=\<0o[0-7]\(_\=[0-7]\)*\>/ display
  26. syn match tomlInteger /[+-]\=\<0b[01]\(_\=[01]\)*\>/ display
  27. syn match tomlInteger /[+-]\=\<\(inf\|nan\)\>/ display
  28. syn match tomlFloat /[+-]\=\<\d\(_\=\d\)*\.\d\+\>/ display
  29. syn match tomlFloat /[+-]\=\<\d\(_\=\d\)*\(\.\d\(_\=\d\)*\)\=[eE][+-]\=\d\(_\=\d\)*\>/ display
  30. syn match tomlBoolean /\<\%(true\|false\)\>/ display
  31. " https://tools.ietf.org/html/rfc3339
  32. syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}/ display
  33. syn match tomlDate /\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?/ display
  34. syn match tomlDate /\d\{4\}-\d\{2\}-\d\{2\}[T ]\d\{2\}:\d\{2\}:\d\{2\}\%(\.\d\+\)\?\%(Z\|[+-]\d\{2\}:\d\{2\}\)\?/ display
  35. syn match tomlDotInKey /\v[^.]+\zs\./ contained display
  36. syn match tomlKey /\v(^|[{,])\s*\zs[[:alnum:]._-]+\ze\s*\=/ contains=tomlDotInKey display
  37. syn region tomlKeyDq oneline start=/\v(^|[{,])\s*\zs"/ end=/"\ze\s*=/ contains=tomlEscape
  38. syn region tomlKeySq oneline start=/\v(^|[{,])\s*\zs'/ end=/'\ze\s*=/
  39. syn region tomlTable oneline start=/^\s*\[[^\[]/ end=/\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey
  40. syn region tomlTableArray oneline start=/^\s*\[\[/ end=/\]\]/ contains=tomlKey,tomlKeyDq,tomlKeySq,tomlDotInKey
  41. syn region tomlKeyValueArray start=/=\s*\[\zs/ end=/\]/ contains=@tomlValue
  42. syn region tomlArray start=/\[/ end=/\]/ contains=@tomlValue contained
  43. syn cluster tomlValue contains=tomlArray,tomlString,tomlInteger,tomlFloat,tomlBoolean,tomlDate,tomlComment
  44. syn keyword tomlTodo TODO FIXME XXX BUG contained
  45. syn match tomlComment /#.*/ contains=@Spell,tomlTodo
  46. hi def link tomlComment Comment
  47. hi def link tomlTodo Todo
  48. hi def link tomlTableArray Title
  49. hi def link tomlTable Title
  50. hi def link tomlDotInKey Normal
  51. hi def link tomlKeySq Identifier
  52. hi def link tomlKeyDq Identifier
  53. hi def link tomlKey Identifier
  54. hi def link tomlDate Constant
  55. hi def link tomlBoolean Boolean
  56. hi def link tomlFloat Float
  57. hi def link tomlInteger Number
  58. hi def link tomlString String
  59. hi def link tomlLineEscape SpecialChar
  60. hi def link tomlEscape SpecialChar
  61. syn sync minlines=500
  62. let b:current_syntax = 'toml'
  63. " vim: et sw=2 sts=2