]> granicus.if.org Git - icinga2/blob - tools/syntax/vim/syntax/icinga2.vim
Fix VIM syntax highlighting for comments
[icinga2] / tools / syntax / vim / syntax / icinga2.vim
1 " Vim syntax file
2 " Filename:             icinga2.vim
3 " Language:             Icinga2 object configuration file
4 " Author:               Carlos Cesario <carloscesario@gmail.com>
5 " Version:              0.0.2
6 " Based:                javascript.vim / nagios.vim
7
8 " For version 5.x: Clear all syntax items
9 " For version 6.x: Quit when a syntax file was already loaded
10 if !exists("main_syntax")
11         if version < 600
12                 syntax clear
13         elseif exists("b:current_syntax")
14                 finish
15         endif
16         let main_syntax = 'icinga2'
17 endif
18
19
20 " case off
21 syntax case ignore
22
23 " comments
24 syn keyword             icinga2CommentTodo              TODO FIXME XXX TBD contained
25 syn match               icinga2LineComment              "\/\/.*" contains=icinga2CommentTodo
26 syn match               icinga2LineComment              "#.*" contains=icinga2CommentTodo
27 syn match               icinga2CommentSkip              "^[ \t]*\*\($\|[ \t]\+\)"
28 syn region              icinga2Comment                  start="/\*"  end="\*/" contains=icinga2CommentTodo
29
30 " type definitions
31 " - double quotes "
32 " - single quotes '
33 " - brackets <>
34
35 syn region              StringD                 start=+"+  end=+"\|$+
36 syn region              StringS                 start=+'+  end=+'\|$+
37 syn match               angleBrackets   "<\w\+>"
38
39
40 " Braces and Parens definition
41 " Braces are used in dictionary definition
42
43 syn match               Braces          "[{}\[\]]"
44 syn match               Parens          "[()]"
45
46
47 " objects types
48 syn match               icinga2ObjDef           "object[ \t]\+\(hostgroup\|host\|service\|servicegroup\|user\|usergroup\)"
49 syn match               icinga2ObjDef           "object[ \t]\+\(checkcommand\|notificationcommand\|eventcommand\|notification\)"
50 syn match               icinga2Objdef           "object[ \t]\+\(timeperiod\|scheduleddowntime\|dependency\|perfdatawriter\)"
51 syn match               icinga2ObjDef           "object[ \t]\+\(graphitewriter\|idomysqlconnection\|idomysqlconnection\)"
52 syn match               icinga2ObjDef           "object[ \t]\+\(livestatuslistener\|statusdatawriter\|externalcommandlistener\)"
53 syn match               icinga2ObjDef           "object[ \t]\+\(compatlogger\|checkresultreader\|checkcomponent\|notificationcomponent\)"
54 syn match               icinga2ObjDef           "object[ \t]\+\(filelogger\|sysloglogger\|icingastatuswriter\|apilistener\|endpoint\|zone\)"
55
56
57 " apply def
58 syn match               icinga2ApplyDef         "apply[ \t]\+\(Service\|Dependency\|Notification\|ScheduledDowntime\)"
59
60
61 " objects attributes
62 syn keyword             icinga2ObjAttr          contained       accept_commands accept_config action_url address address6 arguments author bind_host
63 syn keyword             icinga2ObjAttr          contained       bind_port ca_path categories cert_path check_command check_interval
64 syn keyword             icinga2ObjAttr          contained       check_period child_host_name child_service_name cleanup command command_endpoint command_path
65 syn keyword             icinga2ObjAttr          contained       comment compat_log_path crl_path database disable_checks disable_notifications
66 syn keyword             icinga2ObjAttr          contained       display_name duration email enable_active_checks enable_event_handler
67 syn keyword             icinga2ObjAttr          contained       enable_flapping enable_ha enable_notifications enable_passive_checks enable_perfdata
68 syn keyword             icinga2ObjAttr          contained       endpoints env event_command failover_timeout fixed flapping_threshold groups host
69 syn keyword             icinga2ObjAttr          contained       host_format_template host_name host_name_template host_perfdata_path host_temp_path icon_image
70 syn keyword             icinga2ObjAttr          contained       icon_image_alt instance_description instance_name interval key_path log_dir
71 syn keyword             icinga2ObjAttr          contained       log_duration max_check_attempts methods name notes notes_url objects_path
72 syn keyword             icinga2ObjAttr          contained       pager parent parent_host_name parent_service_name password path period
73 syn keyword             icinga2ObjAttr          contained       port ranges retry_interval rotation_interval rotation_method
74 syn keyword             icinga2ObjAttr          contained       service_format_template service_name service_name_template service_perfdata_path service_temp_path
75 syn keyword             icinga2ObjAttr          contained       severity socket_path socket_type spool_dir states status_path table_prefix
76 syn keyword             icinga2ObjAttr          contained       timeout times types update_interval user user_groups users volatile zone
77 syn match               icinga2ObjAttr          contained       "\(vars.\w\+\)"
78
79
80 " keywords
81 syn keyword             icinga2Keyword          template const import include include_recursive var function
82
83
84 " Assign conditions
85 syn match               icinga2AssingCond       contained       "\(assign[ \t]\+\where\|ignore[ \t]\+\where\)"
86
87
88 " Global functions
89 syn keyword             icinga2GFunction        contained       regex match len union intersection keys string
90 syn keyword     icinga2GFunction        contained       number bool random log typeof get_time exit
91
92
93 " Accessor Functions
94 syn keyword     icinga2AFunction        contained       get_host get_service get_user get_check_command get_event_command get_notification_command
95 syn keyword     icinga2AFunction        contained       get_host_group get_service_group get_user_group get_time_period
96
97
98 " Math functions
99 syn match       icinga2MathFunction     contained       "\(Math.E\|Math.LN2\|Math.LN10\|Math.LOG2E\|Math.PI\|Math.SQRT1_2\|Math.SQRT2\)"
100 syn match       icinga2MathFunction     contained       "\(Math.abs\|Math.acos\|Math.asin\|Math.atan\|Math.atan2\|Math.ceil\|Math.cos\)"
101 syn match       icinga2MathFunction     contained       "\(Math.exp\|Math.floor\|Math.isinf\|Math.isnan\|Math.log\|Math.max\|Math.min\)"
102 syn match       icinga2MathFunction     contained       "\(Math.pow\|Math.random\|Math.round\|Math.sign\|Math.sin\|Math.sqrt\|Math.tan\)"
103
104 " Json functions
105 syn match       icinga2JsonFunction             contained       "\(Json.encode\|Json.decode\)"
106
107 " String functions
108 syn match       icinga2StrFunction      contained       "\(\.to_string\)"
109 syn match       icinga2StrFunction      contained       "\(\.find\)"
110 syn match       icinga2StrFunction      contained       "\(\.contains\)"
111 syn match       icinga2StrFunction      contained       "\(\.len\)"
112 syn match       icinga2StrFunction      contained       "\(\.lower\)"
113 syn match       icinga2StrFunction      contained       "\(\.upper\)"
114 syn match       icinga2StrFunction      contained       "\(\.replace\)"
115 syn match       icinga2StrFunction      contained       "\(\.split\)"
116 syn match       icinga2StrFunction      contained       "\(\.substr\)"
117
118 " Array and Dict  Functions
119 syn match       icinga2ArrFunction      contained       "\(\.add\)"
120 syn match       icinga2ArrFunction      contained       "\(\.clear\)"
121 syn match       icinga2ArrFunction      contained       "\(\.clone\)"
122 syn match       icinga2ArrFunction      contained       "\(\.contains\)"
123 syn match       icinga2ArrFunction      contained       "\(\.len\)"
124 syn match       icinga2ArrFunction      contained       "\(\.remove\)"
125 syn match       icinga2ArrFunction      contained       "\(\.set\)"
126 syn match       icinga2ArrFunction      contained       "\(\.remove\)"
127 syn match       icinga2ArrFunction      contained       "\(\.sort\)"
128 syn match       icinga2ArrFunction      contained       "\(\.join\)"
129 syn match       icinga2ArrFunction      contained       "\(\.clone\)"
130 syn match       icinga2ArrFunction      contained       "\(\.call\)"
131 syn match       icinga2ArrFunction      contained       "\(\.callv\)"
132
133
134 " Conditional statements
135 syn keyword     icinga2Cond                     if else
136
137 " Loops
138 syn keyword     icinga2Loop                     while for break continue
139
140 " Operators
141 syn  match         icinga2Operators "[ \t]\+\(\.\)\+"
142 syn  match         icinga2Operators "[ \t]\+\(!\)\+"
143 syn  match         icinga2Operators "[ \t]\+\(\~\)\+"
144 syn  match         icinga2Operators "[ \t]\+\(+\)\+"
145 syn  match         icinga2Operators "[ \t]\+\(-\)\+"
146 syn  match         icinga2Operators "[ \t]\+\(*\)\+"
147 syn  match         icinga2Operators "[ \t]\+\(/[^/\*]\)\+"
148 syn  match         icinga2Operators "[ \t]\+\(%\)\+"
149 syn  match         icinga2Operators "[ \t]\+\(+\)\+"
150 syn  match         icinga2Operators "[ \t]\+\(-\)\+"
151 syn  match         icinga2Operators "[ \t]\+\(=\)\+"
152 syn  match         icinga2Operators "[ \t]\+\(<\)[ \t]\+"
153 syn  match         icinga2Operators "[ \t]\+\(>\)[ \t]\+"
154 syn  match         icinga2Operators "[ \t]\+\(<<\)\+"
155 syn  match         icinga2Operators "[ \t]\+\(>>\)\+"
156 syn  match         icinga2Operators "[ \t]\+\(<=\)\+"
157 syn  match         icinga2Operators "[ \t]\+\(>=\)\+"
158 syn  match         icinga2Operators "[ \t]\+\(in\)\+"
159 syn  match         icinga2Operators "[ \t]\+\(!in\)\+"
160 syn  match         icinga2Operators "[ \t]\+\(==\)\+"
161 syn  match         icinga2Operators "[ \t]\+\(!=\)\+"
162 syn  match         icinga2Operators "[ \t]\+\(&\)\+"
163 syn  match         icinga2Operators "[ \t]\+\(\^\)\+"
164 syn  match         icinga2Operators "[ \t]\+\(|\)\+"
165 syn  match         icinga2Operators "[ \t]\+\(&&\)\+"
166 syn  match         icinga2Operators "[ \t]\+\(||\)\+"
167 syn  match         icinga2Operators "[ \t]\+\(=>\)\+"
168 syn  match         icinga2Operators "[ \t]\+\(+=\)\+"
169 syn  match         icinga2Operators "[ \t]\+\(-=\)\+"
170 syn  match         icinga2Operators "[ \t]\+\(*=\)\+"
171 syn  match         icinga2Operators "[ \t]\+\(/=\)\+"
172
173 " global constats
174 syn keyword     icinga2Gconst           PrefixDir SysconfDir ZonesDir LocalStateDir RunDir PkgDataDir StatePath ObjectsPath
175 syn keyword     icinga2Gconst           PidPath NodeName ApplicationType EnableNotifications EnableEventHandlers EnableFlapping
176 syn keyword     icinga2Gconst           EnableHostChecks EnableServiceChecks EnablePerfdata UseVfork RunAsUser RunAsGroup PluginDir
177 syn     match           icinga2Gconst           "\(Vars[ \t]\+\)"
178
179 " values type
180 syn keyword             valueBoolean            contained       true false
181 syn keyword             valueNull                       contained       null
182
183
184
185 syn region              nagiosDefBody start='{' end='}'
186         \ contains=icinga2Comment, icinga2LineComment, StringD, Braces, Parens, icinga2ObjDef,
187         \ icinga2ApplyDef, icinga2ObjAttr, icinga2Keyword, icinga2Keyword, icinga2AssignCond,
188         \ icinga2Cond, icinga2Loop, icinga2Operators, icinga2GFunction, icinga2AFunction,
189         \ icinga2MathFunction, icinga2Gconst, icinga2JsonFunction, icinga2StrFunction,
190         \ icinga2ArrFunction, valueBoolean, valueNull
191
192
193 " Highlighting
194 hi link icinga2Comment                          Comment
195 hi link icinga2LineComment                      Comment
196 hi link icinga2CommentTodo                      Todo
197
198 hi link Braces                                          Function
199 hi link Parens                                          Function
200
201 hi link StringS                                         String
202 hi link StringD                                         String
203 hi link angleBrackets                           String
204
205 hi link icinga2ObjDef                           Statement
206 hi link icinga2ApplyDef                         Statement
207 hi link icinga2ObjAttr                          Define
208 hi link icinga2Keyword                          Keyword
209
210 hi link icinga2AssignCond                       Conditional
211
212 hi link icinga2Cond                                     Statement
213 hi link icinga2Loop                                     Statement
214 hi link icinga2Operators                        Operator
215
216 hi link icinga2AFunction                        Function
217 hi link icinga2MathFunction                     Function
218 hi link icinga2GFunction                        Function
219 hi link icinga2JsonFunction                     Function
220 hi link icinga2StrFunction                      Function
221 hi link icinga2ArrFunction                      Function
222
223
224 hi link icinga2Gconst                           Statement
225
226 hi link valueBoolean                            Boolean
227 hi link valueNull                                       Special