Repository navigation
Lexer: keep last line of a C code file lacking a final newline - #3089
Merged
Merged
Conversation
Such a line matched no <ccode> rule and was echoed to stdout instead of reaching the generated C, e.g. losing a closing #endif or }. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
willend
force-pushed
the
lexer-unterminated-last-line
branch
from
November 11, 2026 09:05
5037dc5 to
c0c84d4
Compare
Contributor
Author
|
mccode-antlr parity: no collateral effect expected. mccode-antlr (0.36.0) already keeps a last line that lacks a newline, so this PR brings the C code generator in line with it. Test:
Tested on macOS arm64 only. 🤖 Generated with Claude Code |
2 tasks
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.
Free-form text area
TL;DR: A
%included library (or other C code file) whose last line has no trailing newline lost that line in the generated C. McStas echoed it to stdout instead, typically dropping a closing#endifor}and breaking compilation. This adds one lexer rule so the line is kept.Found with the ESS BIFROST model (niess / mccode-antlr), where
rfc-lib.handrfc-lib.cend without a newline:Change: one new
<ccode>rule inmccode/src/instrument.l. It can only be the longest match on an unterminated last line; it pushes the line back with a newline appended, so the existing rules (%},%include, plain code line) handle it. Details indocs/GRAMMAR/ADR-records/ADR_20261111_UNTERMINATED_LAST_LINE.md.Test output (code generation only, patched vs. unpatched
mcstasbuilt from this branch /main):#endiferrors are gone. (Its remaining errors are unrelated and handled upstream.)ESS_butterfly_MCPL_test,Test_Dispersion_relation_TAS, not investigated).Supermirror_thin_substrate,Test_lib_supermirror_lib):mcstas-comps/share/supermirror-lib.halso lacks a final newline, and its closing comment was silently dropped until now. Comment only, no behaviour change.%include "read_table-lib"generate and pass a compiler syntax check.Not tested: McXtrace (same lexer file, not built), Linux, Windows, and no compile-and-run of the example instruments.
Related upstream fix that adds the newlines: mcdotstar/mcstas-radial-filter-collimator#11
Declaration of use of AI-tools
Development OS / boundary conditions
macOS arm64 (clang), flex/bison from conda-forge. No new dependencies.
PR Checklist for contributing to McStas/McXtrace
My work touches the code-generator in mccode/src
🤖 Generated with Claude Code