Repository navigation
fix(lexer): skip # comments in the alias pre-pass walkers (rubash#2033) - #2116
Merged
Merged
Conversation
…033)
Modernish `use sys/cmd/harden` killed initialization with
`harden.mm: eval: line 163: syntax error near unexpected token 'fi'`.
Root cause: the alias-live gather's streaming alias expander pre-pass
(`ComsubAliasScanner::drive`) and its batch twin
(`expand_comsub_alias_bodies`) walked command-substitution-unit scan text
with quote arms but no `#` comment arm. An apostrophe inside a comment
("modernish's" in harden.mm line 4) opened a phantom single-quote string:
the batch walker's quote skip then swallowed the rest of the input
(hiding real `$(` units from expansion), and the streaming phase PARKED
on the unterminated quote across whole input spans (rescan_park +
retry_deadline span throttle). The alias-live gather
(script_driver.rs read_next_source_group) then advanced its feeder/battery
verdict machines in bursts instead of per line, their state diverged from
the non-alias arm, and the completeness verdict wrongly blessed a
mid-function group cut (harden.mm lines 4..276 of 404); the cut chunk
failed to parse standalone at the `\esac` mode table. Without aliases the
same file gathered correctly, which is why the trigger is
`expand_aliases` + >=1 alias defined.
GNU anchor (parse.y:3631-3645 shell_getc): `#' at a shell_getc position
ALWAYS comments ("Discard until EOL or EOF"); a mid-word `#' (echo a#b)
never reaches shell_getc because read_token_word consumes word characters
without returning to the character feeder. Probed on WSL GNU Bash 5.3:
`echo a#b` -> `a#b`; `echo >#f` -> syntax error (`#' after `>' IS a
comment); `$( # hi ' there <NL> echo IN )` -> IN (comment apostrophes
inert).
Fix: give both pre-pass walkers an `at_word_start` token-boundary state
(true after input start / blank / newline / ; & | ( ) < >) and skip
`#`-at-token-start comments to EOL inert; the streaming form parks only
when the comment's newline is not yet fed, mirroring MainAliasScanner's
own `#' arm. stream==batch is preserved by construction.
Verification:
- regression tests/issue2033_alias_comsub_comment_park_regressions.rs
(3 tests; the sourced-hardem-module frame and the comsub-after-comment
pin both FAIL on the pre-fix binary, pass on this build)
- modernish end-to-end: `use sys/cmd/harden; type -t harden` ->
`function`, rc=0; multi-module `use` and repeat-`use` smoke green
- alias_stream streaming-contract unit tests 7/7
- comment-class GNU matrix (10 rows) byte-identical to GNU except two
rows pre-existing identically on the pristine binary
- true-baseline A/B, 19 suites (alias case casemod comsub comsub2
comsub-eof comsub-posix heredoc iquote nquote nquote1-5 quote
quotearray redir vredir): fixed ledger == pristine ledger per suite
fmt: cargo fmt hits "os error 206" in this environment; rustfmt run
explicitly on both touched files (rustfmt --check clean), commit uses
--no-verify for that environment reason only.
Fixes: #2033
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.
Closes #2033. Tracking root-cause comment: #2033 (comment)
Root cause
Modernish
use sys/cmd/hardenkilled initialization withharden.mm: eval: line 163: syntax error near unexpected token 'fi'.The alias-live gather's streaming alias expander pre-pass
(
ComsubAliasScanner::drive,src/lexer/alias_stream.rs) and its batchtwin (
expand_comsub_alias_bodies) walked their scan text with quotearms but no
#comment arm. An apostrophe inside a comment("modernish's" in harden.mm line 4) opened a phantom single-quote string:
real
$(units from alias expansion;input spans (rescan_park + retry_deadline span throttle); the gather
(
script_driver.rs read_next_source_group) then advanced itsfeeder/battery completeness machines in bursts instead of per line,
their state diverged from the non-alias arm, and the verdict wrongly
blessed a mid-function group cut (harden.mm lines 4..276 of 404). The
cut chunk fails to parse standalone at the
\esacmode table.Trigger shape explained: without aliases the raw arm gathers the same
file correctly (
expand_aliases+ >=1 alias defined is the switch), andwhole-string
evalwas clean because the batch entry path parses thefull text with the comment-aware main scanner.
GNU anchor: parse.y:3631-3645 shell_getc —
#' at a shell_getc position always comments until EOL; a mid-word#' never reaches shell_getc.Class probed on WSL GNU Bash 5.3 (matrix in the issue comment).
Fix
Both pre-pass walkers gain an
at_word_starttoken-boundary state (trueafter input start / blank / newline /
; & | ( ) < >);#at a tokenstart skips to EOL inert. The streaming form parks only when the
comment's newline is not yet fed (mirroring MainAliasScanner's own
#arm). stream==batch preserved by construction.
Verification
failing frames verified on the pre-fix binary, green here
use sys/cmd/harden; type -t harden->function, rc=0; multi-module + repeat-usesmoke green(identical on pristine; separate gaps)
fmt note:
cargo fmtfails with os error 206 in this environment;rustfmt was run explicitly on both touched files (rustfmt --check
clean). Commit uses --no-verify for that environment reason only.