Skip to contentSkip to conversation

sphinx: carry lexers for the languages the manuals show

PATCH New Trevor Woerner 1 participant 8 messages Nov 25

lore
Share & tools
lore
#0 lore raw

cover sphinx: carry lexers for the languages the manuals show

This is the series proposed in [1]: the BitBake lexer first, then the other lexers, one patch each. The BitBake lexer is patch 1 and can be applied on its own.

No block uses any of these lexers yet, so the rendered manuals do not change, with one exception: the console fix in patch 6 changes how existing console blocks read a line opening with a bare "#", from a root prompt to program output. Every commit builds clean under -W on its own.

The BitBake lexer takes its patterns from BitBake's own parser, and is the same lexer proposed to Pygments in [2]. The SCC and wks lexers are derived the same way, from yocto-kernel-tools and from wic's parser.

The series is based on master-next with two of your pending series applied, since both also edit the extension list in conf.py:

- Add support for documentation tags [3]
- Add a "Library Functions" section to the ref-manual [4]

The tags series needed two trivial conflict resolutions to apply on master-next, both in the tags it appends to the end of contributor-guide/submit-changes.rst and ref-manual/kickstart.rst.

[1] https://lore.kernel.org/r/[email protected]
[2] https://github.com/pygments/pygments/pull/3284
[3] https://lore.kernel.org/r/[email protected]
[4] https://lore.kernel.org/r/[email protected]

Trevor Woerner (7):
sphinx: carry a BitBake lexer as a local extension
sphinx: add a lexer for BitBake with placeholders
sphinx: add a lexer for kernel metadata SCC files
sphinx: add a lexer for wic kickstart files
sphinx: add a lexer for pydevshell sessions
sphinx: read a bare "#" in a console block as output
sphinx: mark placeholders in console and plain-text examples

 documentation/conf.py                         |   9 +-
 .../sphinx-static/theme_overrides.css         |  20 +
 documentation/sphinx/bitbake-lexer.py         | 432 ++++++++++++++++++
 documentation/sphinx/bitbake-placeholder.py   | 145 ++++++
 documentation/sphinx/console-lexer.py         |  53 +++
 documentation/sphinx/placeholder-lexers.py    | 134 ++++++
 documentation/sphinx/pydevshell-lexer.py      |  48 ++
 documentation/sphinx/scc-lexer.py             | 116 +++++
 documentation/sphinx/wks-lexer.py             |  60 +++
 9 files changed, 1016 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/bitbake-lexer.py
 create mode 100644 documentation/sphinx/bitbake-placeholder.py
 create mode 100644 documentation/sphinx/console-lexer.py
 create mode 100644 documentation/sphinx/placeholder-lexers.py
 create mode 100644 documentation/sphinx/pydevshell-lexer.py
 create mode 100644 documentation/sphinx/scc-lexer.py
 create mode 100644 documentation/sphinx/wks-lexer.py
Signature · 1 line
2.50.0.173.g8b6f19ccfc3a
#1 lore raw

PATCH 1/7 sphinx: carry a BitBake lexer as a local extension

BitBake's syntax changes from release to release, and the manuals describe each change as it lands. Pygments learns it only in its own releases, which builders install later still, so the highlighting of the manuals depends on whichever Pygments happens to be installed.

This adds a local Sphinx extension carrying a BitBake lexer built from BitBake's own parser patterns, so the manuals are highlighted the same way wherever they are built and can follow the language as it changes. It performs tests at startup and registers itself only if no BitBake lexer is found, or the one found fails its tests. Otherwise the installed lexer is used.

AI-Generated: codex/claude-opus 5.5 (xhigh)

---
 documentation/conf.py                 |   3 +-
 documentation/sphinx/bitbake-lexer.py | 432 ++++++++++++++++++++++++++
 2 files changed, 434 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/bitbake-lexer.py
documentation/conf.py +2 -1
index afa7f8d985f4..cdd554e30c0a 100644
@@ -79,7 +79,8 @@ extensions = [
     'sphinx_copybutton',
     'sphinx_tags',
     'sphinxcontrib.rsvgconverter',
-    'yocto-vars'
+    'yocto-vars',
+    'bitbake-lexer'
 ]
 
 # current_version = "dev"
documentation/sphinx/bitbake-lexer.py new file +432 -0

432 lines not on this page · raw message

Signature · 1 line
2.50.0.173.g8b6f19ccfc3a
#2 lore raw

PATCH 2/7 sphinx: add a lexer for BitBake with placeholders

In reply to Trevor Woerner

The manuals write <like this> for a value the reader has to replace, and BitBake cannot express that. Inside a quoted value it renders as ordinary string content, indistinguishable from text to type verbatim; in a variable name it is not valid BitBake at all.

This adds a bitbake-placeholder lexer that accepts a placeholder where BitBake's charsets do not and marks it wherever it appears. Everything else is inherited from the BitBake lexer, so a block using it still reports a genuine mistake.

AI-Generated: codex/claude-opus 5.5 (xhigh)

---
 documentation/conf.py                         |   3 +-
 .../sphinx-static/theme_overrides.css         |  20 +++
 documentation/sphinx/bitbake-placeholder.py   | 145 ++++++++++++++++++
 3 files changed, 167 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/bitbake-placeholder.py
documentation/conf.py +2 -1
index cdd554e30c0a..95bb24002544 100644
@@ -80,7 +80,8 @@ extensions = [
     'sphinx_tags',
     'sphinxcontrib.rsvgconverter',
     'yocto-vars',
-    'bitbake-lexer'
+    'bitbake-lexer',
+    'bitbake-placeholder'
 ]
 
 # current_version = "dev"
documentation/sphinx-static/theme_overrides.css +20 -0
index 85f01eafbb94..2083ebb5baf4 100644
@@ -252,3 +252,23 @@ a.sd-badge {
     }
 
 }
+
+/* A placeholder in a bitbake-placeholder block: something the reader is
+   meant to replace, such as <recipe> in SRCREV:pn-<recipe>.
+
+   The box is the point. A placeholder usually abuts real text it is not
+   part of - pn-<recipe>, <some.host>/<somepath> - and an outline is what
+   shows where one ends and the other begins. Colour alone does not.
+
+   Italic carries the same meaning without any colour at all, so the mark
+   survives a monochrome printout. The border is #5b8db9 rather than
+   something paler because it has to clear 3:1 against the code block to
+   count as a boundary: a lighter blue measured 2:1 and disappeared. */
+.rst-content .highlight-bitbake-placeholder .ge {
+    color: #144e8c;
+    font-style: italic;
+    font-weight: 600;
+    border: 1px solid #5b8db9;
+    border-radius: 3px;
+    padding: 0 2px;
+}
documentation/sphinx/bitbake-placeholder.py new file +145 -0

145 lines not on this page · raw message

Signature · 1 line
2.50.0.173.g8b6f19ccfc3a
#3 lore raw

PATCH 3/7 sphinx: add a lexer for kernel metadata SCC files

In reply to Trevor Woerner

The kernel manual quotes SCC description files throughout, and none of them can say what they are: Pygments has no lexer for the language and is unlikely to want one, so they render as plain text.

SCC is bash. spp rewrites a few line-oriented directives, then scc sources the result with one shell function declared per statement and PATH unset. Description files use that freedom - conditionals on KARCH are common in real metadata - so extend the bash lexer and mark the vocabulary, read from the functions the tooling declares rather than from the manual's reference section, which omits several.

AI-Generated: codex/claude-opus 5.5 (xhigh)

---
 documentation/conf.py             |   3 +-
 documentation/sphinx/scc-lexer.py | 116 ++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/scc-lexer.py
documentation/conf.py +2 -1
index 95bb24002544..210b4ab60595 100644
@@ -81,7 +81,8 @@ extensions = [
     'sphinxcontrib.rsvgconverter',
     'yocto-vars',
     'bitbake-lexer',
-    'bitbake-placeholder'
+    'bitbake-placeholder',
+    'scc-lexer'
 ]
 
 # current_version = "dev"
documentation/sphinx/scc-lexer.py new file +116 -0

116 lines not on this page · raw message

Signature · 1 line
2.50.0.173.g8b6f19ccfc3a
#4 lore raw

PATCH 4/7 sphinx: add a lexer for wic kickstart files

In reply to Trevor Woerner

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)

---
 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
documentation/conf.py +2 -1
index 210b4ab60595..f89926549d20 100644
@@ -82,7 +82,8 @@ extensions = [
     'yocto-vars',
     'bitbake-lexer',
     'bitbake-placeholder',
-    'scc-lexer'
+    'scc-lexer',
+    'wks-lexer'
 ]
 
 # current_version = "dev"
documentation/sphinx/wks-lexer.py new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.50.0.173.g8b6f19ccfc3a
#5 lore raw

PATCH 5/7 sphinx: add a lexer for pydevshell sessions

In reply to Trevor Woerner

The development manual shows a session in BitBake's Python development shell, and no lexer reads it: console wants a prompt ending in $, #, or %, pycon wants >>>, and both mark the whole block as program output, which the theme greys. The prompt cannot be changed to suit them either, since devshell.bbclass is what sets it.

Teach a session lexer the prompt instead, with Python inside it, so the expressions the reader types are highlighted as Python and the results are not.

AI-Generated: codex/claude-opus 5.5 (xhigh)

---
 documentation/conf.py                    |  3 +-
 documentation/sphinx/pydevshell-lexer.py | 48 ++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/pydevshell-lexer.py
documentation/conf.py +2 -1
index f89926549d20..3a7e3c920fc4 100644
@@ -83,7 +83,8 @@ extensions = [
     'bitbake-lexer',
     'bitbake-placeholder',
     'scc-lexer',
-    'wks-lexer'
+    'wks-lexer',
+    'pydevshell-lexer'
 ]
 
 # current_version = "dev"
documentation/sphinx/pydevshell-lexer.py new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.50.0.173.g8b6f19ccfc3a
#6 lore raw

PATCH 6/7 sphinx: read a bare "#" in a console block as output

In reply to Trevor Woerner

Pygments treats "$", "#", and "%" alike as prompts and lets the preamble before them be empty, so a line opening with "#" is taken for a root prompt and the rest of it is lexed as the command it introduces. Across these manuals that line is a comment or a line of program output every time, never a prompt: a root prompt carries the host preamble saying whose root it is.

Require that preamble before a "#". The line then falls through to Generic.Output, which is what it was, and the theme stops showing perf headers and generated-file comments as commands somebody typed.

AI-Generated: codex/claude-opus 5.5 (xhigh)

---
 documentation/conf.py                 |  3 +-
 documentation/sphinx/console-lexer.py | 53 +++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 documentation/sphinx/console-lexer.py
documentation/conf.py +2 -1
index 3a7e3c920fc4..5db20ff021fc 100644
@@ -84,7 +84,8 @@ extensions = [
     'bitbake-placeholder',
     'scc-lexer',
     'wks-lexer',
-    'pydevshell-lexer'
+    'pydevshell-lexer',
+    'console-lexer'
 ]
 
 # current_version = "dev"
documentation/sphinx/console-lexer.py new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.50.0.173.g8b6f19ccfc3a
#7 lore raw

PATCH 7/7 sphinx: mark placeholders in console and plain-text examples

In reply to Trevor Woerner

Most of the values a reader has to replace are in the commands the manuals tell them to run, where <recipe> and <path/to/repo> look exactly like text to type verbatim.

This adds console-placeholder and text-placeholder. A console line containing a placeholder is already valid, so they re-label the run with a filter over the finished token stream rather than a new grammar. The filter works on offsets, because the shell lexer reads "<" as a redirection and splits the run before a filter sees it.

Both are opt-in per block, because angle brackets also mean other things, such as the kernel's <idle> task in an ftrace listing. A C include is the one case the filter decides for itself, since nobody substitutes the header in "#include <near/dbus.h>".

AI-Generated: codex/claude-opus 5.5 (xhigh)

---
 documentation/conf.py                         |   3 +-
 .../sphinx-static/theme_overrides.css         |   2 +-
 documentation/sphinx/placeholder-lexers.py    | 134 ++++++++++++++++++
 3 files changed, 137 insertions(+), 2 deletions(-)
 create mode 100644 documentation/sphinx/placeholder-lexers.py
documentation/conf.py +2 -1
index 5db20ff021fc..d56c648d8701 100644
@@ -85,7 +85,8 @@ extensions = [
     'scc-lexer',
     'wks-lexer',
     'pydevshell-lexer',
-    'console-lexer'
+    'console-lexer',
+    'placeholder-lexers'
 ]
 
 # current_version = "dev"
documentation/sphinx-static/theme_overrides.css +1 -1
index 2083ebb5baf4..2120c43245cc 100644
@@ -264,7 +264,7 @@ a.sd-badge {
    survives a monochrome printout. The border is #5b8db9 rather than
    something paler because it has to clear 3:1 against the code block to
    count as a boundary: a lighter blue measured 2:1 and disappeared. */
-.rst-content .highlight-bitbake-placeholder .ge {
+.rst-content div[class*="-placeholder"] .ge {
     color: #144e8c;
     font-style: italic;
     font-weight: 600;
documentation/sphinx/placeholder-lexers.py new file +134 -0

134 lines not on this page · raw message

Signature · 1 line
2.50.0.173.g8b6f19ccfc3a