hostconf.vim 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. " Vim syntax file
  2. " Language: host.conf(5) configuration file
  3. " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
  4. " Latest Revision: 2007-06-25
  5. if exists("b:current_syntax")
  6. finish
  7. endif
  8. let s:cpo_save = &cpo
  9. set cpo&vim
  10. syn keyword hostconfTodo
  11. \ contained
  12. \ TODO
  13. \ FIXME
  14. \ XXX
  15. \ NOTE
  16. syn match hostconfComment
  17. \ display
  18. \ contained
  19. \ '\s*#.*'
  20. \ contains=hostconfTodo,
  21. \ @Spell
  22. syn match hostconfBegin
  23. \ display
  24. \ '^'
  25. \ nextgroup=hostconfComment,hostconfKeyword
  26. \ skipwhite
  27. syn keyword hostconfKeyword
  28. \ contained
  29. \ order
  30. \ nextgroup=hostconfLookupOrder
  31. \ skipwhite
  32. let s:orders = ['bind', 'hosts', 'nis']
  33. function s:permute_suffixes(list)
  34. if empty(a:list)
  35. return []
  36. elseif len(a:list) == 1
  37. return a:list[0]
  38. else
  39. let i = 0
  40. let n = len(a:list)
  41. let sub_permutations = []
  42. while i < n
  43. let list_copy = copy(a:list)
  44. let removed = list_copy[i]
  45. call remove(list_copy, i)
  46. call add(sub_permutations, [removed, s:permute_suffixes(list_copy)])
  47. let i += 1
  48. endwhile
  49. return sub_permutations
  50. endif
  51. endfunction
  52. function s:generate_suffix_groups(list_of_order_of_orders, context, trailing_context)
  53. for order_of_orders in a:list_of_order_of_orders
  54. let order = order_of_orders[0]
  55. let trailing_context = a:trailing_context . toupper(order[0]) . order[1:]
  56. let nextgroup = 'hostconfLookupOrder' . trailing_context
  57. let nextgroup_delimiter = nextgroup . 'Delimiter'
  58. let group = 'hostconfLookupOrder' . a:context
  59. execute 'syn keyword' group 'contained' order 'nextgroup=' . nextgroup_delimiter 'skipwhite'
  60. execute 'syn match' nextgroup_delimiter 'contained display "," nextgroup=' . nextgroup 'skipwhite'
  61. if a:context != ""
  62. execute 'hi def link' group 'hostconfLookupOrder'
  63. endif
  64. execute 'hi def link' nextgroup_delimiter 'hostconfLookupOrderDelimiter'
  65. let context = trailing_context
  66. if type(order_of_orders[1]) == type([])
  67. call s:generate_suffix_groups(order_of_orders[1], context, trailing_context)
  68. else
  69. execute 'syn keyword hostconfLookupOrder' . context 'contained' order_of_orders[-1]
  70. execute 'hi def link hostconfLookupOrder' . context 'hostconfLookupOrder'
  71. endif
  72. endfor
  73. endfunction
  74. call s:generate_suffix_groups(s:permute_suffixes(s:orders), "", "")
  75. delfunction s:generate_suffix_groups
  76. delfunction s:permute_suffixes
  77. syn keyword hostconfKeyword
  78. \ contained
  79. \ trim
  80. \ nextgroup=hostconfDomain
  81. \ skipwhite
  82. syn match hostconfDomain
  83. \ contained
  84. \ '\.[^:;,[:space:]]\+'
  85. \ nextgroup=hostconfDomainDelimiter
  86. \ skipwhite
  87. syn match hostconfDomainDelimiter
  88. \ contained
  89. \ display
  90. \ '[:;,]'
  91. \ nextgroup=hostconfDomain
  92. \ skipwhite
  93. syn keyword hostconfKeyword
  94. \ contained
  95. \ multi
  96. \ nospoof
  97. \ spoofalert
  98. \ reorder
  99. \ nextgroup=hostconfBoolean
  100. \ skipwhite
  101. syn keyword hostconfBoolean
  102. \ contained
  103. \ on
  104. \ off
  105. syn keyword hostconfKeyword
  106. \ contained
  107. \ spoof
  108. \ nextgroup=hostconfSpoofValue
  109. \ skipwhite
  110. syn keyword hostconfSpoofValue
  111. \ contained
  112. \ off
  113. \ nowarn
  114. \ warn
  115. hi def link hostconfTodo Todo
  116. hi def link hostconfComment Comment
  117. hi def link hostconfKeyword Keyword
  118. hi def link hostconfLookupOrder Identifier
  119. hi def link hostconfLookupOrderDelimiter Delimiter
  120. hi def link hostconfDomain String
  121. hi def link hostconfDomainDelimiter Delimiter
  122. hi def link hostconfBoolean Boolean
  123. hi def link hostconfSpoofValue hostconfBoolean
  124. let b:current_syntax = "hostconf"
  125. let &cpo = s:cpo_save
  126. unlet s:cpo_save