@@ -80,7 +80,8 @@ extensions = [
'sphinx_tags',
'sphinxcontrib.rsvgconverter',
'yocto-vars',
- 'bitbake-lexer'
+ 'bitbake-lexer',
+ 'bitbake-placeholder'
]
# current_version = "dev"
@@ -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;
+}
new file mode 100644
@@ -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,
+ }
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