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