build: set version to 0.5
[vis.git] / lua / lexers / systemd.lua
blob5f9e618f15ec577b6bceade05b834f97f3c78f45
1 -- Copyright 2016 Christian Hesse
2 -- systemd unit file LPeg lexer.
4 local l = require('lexer')
5 local token, word_match = l.token, l.word_match
6 local P, R, S = lpeg.P, lpeg.R, lpeg.S
8 local M = {_NAME = 'systemd'}
10 -- Whitespace.
11 local ws = token(l.WHITESPACE, l.space^1)
13 -- Comments.
14 local comment = token(l.COMMENT, l.starts_line(S(';#')) * l.nonnewline^0)
16 -- Strings.
17 local sq_str = l.delimited_range("'")
18 local dq_str = l.delimited_range('"')
19 local section_word = word_match{
20 'Automount',
21 'BusName',
22 'Install',
23 'Mount',
24 'Path',
25 'Service',
26 'Service',
27 'Socket',
28 'Timer',
29 'Unit'
31 local string = token(l.STRING, sq_str + dq_str + '[' * section_word * ']')
33 -- Numbers.
34 local dec = l.digit^1 * ('_' * l.digit^1)^0
35 local oct_num = '0' * S('01234567_')^1
36 local integer = S('+-')^-1 * (l.hex_num + oct_num + dec)
37 local number = token(l.NUMBER, (l.float + integer))
39 -- Keywords.
40 local keyword = token(l.KEYWORD, word_match({
41 -- boolean values
42 'true',
43 'false',
44 'on',
45 'off',
46 'yes',
47 'no',
49 -- service types
50 'forking',
51 'simple',
52 'oneshot',
53 'dbus',
54 'notify',
55 'idle',
57 -- special system units
58 'basic.target',
59 'ctrl-alt-del.target',
60 'cryptsetup.target',
61 'dbus.service',
62 'dbus.socket',
63 'default.target',
64 'display-manager.service',
65 'emergency.target',
66 'exit.target',
67 'final.target',
68 'getty.target',
69 'graphical.target',
70 'hibernate.target',
71 'hybrid-sleep.target',
72 'halt.target',
73 'initrd-fs.target',
74 'kbrequest.target',
75 'kexec.target',
76 'local-fs.target',
77 'multi-user.target',
78 'network-online.target',
79 'paths.target',
80 'poweroff.target',
81 'reboot.target',
82 'remote-fs.target',
83 'rescue.target',
84 'initrd-root-fs.target',
85 'runlevel2.target',
86 'runlevel3.target',
87 'runlevel4.target',
88 'runlevel5.target',
89 'shutdown.target',
90 'sigpwr.target',
91 'sleep.target',
92 'slices.target',
93 'sockets.target',
94 'suspend.target',
95 'swap.target',
96 'sysinit.target',
97 'syslog.socket',
98 'system-update.target',
99 'timers.target',
100 'umount.target',
102 -- special system units for devices
103 'bluetooth.target',
104 'printer.target',
105 'smartcard.target',
106 'sound.target',
108 -- special passive system units
109 'cryptsetup-pre.target',
110 'local-fs-pre.target',
111 'network.target',
112 'network-pre.target',
113 'nss-lookup.target',
114 'nss-user-lookup.target',
115 'remote-fs-pre.target',
116 'rpcbind.target',
117 'time-sync.target',
119 -- specail slice units
120 '-.slice',
121 'system.slice',
122 'user.slice',
123 'machine.slice',
125 -- environment variables
126 'PATH',
127 'LANG',
128 'USER',
129 'LOGNAME',
130 'HOME',
131 'SHELL',
132 'XDG_RUNTIME_DIR',
133 'XDG_SESSION_ID',
134 'XDG_SEAT',
135 'XDG_VTNR',
136 'MAINPID',
137 'MANAGERPID',
138 'LISTEN_FDS',
139 'LISTEN_PID',
140 'LISTEN_FDNAMES',
141 'NOTIFY_SOCKET',
142 'WATCHDOG_PID',
143 'WATCHDOG_USEC',
144 'TERM'
145 }, '.-'))
147 -- Options.
148 local option_word = word_match{
149 -- unit section options
150 'Description',
151 'Documentation',
152 'Requires',
153 'Requisite',
154 'Wants',
155 'BindsTo',
156 'PartOf',
157 'Conflicts',
158 'Before',
159 'After',
160 'OnFailure',
161 'PropagatesReloadTo',
162 'ReloadPropagatedFrom',
163 'JoinsNamespaceOf',
164 'RequiresMountsFor',
165 'OnFailureJobMode',
166 'IgnoreOnIsolate',
167 'StopWhenUnneeded',
168 'RefuseManualStart',
169 'RefuseManualStop',
170 'AllowIsolate',
171 'DefaultDependencies',
172 'JobTimeoutSec',
173 'JobTimeoutAction',
174 'JobTimeoutRebootArgument',
175 'StartLimitInterval',
176 'StartLimitBurst',
177 'StartLimitAction',
178 'RebootArgument',
179 'ConditionArchitecture',
180 'ConditionVirtualization',
181 'ConditionHost',
182 'ConditionKernelCommandLine',
183 'ConditionSecurity',
184 'ConditionCapability',
185 'ConditionACPower',
186 'ConditionNeedsUpdate',
187 'ConditionFirstBoot',
188 'ConditionPathExists',
189 'ConditionPathExistsGlob',
190 'ConditionPathIsDirectory',
191 'ConditionPathIsSymbolicLink',
192 'ConditionPathIsMountPoint',
193 'ConditionPathIsReadWrite',
194 'ConditionDirectoryNotEmpty',
195 'ConditionFileNotEmpty',
196 'ConditionFileIsExecutable',
197 'AssertArchitecture',
198 'AssertVirtualization',
199 'AssertHost',
200 'AssertKernelCommandLine',
201 'AssertSecurity',
202 'AssertCapability',
203 'AssertACPower',
204 'AssertNeedsUpdate',
205 'AssertFirstBoot',
206 'AssertPathExists',
207 'AssertPathExistsGlob',
208 'AssertPathIsDirectory',
209 'AssertPathIsSymbolicLink',
210 'AssertPathIsMountPoint',
211 'AssertPathIsReadWrite',
212 'AssertDirectoryNotEmpty',
213 'AssertFileNotEmpty',
214 'AssertFileIsExecutable',
215 'SourcePath',
217 -- install section options
218 'Alias',
219 'WantedBy',
220 'RequiredBy',
221 'Also',
222 'DefaultInstance',
224 -- service section options
225 'Type',
226 'RemainAfterExit',
227 'GuessMainPID',
228 'PIDFile',
229 'BusName',
230 'BusPolicy',
231 'ExecStart',
232 'ExecStartPre',
233 'ExecStartPost',
234 'ExecReload',
235 'ExecStop',
236 'ExecStopPost',
237 'RestartSec',
238 'TimeoutStartSec',
239 'TimeoutStopSec',
240 'TimeoutSec',
241 'RuntimeMaxSec',
242 'WatchdogSec',
243 'Restart',
244 'SuccessExitStatus',
245 'RestartPreventExitStatus',
246 'RestartForceExitStatus',
247 'PermissionsStartOnly',
248 'RootDirectoryStartOnly',
249 'NonBlocking',
250 'NotifyAccess',
251 'Sockets',
252 'FailureAction',
253 'FileDescriptorStoreMax',
254 'USBFunctionDescriptors',
255 'USBFunctionStrings',
257 -- socket section options
258 'ListenStream',
259 'ListenDatagram',
260 'ListenSequentialPacket',
261 'ListenFIFO',
262 'ListenSpecial',
263 'ListenNetlink',
264 'ListenMessageQueue',
265 'ListenUSBFunction',
266 'SocketProtocol',
267 'BindIPv6Only',
268 'Backlog',
269 'BindToDevice',
270 'SocketUser',
271 'SocketGroup',
272 'SocketMode',
273 'DirectoryMode',
274 'Accept',
275 'Writable',
276 'MaxConnections',
277 'KeepAlive',
278 'KeepAliveTimeSec',
279 'KeepAliveIntervalSec',
280 'KeepAliveProbes',
281 'NoDelay',
282 'Priority',
283 'DeferAcceptSec',
284 'ReceiveBuffer',
285 'SendBuffer',
286 'IPTOS',
287 'IPTTL',
288 'Mark',
289 'ReusePort',
290 'SmackLabel',
291 'SmackLabelIPIn',
292 'SmackLabelIPOut',
293 'SELinuxContextFromNet',
294 'PipeSize',
295 'MessageQueueMaxMessages',
296 'MessageQueueMessageSize',
297 'FreeBind',
298 'Transparent',
299 'Broadcast',
300 'PassCredentials',
301 'PassSecurity',
302 'TCPCongestion',
303 'ExecStartPre',
304 'ExecStartPost',
305 'ExecStopPre',
306 'ExecStopPost',
307 'TimeoutSec',
308 'Service',
309 'RemoveOnStop',
310 'Symlinks',
311 'FileDescriptorName',
313 -- mount section options
314 'What',
315 'Where',
316 'Type',
317 'Options',
318 'SloppyOptions',
319 'DirectoryMode',
320 'TimeoutSec',
322 -- path section options
323 'PathExists',
324 'PathExistsGlob',
325 'PathChanged',
326 'PathModified',
327 'DirectoryNotEmpty',
328 'Unit',
329 'MakeDirectory',
330 'DirectoryMode',
332 -- timer section options
333 'OnActiveSec',
334 'OnBootSec',
335 'OnStartupSec',
336 'OnUnitActiveSec',
337 'OnUnitInactiveSec',
338 'OnCalendar',
339 'AccuracySec',
340 'RandomizedDelaySec',
341 'Unit',
342 'Persistent',
343 'WakeSystem',
344 'RemainAfterElapse',
346 -- exec section options
347 'WorkingDirectory',
348 'RootDirectory',
349 'User',
350 'Group',
351 'SupplementaryGroups',
352 'Nice',
353 'OOMScoreAdjust',
354 'IOSchedulingClass',
355 'IOSchedulingPriority',
356 'CPUSchedulingPolicy',
357 'CPUSchedulingPriority',
358 'CPUSchedulingResetOnFork',
359 'CPUAffinity',
360 'UMask',
361 'Environment',
362 'EnvironmentFile',
363 'PassEnvironment',
364 'StandardInput',
365 'StandardOutput',
366 'StandardError',
367 'TTYPath',
368 'TTYReset',
369 'TTYVHangup',
370 'TTYVTDisallocate',
371 'SyslogIdentifier',
372 'SyslogFacility',
373 'SyslogLevel',
374 'SyslogLevelPrefix',
375 'TimerSlackNSec',
376 'LimitCPU',
377 'LimitFSIZE',
378 'LimitDATA',
379 'LimitSTACK',
380 'LimitCORE',
381 'LimitRSS',
382 'LimitNOFILE',
383 'LimitAS',
384 'LimitNPROC',
385 'LimitMEMLOCK',
386 'LimitLOCKS',
387 'LimitSIGPENDING',
388 'LimitMSGQUEUE',
389 'LimitNICE',
390 'LimitRTPRIO',
391 'LimitRTTIME',
392 'PAMName',
393 'CapabilityBoundingSet',
394 'AmbientCapabilities',
395 'SecureBits',
396 'Capabilities',
397 'ReadWriteDirectories',
398 'ReadOnlyDirectories',
399 'InaccessibleDirectories',
400 'PrivateTmp',
401 'PrivateDevices',
402 'PrivateNetwork',
403 'ProtectSystem',
404 'ProtectHome',
405 'MountFlags',
406 'UtmpIdentifier',
407 'UtmpMode',
408 'SELinuxContext',
409 'AppArmorProfile',
410 'SmackProcessLabel',
411 'IgnoreSIGPIPE',
412 'NoNewPrivileges',
413 'SystemCallFilter',
414 'SystemCallErrorNumber',
415 'SystemCallArchitectures',
416 'RestrictAddressFamilies',
417 'Personality',
418 'RuntimeDirectory',
419 'RuntimeDirectoryMode'
421 local preproc = token(l.PREPROCESSOR, option_word)
423 -- Identifiers.
424 local word = (l.alpha + '_') * (l.alnum + S('_.'))^0
425 local identifier = token(l.IDENTIFIER, word)
427 -- Operators.
428 local operator = token(l.OPERATOR, '=')
430 M._rules = {
431 {'whitespace', ws},
432 {'keyword', keyword},
433 {'string', string},
434 {'preproc', preproc},
435 {'identifier', identifier},
436 {'comment', comment},
437 {'number', number},
438 {'operator', operator},
441 M._LEXBYLINE = true
443 return M