* [PATCH 0/7] sphinx: carry lexers for the languages the manuals show
@ 2026-11-25 15:45 Trevor Woerner
2026-11-25 15:45 ` [PATCH 1/7] sphinx: carry a BitBake lexer as a local extension Trevor Woerner
` (7 more replies)
0 siblings, 8 replies; 10+ messages in thread
From: Trevor Woerner @ 2026-11-25 15:45 UTC (permalink / raw)
To: docs
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/atjXdzebFGmKVjj8@localhost.localdomain
[2] https://github.com/pygments/pygments/pull/3284
[3] https://lore.kernel.org/r/20261028-tags-v1-0-d5ad01019eae@bootlin.com
[4] https://lore.kernel.org/r/20261124-oe-utils-docs-v1-0-5fafbf6cb01c@bootlin.com
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
--
2.50.0.173.g8b6f19ccfc3a
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/7] sphinx: carry a BitBake lexer as a local extension
2026-11-25 15:45 [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Trevor Woerner
@ 2026-11-25 15:45 ` Trevor Woerner
2026-11-25 15:45 ` [PATCH 2/7] sphinx: add a lexer for BitBake with placeholders Trevor Woerner
` (6 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2026-11-25 15:45 UTC (permalink / raw)
To: docs
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)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
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
diff --git a/documentation/conf.py b/documentation/conf.py
index afa7f8d985f4..cdd554e30c0a 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -79,7 +79,8 @@ extensions = [
'sphinx_copybutton',
'sphinx_tags',
'sphinxcontrib.rsvgconverter',
- 'yocto-vars'
+ 'yocto-vars',
+ 'bitbake-lexer'
]
# current_version = "dev"
diff --git a/documentation/sphinx/bitbake-lexer.py b/documentation/sphinx/bitbake-lexer.py
new file mode 100644
index 000000000000..5a323ffb943d
--- /dev/null
+++ b/documentation/sphinx/bitbake-lexer.py
@@ -0,0 +1,432 @@
+"""BitBake lexer, carried with the manuals.
+
+BitBake's syntax changes from release to release, and the manuals describe
+it as it changes. Carrying the lexer here keeps their highlighting in step
+with the language, and the same wherever they are built, rather than
+dependent on which Pygments happens to be installed.
+
+The patterns are BitBake's own, taken from its parser. Everything from the
+imports to the end of the lexer class is identical to the lexer proposed
+to Pygments in https://github.com/pygments/pygments/pull/3284, so a fix
+belongs in both.
+
+setup() tests the installed lexer and registers this one only if no
+BitBake lexer is found, or the one found fails its tests. Otherwise the
+installed lexer is used.
+"""
+
+import re
+
+from pygments.lexer import RegexLexer, bygroups, include, using, words
+from pygments.lexers.python import PythonLexer
+from pygments.lexers.shell import BashLexer
+from pygments.token import Comment, Error, Keyword, Name, Operator, \
+ Punctuation, String, Text, Whitespace
+
+__version__ = '2.0'
+
+
+class _FragmentPythonLexer(PythonLexer):
+ """Lex a ``${@...}`` fragment without reporting its incompleteness.
+
+ An inline Python expression is handed over in pieces, split around any
+ ``${VAR}`` expansions embedded in it, so a piece routinely begins or ends
+ mid-string and is not valid Python on its own. The error would be an
+ artefact of the splitting rather than a defect in the metadata.
+
+ This is deliberately the only place errors are suppressed. Errors in
+ BitBake's own syntax, and in a complete shell or Python function body,
+ are reported.
+ """
+
+ def get_tokens_unprocessed(self, text, stack=('root',)):
+ for index, token, value in super().get_tokens_unprocessed(text, stack):
+ yield index, Text if token is Error else token, value
+
+
+# ---------------------------------------------------------------------------
+# Validity is decided by BitBake, never by this file.
+#
+# Each pattern is BitBake's own statement regex from ``bb.parse.parse_py``,
+# mechanically adapted, and used below only as a zero-width guard: a rule
+# fires when and only when BitBake's parser would accept the line. The token
+# spans are then chosen separately, which is the part a lexer is for.
+#
+# Three adaptations are applied, each because BitBake matches one
+# already-assembled logical line while a lexer sees raw file text:
+#
+# \s -> [ \t] its \s can never meet a newline, because
+# the file has already been split into lines
+# . -> (?:[^\n]|\\[ \t]*\n) continuations are joined before BitBake
+# sees them, and inline here instead
+# $ -> [ \t]*$ the line is rstripped before matching, so
+# the anchors tolerate trailing whitespace
+#
+# The last applies to every anchor including the ones inside the assignment
+# rule's negative lookaheads, which are what decide whether the quotes
+# balance. Do not hand-edit these; regenerate them and check that the
+# verdicts still agree with BitBake's on real metadata.
+_BB = {
+ 'function start':
+ '^(?:(?:(?:python(?=(?:(?:[ \\t]|\\\\[ \\t]*\\n)|\\()))|(?:fakeroot(?=(?:[ \\t]|\\\\[ \\t]*\\n))))(?:[ \\t]|\\\\[ \\t]*\\n)*)*(?:[\\w\\.\\-\\+\\{\\}\\$:]+)?(?:[ \\t]|\\\\[ \\t]*\\n)*\\((?:[ \\t]|\\\\[ \\t]*\\n)*\\)(?:[ \\t]|\\\\[ \\t]*\\n)*\\{[ \\t]*$',
+ 'def block':
+ '^def(?:[ \\t]|\\\\[ \\t]*\\n)+(?:\\w+)(?:[^\\n]|\\\\[ \\t]*\\n)*:',
+ 'export':
+ '^export(?:[ \\t]|\\\\[ \\t]*\\n)+(?:[a-zA-Z0-9\\-_+.${}/~]+)[ \\t]*$',
+ 'unset varflag':
+ '^unset(?:[ \\t]|\\\\[ \\t]*\\n)+(?:[a-zA-Z0-9\\-_+.${}/~]+)\\[(?:[a-zA-Z0-9\\-_+.][a-zA-Z0-9\\-_+.@]+)\\][ \\t]*$',
+ 'unset':
+ '^unset(?:[ \\t]|\\\\[ \\t]*\\n)+(?:[a-zA-Z0-9\\-_+.${}/~]+)[ \\t]*$',
+ 'addpylib':
+ '^addpylib(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)',
+ 'addfragments':
+ '^addfragments(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)',
+ 'inherit_defer':
+ '^inherit_defer(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)',
+ 'inherit':
+ '^inherit(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)',
+ 'include_all':
+ '^include_all(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)',
+ 'include':
+ '^include(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)',
+ 'require':
+ '^require(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)',
+ 'EXPORT_FUNCTIONS':
+ '^EXPORT_FUNCTIONS(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)',
+ 'addtask':
+ '^addtask(?:[ \\t]|\\\\[ \\t]*\\n)+(?:[^#\\n]+)(?:#(?:[^\\n]|\\\\[ \\t]*\\n)*|(?:[^\\n]|\\\\[ \\t]*\\n)*?)',
+ 'deltask':
+ '^deltask(?:[ \\t]|\\\\[ \\t]*\\n)+(?:[^#\\n]+)(?:#(?:[^\\n]|\\\\[ \\t]*\\n)*|(?:[^\\n]|\\\\[ \\t]*\\n)*?)',
+ 'addhandler':
+ '^addhandler(?:[ \\t]|\\\\[ \\t]*\\n)+(?:(?:[^\\n]|\\\\[ \\t]*\\n)+)',
+ 'assignment':
+ '^(?:export(?:[ \\t]|\\\\[ \\t]*\\n)+)?(?:[a-zA-Z0-9\\-_+.${}/~:]*?)(?:\\[(?:[a-zA-Z0-9\\-_+.][a-zA-Z0-9\\-_+.@/]*)\\])?(?:(?:[ \\t]|\\\\[ \\t]*\\n)*)(?:(?::=)|(?:\\?\\?=)|(?:\\?=)|(?:\\+=)|(?:=\\+)|(?:=\\.)|(?:\\.=)|=)(?:(?:[ \\t]|\\\\[ \\t]*\\n)*)(?!\'[^\'\\n]*\'[^\'\\n]*\'[ \\t]*$)(?!\\"[^\\"\\n]*\\"[^\\"\\n]*\\"[ \\t]*$)(?:\'(?:(?:[^\\n]|\\\\[ \\t]*\\n)*)\'|"(?:(?:[^\\n]|\\\\[ \\t]*\\n)*)")[ \\t]*$',
+}
+
+
+def _guard(*names):
+ """A zero-width assertion that BitBake's parser would accept this line."""
+ # The anchor is hoisted out of the alternation rather than repeated in
+ # each branch, which regexlint flags as suspicious (W114).
+ return r'(?=^(?:%s))' % '|'.join(_BB[name].lstrip('^') for name in names)
+
+
+_G_FUNC = _guard('function start')
+_G_DEF = _guard('def block')
+_G_INCLUDE = _guard('inherit_defer', 'inherit', 'include_all', 'include',
+ 'require')
+_G_STATEMENT = _guard('addtask', 'deltask', 'addhandler', 'EXPORT_FUNCTIONS',
+ 'addpylib', 'addfragments')
+_G_ASSIGN = _guard('assignment')
+_G_VALUELESS = _guard('export', 'unset varflag', 'unset')
+
+# None of the guards capture, so they add nothing for ``bygroups`` to number.
+
+
+# A bare BitBake identifier (variable, function or flag name). Allows the
+# characters used by OE-Core variable names (digits, ``-``, ``.``, ``+``).
+_IDENT = r'[A-Za-z_][A-Za-z0-9_\-.+]*'
+
+# Optional OE override chain such as ``:append``, ``:remove``, ``:class-target``
+# or ``:${PN}-doc``. Anchored so it only consumes ``:foo`` runs and never
+# eats the leading ``:`` of the ``:=`` assignment operator.
+_OVERRIDE = r'(?::[A-Za-z0-9_\-.+/~${}]+)*'
+
+# All BitBake variable assignment operators, ordered so that the longer
+# operators win the regex alternation.
+_ASSIGN = r'(?:\?\?=|\?=|:=|\+=|=\+|\.=|=\.|=)'
+
+# A variable or function name, matching what BitBake's own parser accepts
+# (``[a-zA-Z0-9\-_+.${}/~:]`` for variables, ``[\w.\-+{}$:]`` for
+# functions). Names may begin with a digit, may contain ``/`` as in
+# ``PREFERRED_PROVIDER_virtual/kernel``, and may embed an expansion as in
+# ``PREFERRED_PROVIDER_virtual/${SDK_PREFIX}libc``. The ``:`` introducing
+# an override chain is excluded, since ``_OVERRIDE`` consumes that.
+_NAME = r':?(?:\$\{[^{}\s]+\}|[A-Za-z0-9_\-.+/~${}])+'
+
+# A varflag name, which may also begin with a digit, as in
+# ``ESW_BRANCH[2024.1]``.
+_FLAG = r'[A-Za-z0-9_\-.+][A-Za-z0-9_\-.+@/]*'
+
+
+class BitBakeLexer(RegexLexer):
+ """
+ Lexer for BitBake recipes, classes, includes and configuration files
+ used by the Yocto Project and OpenEmbedded build system.
+ """
+
+ name = 'BitBake'
+ url = 'https://docs.yoctoproject.org/bitbake/'
+ aliases = ['bitbake']
+ filenames = ['*.bbclass', '*.bbappend']
+ mimetypes = ['text/x-bitbake']
+ version_added = '2.21'
+
+ flags = re.MULTILINE
+
+ tokens = {
+ 'root': [
+ (r'[ \t]+$', Whitespace),
+ (r'\n', Whitespace),
+
+ # ``handle`` tests for a comment at column zero only, and only
+ # after joining continuations, so an indented ``#`` is not a
+ # comment and a comment ending in ``\`` swallows the line below.
+ (r'^#(?:[^\n]|\\[ \t]*\n)*', Comment.Single),
+
+ # ``python [name]() { ... }`` blocks (also ``fakeroot python``).
+ # Must be tried before the generic shell function rule so the
+ # ``python`` keyword is not mistaken for a shell function name.
+ (_G_FUNC + r'(^(?:fakeroot[ \t]+)?)(python)((?:[ \t]+' + _NAME
+ + _OVERRIDE + r')?)'
+ r'([ \t]*\([ \t]*\)[ \t]*)(\{[ \t]*\n)'
+ r'((?:.*\n)*?)'
+ r'(^\}[ \t]*$)',
+ bygroups(Keyword.Type, Keyword, Name.Function, Text,
+ Punctuation, using(PythonLexer), Punctuation)),
+
+ # Shell task bodies: ``[fakeroot ]name[:override]() { ... }``.
+ (_G_FUNC + r'(^(?:fakeroot[ \t]+)?)(' + _NAME + r')('
+ + _OVERRIDE + r')'
+ r'([ \t]*\([ \t]*\)[ \t]*)(\{[ \t]*\n)'
+ r'((?:.*\n)*?)'
+ r'(^\}[ \t]*$)',
+ bygroups(Keyword.Type, Name.Function, Name.Decorator, Text,
+ Punctuation, using(BashLexer), Punctuation)),
+
+ # Top-level python ``def`` blocks; the body is any run of
+ # indented or blank lines following the signature.
+ # BitBake's rule is ``def\s+(\w+).*:``, which validates little
+ # and does not require a body, so neither may this. The guard
+ # has already decided the line is a def.
+ (_G_DEF + r'^def[ \t]+(?:[^\n]|\\[ \t]*\n)*:(?:[^\n]|\\[ \t]*\n)*(?:\n|$)'
+ r'(?:[ \t]+.*\n|\n)*',
+ using(PythonLexer)),
+
+ # ``inherit`` / ``inherit_defer`` / ``include`` / ``include_all`` /
+ # ``require`` directives. Longer keywords are listed first so the
+ # regex alternation does not match the shorter prefix.
+ (_G_INCLUDE
+ + r'^(inherit_defer|inherit|include_all|include|require)\b',
+ Keyword.Namespace, 'include-line'),
+
+ # ``addtask`` / ``deltask`` / ``addhandler`` / ``EXPORT_FUNCTIONS``
+ # / ``addpylib`` / ``addfragments``.
+ (_G_STATEMENT
+ + r'^(addtask|deltask|addhandler|EXPORT_FUNCTIONS|addpylib'
+ r'|addfragments)\b',
+ Keyword, 'statement'),
+
+ # ``VAR[flag] = "value"`` (varflag assignment). The variable may
+ # carry an override chain first, as in
+ # ``GOARM:arm:class-target[export] = "1"``.
+ (_G_ASSIGN + r'^(' + _NAME + r')(' + _OVERRIDE + r')(\[)('
+ + _FLAG + r')(\])'
+ r'([ \t]*)(' + _ASSIGN + r')',
+ bygroups(Name.Variable, Name.Decorator, Punctuation,
+ Name.Attribute, Punctuation, Whitespace, Operator),
+ 'value'),
+
+ # ``[export ]VAR[:override...] OP "value"`` assignments.
+ (_G_ASSIGN + r'^(export[ \t]+)?(' + _NAME + r')('
+ + _OVERRIDE + r')'
+ r'([ \t]*)(' + _ASSIGN + r')',
+ bygroups(Keyword.Type, Name.Variable, Name.Decorator,
+ Whitespace, Operator),
+ 'value'),
+
+ # ``export VAR`` and ``unset VAR`` / ``unset VAR[flag]``, which
+ # carry no value. These follow the assignment rules so that
+ # ``export VAR = "value"`` is still matched as an assignment.
+ (_G_VALUELESS + r'^(export|unset)([ \t]+)(' + _NAME + r')(\[)('
+ + _FLAG + r')'
+ r'(\])([ \t]*)$',
+ bygroups(Keyword, Whitespace, Name.Variable, Punctuation,
+ Name.Attribute, Punctuation, Whitespace)),
+ (_G_VALUELESS + r'^(export|unset)([ \t]+)(' + _NAME
+ + r')([ \t]*)$',
+ bygroups(Keyword, Whitespace, Name.Variable, Whitespace)),
+
+ # Nothing above matched, so BitBake's parser would reject this
+ # line. Report it. A documentation block that is wrong on
+ # purpose carries ``:force:``, which skips Sphinx's filter for
+ # that block and leaves the marking visible.
+ (r'(?:[^\n]|\\[ \t]*\n)+', Error),
+ ],
+
+ 'include-line': [
+ (r'[ \t]+', Whitespace),
+ (r'\\\n', Text),
+ (r'\n', Whitespace, '#pop'),
+ include('interp'),
+ (r'\$', String),
+ (r'[^\s$]+', String),
+ (r'[^\n]', String),
+ ],
+
+ 'statement': [
+ (r'[ \t]+', Whitespace),
+ (r'\\\n', Text),
+ (r'\n', Whitespace, '#pop'),
+ (words(('after', 'before'), suffix=r'\b'), Keyword),
+ include('interp'),
+ (r'\$', Name),
+ (r'[^\s$\\]+', Name),
+ (r'[^\n]', Name),
+ ],
+
+ 'value': [
+ (r'[ \t]+', Whitespace),
+ # A backslash is special to BitBake only as the last
+ # character of a line, where it continues the statement.
+ # There are no escape sequences in a value, so treating
+ # \\\\ as an escaped pair would swallow the backslash that
+ # forms the continuation.
+ (r'\\[ \t]*\n', String.Escape),
+ (r'\n', Whitespace, '#pop'),
+ (r'"', String.Double, 'string-double'),
+ (r"'", String.Single, 'string-single'),
+ include('interp'),
+ (r'\$', String),
+ (r'[^\s"\'$\\]+', String),
+ (r'[^\n]', String),
+ ],
+
+ 'string-double': [
+ # A backslash is special to BitBake only as the last
+ # character of a line, where it continues the statement.
+ # There are no escape sequences in a value, so treating
+ # \\\\ as an escaped pair would swallow the backslash that
+ # forms the continuation.
+ (r'\\[ \t]*\n', String.Escape),
+ (r'"', String.Double, '#pop'),
+ include('interp'),
+ (r'\$', String.Double),
+ (r'[^"\\$\n]+', String.Double),
+ (r'[^\n]', String.Double),
+ ],
+
+ 'string-single': [
+ # A backslash is special to BitBake only as the last
+ # character of a line, where it continues the statement.
+ # There are no escape sequences in a value, so treating
+ # \\\\ as an escaped pair would swallow the backslash that
+ # forms the continuation.
+ (r'\\[ \t]*\n', String.Escape),
+ (r"'", String.Single, '#pop'),
+ include('interp'),
+ (r'\$', String.Single),
+ (r"[^'\\$\n]+", String.Single),
+ (r'[^\n]', String.Single),
+ ],
+
+ 'interp': [
+ # ``${@ python expression }`` evaluated by BitBake at parse time.
+ (r'\$\{@', String.Interpol, 'py-interp'),
+ # ``${VAR}`` variable expansion, which may itself contain further
+ # expansions such as ``${TUNE_ARCH:tune-${DEFAULTTUNE}}``.
+ (r'\$\{', String.Interpol, 'var-interp'),
+ ],
+
+ 'var-interp': [
+ (r'\}', String.Interpol, '#pop'),
+ (r'\\[ \t]*\n', String.Escape),
+ (r'\$\{@', String.Interpol, 'py-interp'),
+ (r'\$\{', String.Interpol, '#push'),
+ (r'[^${}\n\\]+', Name.Variable),
+ (r'\$', Name.Variable),
+ (r'[^\n]', Name.Variable),
+ ],
+
+ 'py-interp': [
+ (r'\}', String.Interpol, '#pop'),
+ (r'\\[ \t]*\n', String.Escape),
+ # ``${VAR}`` expansions embedded in the Python expression, as in
+ # ``${@bb.utils.contains('F', 'x', '${A}', '', d)}``.
+ (r'\$\{', String.Interpol, 'var-interp'),
+ # The backslash is excluded so that the continuation rule above
+ # gets the chance to match it. Swallowed here instead, the
+ # newline ends up matching nothing, the state stack unwinds
+ # mid-expression, and every following line of a multi-line
+ # ``${@...}`` is lexed at the top level and reported as invalid.
+ (r'[^${}\n\\]+', using(_FragmentPythonLexer)),
+ # A ``$`` that does not open an expansion belongs to the Python
+ # expression's own text, most often a regular-expression anchor
+ # inside a quoted string.
+ (r'\$', String),
+ (r'\{', using(_FragmentPythonLexer)),
+ (r'[^\n]', String),
+ ],
+ }
+
+# What the installed lexer must get right to be used instead of this one.
+# Testing beats a version check: it judges whatever lexer is installed by
+# what it does, and costs one lex of a few short lines.
+#
+# These assert that an Error IS reported. A lexer that accepts what BitBake
+# rejects is invisible to a check looking only for the absence of errors.
+_PROBES_MUST_ERROR = (
+ # an unquoted value is not an assignment; BitBake rejects the line
+ 'PV = 0.8.16~rc1',
+ # neither is one carrying a trailing comment
+ 'ARCHIVER_MODE[src] = "x" # comment',
+)
+
+# Constructs that must lex cleanly, each paired with what the installed
+# lexer must make of one telling character. Asserting what the token IS
+# matters, rather than only that no Error was reported: a release could
+# suppress errors without fixing the lexing, and an error-only check would
+# then stand this extension down while blocks silently went back to being
+# mis-highlighted, with a zero exit code.
+_PROBES_MUST_BE_CLEAN = (
+ # the "$" anchoring a regex belongs to the string, not to an expansion
+ ('COMPATIBLE_MACHINE = "^mymachine$"', 32, String.Double),
+ # the inner "${" of a nested expansion is an expansion in its own right
+ ('TUNE_FEATURES ??= "${TUNE_FEATURES:tune-${DEFAULTTUNE}}"', 40,
+ String.Interpol),
+ # a statement carrying no value is still a statement
+ ('unset DATE', 0, Keyword),
+)
+
+
+def _installed_lexer_is_fixed():
+ """True only if the installed lexer demonstrably behaves.
+
+ Fails safe: anything unexpected - no bitbake lexer at all, an import
+ failure, a token type this does not recognise - is reported as not
+ fixed, so the carried lexer is used. Being wrong that way costs nothing;
+ being wrong the other way loses the highlighting silently.
+ """
+ try:
+ from pygments.lexers import get_lexer_by_name
+ lexer = get_lexer_by_name('bitbake')
+ except Exception:
+ return False
+ for text in _PROBES_MUST_ERROR:
+ try:
+ tokens = list(lexer.get_tokens_unprocessed(text))
+ except Exception:
+ return False
+ if not any(t is Error for _, t, _ in tokens):
+ return False
+ for text, offset, expected in _PROBES_MUST_BE_CLEAN:
+ try:
+ tokens = list(lexer.get_tokens_unprocessed(text))
+ except Exception:
+ return False
+ if any(t is Error for _, t, _ in tokens):
+ return False
+ at = [t for i, t, _ in tokens if i == offset]
+ if len(at) != 1 or at[0] is not expected:
+ return False
+ return True
+
+
+def setup(app):
+ if not _installed_lexer_is_fixed():
+ app.add_lexer('bitbake', BitBakeLexer)
+ return {
+ 'version': __version__,
+ 'parallel_read_safe': True,
+ 'parallel_write_safe': True,
+ }
--
2.50.0.173.g8b6f19ccfc3a
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/7] sphinx: add a lexer for BitBake with placeholders
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 ` Trevor Woerner
2026-11-25 15:45 ` [PATCH 3/7] sphinx: add a lexer for kernel metadata SCC files Trevor Woerner
` (5 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2026-11-25 15:45 UTC (permalink / raw)
To: docs
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)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
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
diff --git a/documentation/conf.py b/documentation/conf.py
index cdd554e30c0a..95bb24002544 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -80,7 +80,8 @@ extensions = [
'sphinx_tags',
'sphinxcontrib.rsvgconverter',
'yocto-vars',
- 'bitbake-lexer'
+ 'bitbake-lexer',
+ 'bitbake-placeholder'
]
# current_version = "dev"
diff --git a/documentation/sphinx-static/theme_overrides.css b/documentation/sphinx-static/theme_overrides.css
index 85f01eafbb94..2083ebb5baf4 100644
--- a/documentation/sphinx-static/theme_overrides.css
+++ b/documentation/sphinx-static/theme_overrides.css
@@ -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;
+}
diff --git a/documentation/sphinx/bitbake-placeholder.py b/documentation/sphinx/bitbake-placeholder.py
new file mode 100644
index 000000000000..8141ac7b5687
--- /dev/null
+++ b/documentation/sphinx/bitbake-placeholder.py
@@ -0,0 +1,145 @@
+"""BitBake with documentation placeholders: the ``bitbake-placeholder`` dialect.
+
+The manuals write ``<like this>`` for "replace this with your own value".
+BitBake has no way to express that, so the convention behaves differently
+depending on where it lands: inside a quoted value it is legal BitBake and
+takes ordinary string colour, indistinguishable from a literal; in a
+variable name it is not BitBake at all, because ``<`` is not in BitBake's
+name charset.
+
+This lexer differs from plain BitBake in exactly two ways, and in no
+others:
+
+- it **accepts** a placeholder where BitBake's charsets do not, so
+ ``SRCREV:pn-<recipe> = "${AUTOREV}"`` lexes as the assignment it is
+ plainly meant to be
+- it **marks** a placeholder wherever it appears, so a reader can tell it
+ apart from text to be typed verbatim
+
+Everything else is inherited, so a block tagged ``bitbake-placeholder``
+still fails on a genuine mistake. That is the point of a dialect rather
+than a permissive lexer: it admits one convention, not all errors.
+
+``Generic.Emph`` carries the placeholder. ``Name.Placeholder`` would be
+the obvious choice and is a trap: it has no entry in Pygments'
+``STANDARD_TYPES``, so the HTML formatter walks up to ``Name`` and emits
+``class="n"``, which is indistinguishable from every other name.
+"""
+import importlib
+
+from pygments.lexer import bygroups, inherit, this, using
+from pygments.token import Generic, Keyword, Name, Operator, String, \
+ Whitespace
+
+__version__ = '1.0'
+
+
+def _base_lexer():
+ """The BitBake lexer this dialect extends.
+
+ Prefer the carried one, since it is the lexer the manuals are written
+ against, and fall back to the stock lexer if ``bitbake-lexer.py`` is
+ absent, so this file does not depend on it.
+
+ Resolving through ``get_lexer_by_name('bitbake')`` does not work here:
+ ``app.add_lexer`` registers with Sphinx rather than with Pygments, so
+ the lookup returns the stock lexer even when the carried one is
+ registered.
+ """
+ try:
+ return importlib.import_module('bitbake-lexer').BitBakeLexer
+ except Exception:
+ from pygments.lexers.bitbake import BitBakeLexer
+ return BitBakeLexer
+
+
+_PH = r'<[^<>\n]+>'
+
+# A variable name that may carry placeholders. Deliberately not derived
+# from the base lexer's own pattern: this file has to work against either
+# base, and a name is the one thing the two agree on.
+_NCHAR = r'(?:\$\{[^{}\s]+\}|[A-Za-z0-9_\-.+/~${}])'
+_PNAME = r':?(?:' + _NCHAR + r'|' + _PH + r')+'
+_POVERRIDE = r'(?::(?:' + _NCHAR + r'|' + _PH + r')+)*'
+_ASSIGN = r'(?:\?\?=|\?=|:=|\+=|=\+|\.=|=\.|=)'
+
+# Fire only where a placeholder is actually present in the name. Without
+# this the dialect would accept ``PV = 1.2.3``, which no BitBake accepts:
+# the rules below are unguarded, so anything they match bypasses the
+# inherited rules and their checks. A dialect has to admit one convention,
+# not all errors, and this is what holds it to that.
+_HAS_PH = (r'(?=(?:export[ \t]+)?(?:' + _NCHAR + r'|:)*' + _PH + r')')
+
+
+class BitBakePlaceholderLexer(_base_lexer()):
+ """BitBake, plus the manuals' ``<replace this>`` convention."""
+
+ name = 'BitBake with placeholders'
+ aliases = ['bitbake-placeholder']
+ filenames = []
+ mimetypes = []
+ url = 'https://docs.yoctoproject.org'
+
+ tokens = {
+ 'root': [
+ # An assignment whose name or override chain carries a
+ # placeholder. This comes first because the inherited rules are
+ # guarded by BitBake's own regexes, which reject such a name
+ # outright, so the line would never reach them.
+ #
+ # A placeholder inside a varflag, ``FOO[<flag>] = "1"``, is not
+ # handled: the manuals contain none, and supporting a form
+ # nobody writes is a rule nobody can check.
+ (r'^' + _HAS_PH
+ + r'(export[ \t]+)?(' + _PNAME + r')(' + _POVERRIDE + r')'
+ r'([ \t]*)(' + _ASSIGN + r')',
+ bygroups(Keyword.Type, using(this, state='placeholder-name'),
+ using(this, state='placeholder-name'), Whitespace,
+ Operator),
+ 'value'),
+ inherit,
+ ],
+
+ # Split a name into its placeholder and non-placeholder parts, so
+ # ``pn-<recipe>`` shows which half the reader has to replace.
+ 'placeholder-name': [
+ (_PH, Generic.Emph),
+ (r':', Name.Decorator),
+ (r'[^<:\n]+', Name.Variable),
+ (r'[^\n]', Name.Variable),
+ ],
+
+ # Marking, as opposed to accepting. A placeholder inside a value is
+ # already valid BitBake; it just looks like a literal.
+ #
+ # The second rule in each state is what makes the first one work.
+ # The inherited states end in a greedy run of "anything that is not
+ # a quote, dollar or backslash", which swallows a whole value
+ # including its placeholders as one token, so the rule above never
+ # gets a position to match at. Stopping at the next "<" hands each
+ # placeholder back to it.
+ 'value': [
+ (_PH, Generic.Emph),
+ (r'[^<\s"\'$\\]+', String),
+ inherit,
+ ],
+ 'string-double': [
+ (_PH, Generic.Emph),
+ (r'[^<"\\$\n]+', String.Double),
+ inherit,
+ ],
+ 'string-single': [
+ (_PH, Generic.Emph),
+ (r"[^<'\\$\n]+", String.Single),
+ inherit,
+ ],
+ }
+
+
+def setup(app):
+ app.add_lexer('bitbake-placeholder', BitBakePlaceholderLexer)
+ return {
+ 'version': __version__,
+ 'parallel_read_safe': True,
+ 'parallel_write_safe': True,
+ }
--
2.50.0.173.g8b6f19ccfc3a
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/7] sphinx: add a lexer for kernel metadata SCC files
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 ` Trevor Woerner
2026-11-25 15:45 ` [PATCH 4/7] sphinx: add a lexer for wic kickstart files Trevor Woerner
` (4 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2026-11-25 15:45 UTC (permalink / raw)
To: docs
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)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
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
diff --git a/documentation/conf.py b/documentation/conf.py
index 95bb24002544..210b4ab60595 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -81,7 +81,8 @@ extensions = [
'sphinxcontrib.rsvgconverter',
'yocto-vars',
'bitbake-lexer',
- 'bitbake-placeholder'
+ 'bitbake-placeholder',
+ 'scc-lexer'
]
# current_version = "dev"
diff --git a/documentation/sphinx/scc-lexer.py b/documentation/sphinx/scc-lexer.py
new file mode 100644
index 000000000000..dd1166ca7014
--- /dev/null
+++ b/documentation/sphinx/scc-lexer.py
@@ -0,0 +1,116 @@
+"""Lexer for kernel metadata SCC description files.
+
+SCC describes a BSP or a kernel feature: which branch to build on, which
+patches to apply and which configuration fragments to queue. The tooling
+that reads it is ``yocto-kernel-tools``, and the shape of the language
+follows from how that tooling works rather than from how it looks. ``spp``
+rewrites a few line-oriented directives, and then ``scc`` *sources the
+result as a bash script*, having first defined one shell function per
+statement and unset ``PATH`` so nothing else can run.
+
+So an SCC file is not a dialect of bash but bash itself, under a
+preprocessor: the ``spp`` directives have their own, non-shell semantics -
+``#define`` is a comment as far as bash is concerned - while everything
+surviving that pass is ordinary shell with a fixed vocabulary of commands.
+Real metadata relies on it, with conditionals on ``KARCH`` in particular,
+and a lexer built from the manual's statement list rejects them. This one
+extends the bash lexer and marks the vocabulary, so the shell half is
+right by construction and only the command list has to be got right.
+
+That list comes from the implementation: the functions ``scc`` defines
+itself, the functions it sources from ``scc-cmds/*.cmd``, and the
+directives ``spp`` matches before any of that runs. It is wider than the
+"SCC Description File Reference" section of ``kernel-dev/advanced.rst``,
+which omits ``mark``, ``merge``, ``tag``, ``prefix``, and the flags.
+"""
+from pygments.lexer import bygroups, inherit, words
+from pygments.lexers.shell import BashLexer
+from pygments.token import Comment, Keyword, Name, Text, Whitespace
+
+__version__ = '2.0'
+
+# Statements, as the tooling defines them. ``spp`` handles include, patch
+# and kconf itself; the rest are shell functions declared by scc and by
+# scc-cmds/*.cmd before the file is sourced.
+_COMMANDS = (
+ 'branch', 'define', 'git', 'include', 'kconf', 'mark', 'merge',
+ 'patch', 'prefix', 'reloc_dir', 'set_kernel_version', 'tag',
+)
+
+# spp matches this before bash ever sees the file, so it is a directive
+# wearing a comment's clothes and needs its own rule.
+_DIRECTIVES = ('#define',)
+
+# Words that qualify a statement rather than starting one: the kconf
+# fragment classes kconf.cmd tests for, and the flags spp looks for on an
+# include line.
+_FLAGS = (
+ 'as_module', 'hardware', 'non-hardware', 'nocfg', 'nopatch',
+ 'optional', 'required',
+)
+
+# spp recognises these only immediately ahead of kconf, at the margin.
+_LEADERS = ('as_module', 'force')
+
+# A statement sits at the margin. Reaching it reliably needs the rule
+# below that stops a run of whitespace at the end of a line.
+_MARGIN = r'^[ \t]*'
+
+
+class SccLexer(BashLexer):
+ """Kernel metadata SCC description files."""
+
+ name = 'SCC'
+ aliases = ['scc']
+ filenames = ['*.scc']
+ mimetypes = []
+ url = 'https://docs.yoctoproject.org/kernel-dev/advanced.html'
+
+ tokens = {
+ 'root': [
+ # Both spellings of define name a variable, so mark it.
+ (r'(' + _MARGIN + r')(' + '|'.join(_DIRECTIVES) +
+ r')([ \t]+)([A-Za-z_]\w*)',
+ bygroups(Whitespace, Comment.Preproc, Whitespace,
+ Name.Variable)),
+ (r'(' + _MARGIN + r')(define)([ \t]+)([A-Za-z_]\w*)',
+ bygroups(Whitespace, Keyword, Whitespace, Name.Variable)),
+
+ # A statement only starts a line. Elsewhere the same word is
+ # an argument: "branch" is a command at the margin and a
+ # subcommand in "git branch pvr master".
+ (r'(' + _MARGIN + r')((?:' + '|'.join(_LEADERS) +
+ r')(?=[ \t]))?([ \t]*)('
+ + '|'.join(_COMMANDS) + r')(?=[ \t]|$)',
+ bygroups(Whitespace, Name.Builtin, Whitespace, Keyword)),
+
+ (words(_FLAGS, prefix=r'(?<=[ \t])', suffix=r'(?=[ \t]|$)'),
+ Name.Builtin),
+
+ # Keep whitespace runs from crossing a line ending, so the
+ # next statement is still at the margin when it is reached.
+ (r'[ \t]*\n', Whitespace),
+
+ # The bash lexer's own copy of this rule swallows the newline
+ # and the indent behind it, which would leave a statement
+ # inside a conditional no longer at the margin and so
+ # unmarked. Match the words alone and leave the rest.
+ (r'\b(if|fi|else|while|in|do|done|for|then|return|function|'
+ r'case|select|break|continue|until|esac|elif)\b', Keyword),
+
+ # Cosmetic: patch filenames conventionally lead with a
+ # sequence number, and bash would colour that as a number.
+ (r'\d+(?=[\w./+-])', Text),
+
+ inherit,
+ ],
+ }
+
+
+def setup(app):
+ app.add_lexer('scc', SccLexer)
+ return {
+ 'version': __version__,
+ 'parallel_read_safe': True,
+ 'parallel_write_safe': True,
+ }
--
2.50.0.173.g8b6f19ccfc3a
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/7] sphinx: add a lexer for wic kickstart files
2026-11-25 15:45 [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Trevor Woerner
` (2 preceding siblings ...)
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
2026-11-25 15:45 ` [PATCH 5/7] sphinx: add a lexer for pydevshell sessions Trevor Woerner
` (3 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2026-11-25 15:45 UTC (permalink / raw)
To: docs
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/7] sphinx: add a lexer for pydevshell sessions
2026-11-25 15:45 [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Trevor Woerner
` (3 preceding siblings ...)
2026-11-25 15:45 ` [PATCH 4/7] sphinx: add a lexer for wic kickstart files Trevor Woerner
@ 2026-11-25 15:45 ` Trevor Woerner
2026-11-25 15:45 ` [PATCH 6/7] sphinx: read a bare "#" in a console block as output Trevor Woerner
` (2 subsequent siblings)
7 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2026-11-25 15:45 UTC (permalink / raw)
To: docs
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)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
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
diff --git a/documentation/conf.py b/documentation/conf.py
index f89926549d20..3a7e3c920fc4 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -83,7 +83,8 @@ extensions = [
'bitbake-lexer',
'bitbake-placeholder',
'scc-lexer',
- 'wks-lexer'
+ 'wks-lexer',
+ 'pydevshell-lexer'
]
# current_version = "dev"
diff --git a/documentation/sphinx/pydevshell-lexer.py b/documentation/sphinx/pydevshell-lexer.py
new file mode 100644
index 000000000000..a0dd7c9fa684
--- /dev/null
+++ b/documentation/sphinx/pydevshell-lexer.py
@@ -0,0 +1,48 @@
+"""Lexer for ``bitbake -c pydevshell`` sessions.
+
+The development manual shows a session in BitBake's Python development
+shell: expressions typed at a ``pydevshell> `` prompt with their results
+beneath. No existing lexer reads it. ``console`` is a shell session and
+wants a prompt ending in ``$``, ``#``, or ``%``; ``pycon`` wants ``>>>``.
+Both mark the whole block as program output, which the theme renders in
+grey, so the block ends up dimmer than the prose around it and no better
+told apart.
+
+The prompt is not ours to change: ``devshell.bbclass`` sets
+``ps1 = "pydevshell> "``, so what the manual shows is what the reader
+sees. That leaves teaching a lexer the prompt as the only way to render
+one of these correctly.
+
+``ShellSessionBaseLexer`` does the work once ``_ps1rgx`` matches: it
+splits the typed line from its output and hands the typed part to an inner
+lexer, which here is Python.
+"""
+import re
+
+from pygments.lexers.python import PythonLexer
+from pygments.lexers.shell import ShellSessionBaseLexer
+
+__version__ = '1.0'
+
+
+class PyDevShellSessionLexer(ShellSessionBaseLexer):
+ """A session in BitBake's Python development shell."""
+
+ name = 'BitBake pydevshell session'
+ aliases = ['pydevshell']
+ filenames = []
+ mimetypes = []
+ url = 'https://docs.yoctoproject.org/dev-manual/python-development-shell.html'
+
+ _innerLexerCls = PythonLexer
+ _ps1rgx = re.compile(r'^(pydevshell> )(.*\n?)')
+ _ps2 = '... '
+
+
+def setup(app):
+ app.add_lexer('pydevshell', PyDevShellSessionLexer)
+ return {
+ 'version': __version__,
+ 'parallel_read_safe': True,
+ 'parallel_write_safe': True,
+ }
--
2.50.0.173.g8b6f19ccfc3a
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/7] sphinx: read a bare "#" in a console block as output
2026-11-25 15:45 [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Trevor Woerner
` (4 preceding siblings ...)
2026-11-25 15:45 ` [PATCH 5/7] sphinx: add a lexer for pydevshell sessions Trevor Woerner
@ 2026-11-25 15:45 ` 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
7 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2026-11-25 15:45 UTC (permalink / raw)
To: docs
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)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
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
diff --git a/documentation/conf.py b/documentation/conf.py
index 3a7e3c920fc4..5db20ff021fc 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -84,7 +84,8 @@ extensions = [
'bitbake-placeholder',
'scc-lexer',
'wks-lexer',
- 'pydevshell-lexer'
+ 'pydevshell-lexer',
+ 'console-lexer'
]
# current_version = "dev"
diff --git a/documentation/sphinx/console-lexer.py b/documentation/sphinx/console-lexer.py
new file mode 100644
index 000000000000..0f9eaa4ce33e
--- /dev/null
+++ b/documentation/sphinx/console-lexer.py
@@ -0,0 +1,53 @@
+"""A console session lexer that reads a bare ``#`` as output, not a prompt.
+
+Pygments treats ``$``, ``#``, and ``%`` alike and allows the preamble
+before them to be empty, so a line beginning ``#`` is a root prompt and
+the rest of the line is lexed as the command it introduces. In these
+manuals that is wrong far more often than it is right: a ``#`` opening a
+line is a comment or a line of program output, and a root prompt carries
+the ``user@host:path`` preamble that says whose root it is.
+
+Requiring that preamble before a ``#`` is the whole of the change.
+``$`` and ``%`` keep Pygments' behaviour exactly, bare prompt included.
+A line that is no longer a prompt falls through to ``Generic.Output``,
+which is what it always was.
+
+This is a local convention rather than a universal one - outside these
+manuals a bare ``#`` really is how a root shell prompts - so it belongs
+here and not upstream.
+"""
+import re
+
+from pygments.lexers.shell import BashSessionLexer
+
+__version__ = '1.0'
+
+# Pygments' own preamble alternation, spelled twice: once as it has it,
+# and once with the empty branch removed. Keeping its wording rather than
+# writing a tidier one means a prompt shape it learns later still works.
+_PREAMBLE = (r'(?:\[.*?\])|(?:\(\S+\))?'
+ r'(?:| |sh\S*?|\w+\S+[@:]\S+(?:\s+\S+)?|\[\S+[@:][^\n]+\].+)')
+_NAMED = (r'(?:\[.*?\])|(?:\(\S+\))?'
+ r'(?:sh\S*?|\w+\S+[@:]\S+(?:\s+\S+)?|\[\S+[@:][^\n]+\].+)')
+
+
+class ConsoleSessionLexer(BashSessionLexer):
+ """A console session in which a bare ``#`` is not a root prompt."""
+
+ name = 'Console session'
+ aliases = ['console']
+ filenames = []
+ mimetypes = []
+
+ _ps1rgx = re.compile(
+ r'^((?:' + _PREAMBLE + r')\s*[$%]\s*'
+ r'|(?:' + _NAMED + r')\s*#\s*)(.*\n?)')
+
+
+def setup(app):
+ app.add_lexer('console', ConsoleSessionLexer)
+ return {
+ 'version': __version__,
+ 'parallel_read_safe': True,
+ 'parallel_write_safe': True,
+ }
--
2.50.0.173.g8b6f19ccfc3a
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 7/7] sphinx: mark placeholders in console and plain-text examples
2026-11-25 15:45 [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Trevor Woerner
` (5 preceding siblings ...)
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 ` Trevor Woerner
2026-11-26 16:33 ` [docs] [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Antonin Godard
7 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2026-11-25 15:45 UTC (permalink / raw)
To: docs
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)
Signed-off-by: Trevor Woerner <twoerner@gmail.com>
---
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
diff --git a/documentation/conf.py b/documentation/conf.py
index 5db20ff021fc..d56c648d8701 100644
--- a/documentation/conf.py
+++ b/documentation/conf.py
@@ -85,7 +85,8 @@ extensions = [
'scc-lexer',
'wks-lexer',
'pydevshell-lexer',
- 'console-lexer'
+ 'console-lexer',
+ 'placeholder-lexers'
]
# current_version = "dev"
diff --git a/documentation/sphinx-static/theme_overrides.css b/documentation/sphinx-static/theme_overrides.css
index 2083ebb5baf4..2120c43245cc 100644
--- a/documentation/sphinx-static/theme_overrides.css
+++ b/documentation/sphinx-static/theme_overrides.css
@@ -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;
diff --git a/documentation/sphinx/placeholder-lexers.py b/documentation/sphinx/placeholder-lexers.py
new file mode 100644
index 000000000000..668a3b71e992
--- /dev/null
+++ b/documentation/sphinx/placeholder-lexers.py
@@ -0,0 +1,134 @@
+"""Marking placeholders in languages whose lexers already accept them.
+
+``bitbake-placeholder`` exists because BitBake *rejects* a placeholder in
+a variable name: ``<`` is not in its name charset, so
+``SRCREV:pn-<recipe>`` is not an assignment at all until a rule says so.
+Widening a grammar has to be done in the grammar.
+
+Everywhere else there is nothing to widen. ``$ devtool modify <recipe>``
+is a perfectly ordinary console line; the placeholder simply looks like
+text to type verbatim. All that is needed is to re-label the run, and
+that can be done after lexing, for any language, without touching how it
+parses.
+
+So this carries a filter rather than a dialect, and builds the dialects
+from it. Most of the manuals' placeholders are in console blocks, so this
+is where the convention is most often unreadable.
+
+The filter works on absolute offsets rather than on token values, because
+a base lexer may already have split the run: the shell lexer reads ``<``
+as a redirection operator, so ``<recipe>`` never arrives as one token.
+
+Output is marked as well as input. A session lexer can tell a typed line
+from a printed one, but that does not decide whether a run is a
+placeholder: a usage synopsis is printed by the tool and exists precisely
+to say what the reader supplies.
+
+Each dialect is opt-in per block. Angle brackets mean other things, such
+as ``<idle>-0`` in an ftrace listing, where ``<idle>`` is the kernel's own
+name for the idle task. Apart from a C ``#include``, which is excluded
+below, no pattern can tell those from a placeholder, so a person decides
+per block, and a block whose printed text should not be marked is simply
+left out.
+
+An address in the angle brackets RFC 822 wants is safe by construction
+rather than by exclusion: ``@`` is not in the placeholder charset.
+"""
+import importlib
+import re
+
+from pygments.filter import Filter
+from pygments.lexers.special import TextLexer
+from pygments.token import Generic
+
+# The corrected console lexer, not Pygments' own, so a placeholder block
+# reads a bare "#" the same way every other console block does. The
+# module name is not an identifier, so it cannot be a plain import.
+BashSessionLexer = importlib.import_module('console-lexer').ConsoleSessionLexer
+
+__version__ = '1.0'
+
+# Opens with a letter, then word characters, spaces and the punctuation a
+# path or a dotted name needs. No "@", so an e-mail address never matches.
+PLACEHOLDER = re.compile(r'<[A-Za-z][\w .\'/-]*>')
+
+# The one bracketed form that is never a placeholder however a block is
+# labelled, because it is C rather than prose: the reader does not
+# substitute the header in "#include <near/dbus.h>". This is mechanical
+# and needs no per-block judgement, unlike the opt-in itself.
+INCLUDE = re.compile(r'#\s*include\s*$')
+
+
+def placeholder_spans(text):
+ """Offsets of the runs to mark."""
+ return [m.span() for m in PLACEHOLDER.finditer(text)
+ if not INCLUDE.search(text[:m.start()].rsplit('\n', 1)[-1])]
+
+
+class PlaceholderFilter(Filter):
+ """Re-label placeholder runs in a finished token stream."""
+
+ def filter(self, lexer, stream):
+ tokens = list(stream)
+ text = ''.join(value for _, value in tokens)
+ spans = placeholder_spans(text)
+ if not spans:
+ yield from tokens
+ return
+
+ split, pos = [], 0
+ for ttype, value in tokens:
+ end = pos + len(value)
+ cuts = sorted({pos, end} | {edge for span in spans
+ for edge in span if pos < edge < end})
+ for a, b in zip(cuts, cuts[1:]):
+ inside = any(s <= a and b <= e for s, e in spans)
+ split.append(((Generic.Emph if inside else ttype), text[a:b]))
+ pos = end
+
+ # Merge adjacent pieces of the same type. Keeping the base lexer's
+ # boundaries emits one span per fragment, and an outlined style
+ # then draws a box around each half of the same placeholder.
+ merged = []
+ for ttype, value in split:
+ if merged and merged[-1][0] is ttype:
+ merged[-1] = (ttype, merged[-1][1] + value)
+ else:
+ merged.append((ttype, value))
+ yield from merged
+
+
+def _filtered(class_name, lexer_name, alias, base):
+ """A copy of `base` that marks placeholders and changes nothing else."""
+
+ def __init__(self, **options):
+ base.__init__(self, **options)
+ self.add_filter(PlaceholderFilter())
+
+ return type(class_name, (base,), {
+ '__init__': __init__,
+ '__doc__': '%s, with placeholders marked.' % lexer_name,
+ 'name': lexer_name,
+ 'aliases': [alias],
+ 'filenames': [],
+ 'mimetypes': [],
+ })
+
+
+ConsolePlaceholderLexer = _filtered(
+ 'ConsolePlaceholderLexer', 'Console session with placeholders',
+ 'console-placeholder', BashSessionLexer)
+
+TextPlaceholderLexer = _filtered(
+ 'TextPlaceholderLexer', 'Plain text with placeholders',
+ 'text-placeholder', TextLexer)
+
+
+def setup(app):
+ for lexer in (ConsolePlaceholderLexer, TextPlaceholderLexer):
+ app.add_lexer(lexer.aliases[0], lexer)
+ return {
+ 'version': __version__,
+ 'parallel_read_safe': True,
+ 'parallel_write_safe': True,
+ }
--
2.50.0.173.g8b6f19ccfc3a
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [docs] [PATCH 0/7] sphinx: carry lexers for the languages the manuals show
2026-11-25 15:45 [PATCH 0/7] sphinx: carry lexers for the languages the manuals show Trevor Woerner
` (6 preceding siblings ...)
2026-11-25 15:45 ` [PATCH 7/7] sphinx: mark placeholders in console and plain-text examples Trevor Woerner
@ 2026-11-26 16:33 ` Antonin Godard
2026-11-26 22:26 ` Trevor Woerner
7 siblings, 1 reply; 10+ messages in thread
From: Antonin Godard @ 2026-11-26 16:33 UTC (permalink / raw)
To: twoerner, docs
Hi Trevor,
On Wed Nov 25, 2026 at 4:45 PM CET, Trevor Woerner via docs wrote:
> 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.
For most of the series, the code is unfortunately unreviewable and I don't
think we want to maintain that in the future. While I think there is some
justification in adding lexers (better readability), I also think we could aim
for an in-between:
Pygments already has an upstream BitBake lexer (thanks to you). It can cover
most of our existing snippets. For the ones that are failing, we can skip them
(with a 'text' code-block) until the upstream lexer is fixed. Having our own
BitBake lexer will not encourage upstream fixes - it will hide those upstream
errors and will rarely lead to an upstream fix.
Patch 4 and 5, however, look like simple lexers, I am fine with keeping them.
For the remaining lexers, I think we can accept that they won't be highlighted
(or highlight them with a similar lexer, if that is possible).
> 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]
Can you rebase on master? These two series won't be merged before M1 anyway as
they require some updates on the Autobuilder.
Thanks,
Antonin
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [docs] [PATCH 0/7] sphinx: carry lexers for the languages the manuals show
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
0 siblings, 0 replies; 10+ messages in thread
From: Trevor Woerner @ 2026-11-26 22:26 UTC (permalink / raw)
To: Antonin Godard; +Cc: docs
On Thu, Nov 26, 2026 at 11:33 AM Antonin Godard
<antonin.godard@bootlin.com> wrote:
>
> Hi Trevor,
>
> On Wed Nov 25, 2026 at 4:45 PM CET, Trevor Woerner via docs wrote:
> > 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.
>
> For most of the series, the code is unfortunately unreviewable and I don't
> think we want to maintain that in the future. While I think there is some
> justification in adding lexers (better readability), I also think we could aim
> for an in-between:
>
> Pygments already has an upstream BitBake lexer (thanks to you). It can cover
> most of our existing snippets. For the ones that are failing, we can skip them
> (with a 'text' code-block) until the upstream lexer is fixed. Having our own
> BitBake lexer will not encourage upstream fixes - it will hide those upstream
> errors and will rarely lead to an upstream fix.
>
> Patch 4 and 5, however, look like simple lexers, I am fine with keeping them.
> For the remaining lexers, I think we can accept that they won't be highlighted
> (or highlight them with a similar lexer, if that is possible).
>
> > 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]
>
> Can you rebase on master? These two series won't be merged before M1 anyway as
> they require some updates on the Autobuilder.
Absolutely! v2 coming up :-)
Thanks
>
> Thanks,
> Antonin
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-11-26 22:26 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 4/7] sphinx: add a lexer for wic kickstart files Trevor Woerner
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox