aboutsummaryrefslogtreecommitdiff
path: root/lua/lexers/systemd.lua
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2025-03-24 10:11:05 -0400
committerRandy Palamar <randy@rnpnr.xyz>2025-06-13 09:25:20 -0600
commit16e31ceb717c943584cb75d0e28c21e356a54076 (patch)
tree2d07cf6b6c2e7502d8be0214b1a2484aeeaf409b /lua/lexers/systemd.lua
parentf694179d1153eecc50c1179cf5ee8233639f9eba (diff)
downloadvis-16e31ceb717c943584cb75d0e28c21e356a54076.tar.gz
vis-16e31ceb717c943584cb75d0e28c21e356a54076.tar.xz
lua/lexers: update to scintillua 6.5
This is an amalgamation of the following upstream commits: - Overhauled API documentation for lexer.lua. - Fixed Markdown to allow code fence blocks to be indented. - Use GitHub Pages' Primer theme for documentation. Build static pages with Jekyll, like GitHub Pages does. - Migrated systemd lexer. Thanks to Matěj Cepl. - Migrated Lisp lexer and highlight character escapes. Thanks to Matěj Cepl. - Migrated rpmspec lexer and made some improvements. Thanks to Matěj Cepl. - Modernized reST lexer. Thanks to Matěj Cepl. - Markdown lexer should just tag the start of a blockquote. The quote's contents may contain markdown. - Output lexer can highlight CSI color sequences. - Allow lexers to define their own fold functions. - Added custom folder for Markdown headers. - Added `lexer.line_start`, `lexer.line_end` and `lexer.text_range()`. - Fixed Markdown lexer to not lex some continuation lines as code. - Fixed SciTE not using Scintillua's markdown lexer. - Markdown lexer should not highlight secondary paragraphs in list items as code blocks. - Have SciTE recognize CMakeLists.txt.
Diffstat (limited to 'lua/lexers/systemd.lua')
-rw-r--r--lua/lexers/systemd.lua75
1 files changed, 42 insertions, 33 deletions
diff --git a/lua/lexers/systemd.lua b/lua/lexers/systemd.lua
index 9145cd3..780830d 100644
--- a/lua/lexers/systemd.lua
+++ b/lua/lexers/systemd.lua
@@ -1,17 +1,41 @@
-- Copyright 2016-2025 Christian Hesse. See LICENSE.
-- systemd unit file LPeg lexer.
-local lexer = require('lexer')
-local token, word_match = lexer.token, lexer.word_match
+local lexer = lexer
local P, S = lpeg.P, lpeg.S
-local lex = lexer.new('systemd', {lex_by_line = true})
-
--- Whitespace.
-lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1))
+local lex = lexer.new(..., {lex_by_line = true})
-- Keywords.
-lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
+lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD)))
+
+-- Options.
+lex:add_rule('option', lex:tag(lexer.PREPROCESSOR, lex:word_match(lexer.PREPROCESSOR)))
+
+-- Identifiers.
+lex:add_rule('identifier',
+ lex:tag(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0))
+
+-- Strings.
+local sq_str = lexer.range("'")
+local dq_str = lexer.range('"')
+lex:add_rule('string', lex:tag(lexer.STRING, sq_str + dq_str))
+
+-- Sections.
+lex:add_rule('section', lex:tag(lexer.LABEL, '[' * lex:word_match(lexer.LABEL) * ']'))
+
+-- Comments.
+lex:add_rule('comment', lex:tag(lexer.COMMENT, lexer.starts_line(lexer.to_eol(S(';#')))))
+
+-- Numbers.
+local integer = S('+-')^-1 * (lexer.hex_num + lexer.oct_num_('_') + lexer.dec_num_('_'))
+lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.float + integer))
+
+-- Operators.
+lex:add_rule('operator', lex:tag(lexer.OPERATOR, '='))
+
+-- Word lists
+lex:set_word_list(lexer.KEYWORD, {
-- Boolean values.
'true', 'false', 'on', 'off', 'yes', 'no',
-- Service types.
@@ -38,10 +62,9 @@ lex:add_rule('keyword', token(lexer.KEYWORD, word_match{
'PATH', 'LANG', 'USER', 'LOGNAME', 'HOME', 'SHELL', 'XDG_RUNTIME_DIR', 'XDG_SESSION_ID',
'XDG_SEAT', 'XDG_VTNR', 'MAINPID', 'MANAGERPID', 'LISTEN_FDS', 'LISTEN_PID', 'LISTEN_FDNAMES',
'NOTIFY_SOCKET', 'WATCHDOG_PID', 'WATCHDOG_USEC', 'TERM'
-}))
+})
--- Options.
-lex:add_rule('option', token(lexer.PREPROCESSOR, word_match{
+lex:set_word_list(lexer.PREPROCESSOR, {
-- Unit section.
'Description', 'Documentation', 'Requires', 'Requisite', 'Wants', 'BindsTo', 'PartOf',
'Conflicts', 'Before', 'After', 'OnFailure', 'PropagatesReloadTo', 'ReloadPropagatedFrom',
@@ -103,30 +126,16 @@ lex:add_rule('option', token(lexer.PREPROCESSOR, word_match{
'UtmpIdentifier', 'UtmpMode', 'SELinuxContext', 'AppArmorProfile', 'SmackProcessLabel',
'IgnoreSIGPIPE', 'NoNewPrivileges', 'SystemCallFilter', 'SystemCallErrorNumber',
'SystemCallArchitectures', 'RestrictAddressFamilies', 'Personality', 'RuntimeDirectory',
- 'RuntimeDirectoryMode'
-}))
-
--- Identifiers.
-lex:add_rule('identifier', token(lexer.IDENTIFIER, (lexer.alpha + '_') * (lexer.alnum + S('_.'))^0))
-
--- Strings.
-local sq_str = lexer.range("'")
-local dq_str = lexer.range('"')
-lex:add_rule('string', token(lexer.STRING, sq_str + dq_str))
+ 'RuntimeDirectoryMode',
+ -- Container files.
+ 'AddCapability', 'AutoUpdate', 'ContainerName', 'Exec', 'HostName', 'Image', 'Network',
+ 'PodmanArgs', 'PublishPort', 'UserNS', 'Volume'
+})
--- Sections.
-lex:add_rule('section', token(lexer.LABEL, '[' *
- word_match('Automount BusName Install Mount Path Service Service Socket Timer Unit') * ']'))
-
--- Comments.
-lex:add_rule('comment', token(lexer.COMMENT, lexer.starts_line(lexer.to_eol(S(';#')))))
-
--- Numbers.
-local integer = S('+-')^-1 * (lexer.hex_num + lexer.oct_num_('_') + lexer.dec_num_('_'))
-lex:add_rule('number', token(lexer.NUMBER, lexer.float + integer))
-
--- Operators.
-lex:add_rule('operator', token(lexer.OPERATOR, '='))
+lex:set_word_list(lexer.LABEL, {
+ 'Automount', 'BusName', 'Install', 'Mount', 'Path', 'Service', 'Service', 'Socket', 'Timer',
+ 'Unit'
+})
lexer.property['scintillua.comment'] = '#'