@@ -82,7 +82,8 @@ extensions = [
'yocto-vars',
'bitbake-lexer',
'bitbake-placeholder',
- 'scc-lexer'
+ 'scc-lexer',
+ 'wks-lexer'
]
# current_version = "dev"
new file mode 100644
@@ -0,0 +1,60 @@
+"""A lexer for wic kickstart (.wks) files.
+
+wic reads a .wks file line by line: a line whose first non-blank
+character is ``#`` is a comment, and every other line is split with
+``shlex.split`` and handed to ``argparse``, after ``${VAR}`` has been
+expanded. The quoting is therefore shell quoting, which is why this
+extends the bash lexer. What the bash lexer cannot do is mark the
+vocabulary: ``part`` is not a shell builtin, so the statement opening
+each line comes out as ordinary text, and so does every ``--option``.
+
+The statements and options below are taken from wic's parser,
+``ksparser.py``, rather than from the manual, so update them from there
+when wic gains one. ``partition`` is not a statement: it was an alias
+while wic bundled pykickstart, and the parser that replaced it in 2016
+kept only ``part``.
+"""
+from pygments.lexer import bygroups, inherit
+from pygments.lexers.shell import BashLexer
+from pygments.token import Comment, Keyword, Name, Text, Whitespace
+
+__version__ = '1.0'
+
+# The subparsers wic registers.
+STATEMENTS = ('part', 'bootloader', 'include')
+
+
+class WksLexer(BashLexer):
+ """wic kickstart."""
+
+ name = 'wic kickstart'
+ aliases = ['wks']
+ filenames = ['*.wks', '*.wks.in']
+ mimetypes = []
+
+ tokens = {
+ 'root': [
+ # A statement is only a statement at the start of a line.
+ # Anchoring matters: "include" is also an ordinary word in
+ # "--include-path", and "part" appears inside several option
+ # names, so an unanchored keyword would mark both.
+ (r'^(\s*)(%s)(\b)' % '|'.join(STATEMENTS),
+ bygroups(Whitespace, Keyword, Text)),
+ # Long options carry the meaning on a wic line; bash leaves
+ # them as plain text because it has no notion of them.
+ (r'--[\w-]+', Name.Attribute),
+ # wic tests the first character of the stripped line, so a
+ # comment may be indented and is never trailing.
+ (r'^\s*#.*$', Comment.Single),
+ inherit,
+ ],
+ }
+
+
+def setup(app):
+ app.add_lexer('wks', WksLexer)
+ return {
+ 'version': __version__,
+ 'parallel_read_safe': True,
+ 'parallel_write_safe': True,
+ }
The manuals show .wks files in several places and have no language for them, so they are tagged text, tagged shell, or left to the default. Shell comes closest, because wic splits each line with shlex and expands ${VAR} before parsing, but it does not know the vocabulary: the "part" opening a line and every option come out as ordinary text. This extends the bash lexer to mark the statements and long options that wic's own parser registers. AI-Generated: codex/claude-opus 5.5 (xhigh) Signed-off-by: Trevor Woerner <twoerner@gmail.com> --- documentation/conf.py | 3 +- documentation/sphinx/wks-lexer.py | 60 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 documentation/sphinx/wks-lexer.py