Repository navigation
compiler: lex listings' \lstinline as a raw delimited argument - #188
Merged
Merged
Conversation
`\lstinline|x y|` reached the parser as an ordinary `TokenKind::Command`, so every use raised "\lstinline is not supported by this compiler version" and the delimiters and body were typeset as prose. listings reads it exactly the way `\verb` reads its argument, and the compiler already has that path. This is the `\lstinline` half of draft PR #145, written against main rather than merged (#145 is render-pipeline only and predates the NFSS font selection main has since gained; its render-pipeline half is not reused). ## Lexing `\lstinline` joins `\verb` in the lexer's raw-argument branch, with the two differences listings.sty has: * an optional `[<key=value list>]` comes first, and is skipped only when it closes on the same line (otherwise `[` is the delimiter, as it would be for `\verb`); * the blanks after the command *are* skipped (`\@ifnextchar`), unlike `\verb`, whose very next character -- even a space -- is the delimiter; * `\lstinline{...}` closes on `}`. The keys are deliberately not interpreted here: they set no text (listings.sty's `\lstinline` does `\lstset{flexiblecolumns,#1}`), and the renderer scans `\lstset`/`\lstdefinestyle`/the local list from the source. The body is raw: `%`, `\`, `$`, `{` and `}` are not reinterpreted. `TokenKind::Verb` gains `listing: bool` so an unterminated one says "\lstinline has no closing delimiter on this line" under its own name. ## Getting it past the expansion engine `prepare_document` hides a `\verb` body from the TeX engine by blanking the bytes between the delimiters and recording the lexer's token, which the conversion then maps back by source position. `\lstinline` now takes the same route: its first five bytes are spelled over as `\verb` in the copy the engine reads, and the rest of the construct is blanked as before. The engine therefore needs no `\lstinline` primitive, never sees the keys or the delimiters, and the conversion's existing `"verb"` arm hands back *this* token -- the one the compiler's own lexer built, carrying the listing's real text. The `prepare_document` fast-path guard gained `\lstinline` so a document that uses it and nothing else is still prepared. ## Tests Three new parser tests: the six delimiter/option/brace forms above, the unterminated case and its message, and the non-closing-bracket case. The three lexer tests that spell out `TokenKind::Verb` carry the new field. `crates/compiler` `cargo test --release`: **398 passed, 0 failed, 4 ignored**. Control checkout of the same base (89e49fe, `git archive`): 395 passed, 0 failed, 4 ignored -- the three new ones are this change. Verified end to end through the compiler binary: `\lstinline|x y|`, `\lstinline[language=C]!int z!` and `\lstinline{p q}` in one paragraph produce three verbatim text items and no diagnostic beyond the pre-existing "packages listings are recognised but not implemented". ## Not in this change The listings *rendering* model -- `\lstset` keys, fixed/flexible columns and their lost-space kerns, frames, line numbers, keyword/comment/string styles, `breaklines` -- is render-pipeline work and is not attempted here. With this change `\lstinline` sets literal typewriter text, which is what listings' own default (`flexiblecolumns`, a typewriter `basicstyle`) comes to for the common case; a non-default `\lstinline[...]` is not yet honoured. `verbatim_display` still expands a tab to an 8-column tab stop and renders `\verb*`'s space as U+00B7. LaTeX does neither -- `\@verbatim` sets a tab as one ordinary space, and `\verb*` uses `\char32` of the typewriter font -- which is a real mismatch in this crate's own Core-14 layout. The render pipeline now reads those bytes from the source instead of from this string (companion PR), so it is unaffected; fixing `verbatim_display` itself would change committed compiler layout expectations and is left as its own change. Implementation-Agent: engine-engineer (linux-primary, NixOS PC) Commit-Executor: engine-engineer via git (Cursor usage limit fallback) Co-authored-by: GoKubar <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar
marked this pull request as ready for review
September 13, 2026 18:54
This was referenced Sep 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on main
89e49fed, not stacked.crates/compileronly. Companion to #187 (the render-pipeline half) and #183 (the typewriter fonts).What was wrong
\lstinline|x y|reached the parser as an ordinaryTokenKind::Command, so every use raised "\lstinline is not supported by this compiler version" and the delimiters and body were typeset as prose. listings reads it exactly the way\verbreads its argument, and the compiler already has that path.This is the
\lstinlinehalf of draft PR #145, written against main rather than merged — #145 is render-pipeline only, predates the NFSS font selection main has since gained, and its render-pipeline half is not reused (see #187).Lexing
\lstinlinejoins\verbin the lexer's raw-argument branch, with the differences listings.sty has:[<key=value list>]first, skipped only when it closes on the same line (otherwise[is the delimiter, as it would be for\verb);\@ifnextchar), unlike\verb, whose very next character — even a space — is the delimiter;\lstinline{...}closes on}.The keys are deliberately not interpreted here: they set no text (listings.sty's
\lstinlinedoes\lstset{flexiblecolumns,#1}), and the renderer scans\lstset/\lstdefinestyle/the local list from the source. The body is raw —%,\,$,{and}are not reinterpreted.TokenKind::Verbgainslisting: boolso an unterminated one says "\lstinline has no closing delimiter on this line" under its own name.Getting it past the expansion engine
prepare_documenthides a\verbbody from the TeX engine by blanking the bytes between the delimiters and recording the lexer's token, which the conversion maps back by source position.\lstinlinenow takes the same route: its first five bytes are spelled over as\verbin the copy the engine reads, and the rest of the construct is blanked as before.So the engine needs no
\lstinlineprimitive, never sees the keys or the delimiters, and the conversion's existing"verb"arm hands back this token — the one the compiler's own lexer built, carrying the listing's real text. Theprepare_documentfast-path guard gained\lstinlineso a document that uses it and nothing else is still prepared.Tests and gates
Three new parser tests: the six delimiter/option/brace forms, the unterminated case and its message, and the non-closing-bracket case. The three lexer tests that spell out
TokenKind::Verbcarry the new field.89e49fed(git archive)Verified end to end through the compiler binary:
\lstinline|x y|,\lstinline[language=C]!int z!and\lstinline{p q}in one paragraph produce three verbatim text items and no diagnostic beyond the pre-existing "packages listings are recognised but not implemented".Not in this change
\lstsetkeys, fixed/flexible columns and their lost-space kerns, frames, line numbers, keyword/comment/string styles,breaklines— is render-pipeline work and is not attempted. With this change\lstinlinesets literal typewriter text, which is what listings' own default (flexiblecolumnswith a typewriterbasicstyle) comes to for the common case; a non-default\lstinline[...]is not yet honoured.verbatim_displaystill expands a tab to an 8-column stop and renders\verb*'s space as U+00B7. LaTeX does neither:\@verbatimsets a tab as one ordinary space (pdfTeX puts<tab>oneone typewriter width from the margin, not eight), and\verb*uses\char32of the typewriter font. This is a real mismatch in this crate's own Core-14 layout. render-pipeline: literal text, and \verb/verbatim in the typewriter face NFSS selects #187 sidesteps it by reading those bytes from the source, so the render pipeline is unaffected; fixingverbatim_displayitself would move committed compiler layout expectations and is left as its own change. Filed here so it is not lost.Resume notes
crates/render-pipeline/vendor/compilerneeds a re-pin before render-pipeline: literal text, and \verb/verbatim in the typewriter face NFSS selects #187's28-lstinlinefixture can move fromNOT_YETto gated.lstinlineis still listed invocabulary.rs'sKNOWN_UNIMPLEMENTED_COMMANDS, exactly asverbis — harmless (the lexer intercepts both before the parser's command dispatch), but that list is stale for both and worth a separate tidy.🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu