Repository navigation
compiler: recognize \lstinputlisting[options]{file} as a literal listing (GH-LSTINPUTLISTING) - #586
Conversation
What changed:
- parser: new \lstinputlisting[options]{file} arm. The {file} argument
resolves with exactly the \input/\include rules (path_is_safe gate,
document_by_path lookup with .tex appended as fallback); the file is
never parsed, its bytes become one Block::Verbatim like an inline
lstlisting body, so file listings count for \lstlistoflistings
purposes exactly like inline ones. Options run through the same
optional_bracket_argument parser with the same warn-and-typeset-
literally fallback. Missing files report 'listed file not found'
with the same error/recovery/help shape as a missing \input.
- vocabulary: lstinputlisting is a listings command; BUILT_INS so the
expansion engine passes it through as a host command.
- supported inventory (+ regenerated supported-latex.json, coverage
docs, Mac bundled copy): new [options]{file} entry.
What was run:
- cargo test --release --test lstinputlisting: 4 passed
- mutation check (dispatch arm reverted): 4 failed with
'\lstinputlisting is not supported by this compiler version'; restored: 4 passed
- cargo test --release (crates/compiler): 58 suites, 674 passed, 0 failed
(base before change: 57 suites, 0 failures)
- entry-point repro through flashtex_compiler::protocol::handle_line
(temporary test, deleted): file bytes typeset with code.py spans,
no unknown_command
Implementation-Agent: muse-spark-1.3-contributor
|
daniel-parent review (subagent) Verdict: READY (stacked on open #542 — see stacking note at the end) This is a fresh review; no prior What I checked
Non-blocking note (for the integration lane, not a finding against #586)#586's single commit ( StackingThis PR is stacked on open PR #542 (branch |
f89ef10
into
agent/daniel-parent/lstlisting-braced-options
Scope
Stacked on #542 (this PR's base branch) — builds on its
\lstlisting/\lstlistoflistingsoption-parsing and listing-numbering work rather than duplicating it. Do not diff this PR againstmain; diff against #542's head.\lstinputlisting[options]{file}(listings package) now recognizes and resolves the file, reusing\input/\include's exact file-resolution logic (verified by readingP::includefirst:token_text+ trim,path_is_safegate,document_by_pathlookup with.texappended as a fallback if the bare name isn't found — confirmed this compiler does append.tex, matching real listings.sty behavior). The optional[options]argument goes through the SAME parser #542 fixed forlstlisting(braced-]handling included), with the same warn-and-typeset-literally fallback. The file's raw bytes become oneBlock::Verbatim, identical in shape to an inline\begin{lstlisting}block, so it counts for\lstlistoflistingspurposes at the compiler level (there is no separate compiler-side listing counter to update — the render-pipeline owns that). Missing/unsafe paths get a clear diagnostic (listed file not found: looked for 'X' and 'X.tex'), matching\input's error style — no panic, no silent no-op.Overlap check
coord.py claims— no other claim on\lstinputlisting. Confirmed this branch's own diff (vs. #542's head, notmain) touches onlycrates/compiler/**anddocs/user/compiler.md— nothing undercrates/render-pipeline/.Test results
Focused run (
cargo test --test lstinputlisting):Independent mutation check (supervisor-run, fresh
CARGO_TARGET_DIR): disabled the dispatch arm →file_content_appears_as_a_literal_listingFAILED, tripping the codebase's own internal consistency assertion (assertion failed: !BUILT_INS.contains(&name)); restored → passes. Fullcargo test --releaseincrates/compiler(lane's own run): 58 suites, 674 passed, 0 failed.Entry-point repro (via
flashtex_compiler::protocol::handle_line, a two-document payload withmain.tex+code.py): compiling\lstinputlisting[caption=Example]{code}returns only the expected "options are not implemented" warning (options genuinely aren't wired to formatting yet, matchinglstlisting's own scope) —code.py's content is typeset literally with source spans pointing atcode.py, and the surroundingBefore./After.paragraphs stay intact.Not done
Render-pipeline
\lstlistoflistingspolish:crates/render-pipeline/src/listings.rs::scancounts/numbers/captions listings by scanning source text for\begin{lstlisting}and matching by body-span ranges within the SAME document. A\lstinputlisting-produced block carries spans in the INCLUDED file's document, so pipelinescanwon't currently pick it up for caption/number styling or the LoL page — the content still renders as literal typewriter lines (this PR's compiler lowering), just without pipeline-side numbering/captioning. Extendinglistings::scanto recognize\lstinputlistingis a separate render-pipeline slice, proposed as a follow-up.🤖 Generated with Claude Code