Yocto Project Documentation
 help / color / mirror / Atom feed
From: Trevor Woerner <twoerner@gmail.com>
To: docs@lists.yoctoproject.org
Subject: [PATCH 4/7] sphinx: add a lexer for wic kickstart files
Date: Wed, 25 Nov 2026 10:45:32 -0500	[thread overview]
Message-ID: <20261125154535.3486104-5-twoerner@gmail.com> (raw)
In-Reply-To: <20261125154535.3486104-1-twoerner@gmail.com>

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

diff --git a/documentation/conf.py b/documentation/conf.py
index 210b4ab60595..f89926549d20 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -82,7 +82,8 @@ extensions = [
     'yocto-vars',
     'bitbake-lexer',
     'bitbake-placeholder',
-    'scc-lexer'
+    'scc-lexer',
+    'wks-lexer'
 ]
 
 # current_version = "dev"
diff --git a/documentation/sphinx/wks-lexer.py b/documentation/sphinx/wks-lexer.py
new file mode 100644
index 000000000000..1e5e5ec1e5b9
--- /dev/null
+++ b/documentation/sphinx/wks-lexer.py
@@ -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,
+    }
-- 
2.50.0.173.g8b6f19ccfc3a


  parent reply	other threads:[~2026-11-25 15:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 15:45 [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Trevor Woerner
2026-11-25 15:45 ` [PATCH 1/7] sphinx: carry a BitBake lexer as a local extension Trevor Woerner
2026-11-25 15:45 ` [PATCH 2/7] sphinx: add a lexer for BitBake with placeholders Trevor Woerner
2026-11-25 15:45 ` [PATCH 3/7] sphinx: add a lexer for kernel metadata SCC files Trevor Woerner
2026-11-25 15:45 ` Trevor Woerner [this message]
2026-11-25 15:45 ` [PATCH 5/7] sphinx: add a lexer for pydevshell sessions Trevor Woerner
2026-11-25 15:45 ` [PATCH 6/7] sphinx: read a bare "#" in a console block as output Trevor Woerner
2026-11-25 15:45 ` [PATCH 7/7] sphinx: mark placeholders in console and plain-text examples Trevor Woerner
2026-11-26 16:33 ` [docs] [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Antonin Godard
2026-11-26 22:26   ` Trevor Woerner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125154535.3486104-5-twoerner@gmail.com \
    --to=twoerner@gmail.com \
    --cc=docs@lists.yoctoproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox