Repository navigation
fix(parser): accept terminator-less then/do after ]] and (( )) in compound bodies - #475
Merged
Merged
Conversation
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.
Summary
Closes #460.
GNU bash accepts a terminator-less
thendirectly after a closed[[ ]]inside any compound body —f() { if [[ $x == y ]] then echo a; fi; }parses clean, and the real-worldGaelGosse/shell_function_n_shortcuts/.shortcutbattery-prompt function depends on it (elif [[ $charge == "Full" ]] then). rubash rejected it withsyntax error near unexpected token 'then', but only through the function-body path: the top-level parse parked the same error node invisibly inside the if-condition, sorubash -nfailed only with the function wrapper.Root cause
run_command_loop's "a complete compound command must be followed by a connector" check fired on the reserved wordthenafter the[[ ]]compound. GNU grammar:if_command: IF compound_list THEN ...wherecompound_list: newline_list list1(parse.y:1262) admits a singlepipeline_commandwith no terminator (parse.y:1323-1324), andreserved_word_acceptable(parse.y:5899) hasCOND_ENDin its predecessor set, sothenis recognized asTHENright after]].(( ))form needed one more admission: rubash folds(( x == y ))into a singleARITH_CMD-shaped keyword token, socommand_boundary_keyword_allowed(the section-stop predicate) did not see a command boundary beforethen. GNU'sreserved_word_acceptableacceptsARITH_CMDas a predecessor, same as the folded{ ... }group already handled there.Changes
src/parser/parse_loop.rs: the compound-connector check no longer fires when the next token is the reserved wordthen/doat a command boundary (command_boundary_keyword_allowed).src/parser/support.rs: a folded(( ... ))keyword token is a reserved-word-acceptable predecessor, alongside the existing folded{ ... }case.Rejection semantics preserved (pinned to GNU)
if true then/if echo hi >/dev/null then— after a plain WORD,thenis still an argument → rejected, as GNU.while [[ $x == y ]] then ... done(THEN/DONE mismatch) → rejected, as GNU.[[ a == a ]] echo x,[[ a == ]],[[ -n—[[ ]]existing semantics and diagnostics unchanged.if (( x == y )) then(top level and function body) andwhile (( x )) do/while [[ x == y ]] donow match GNU, which previously failed at top level too.Testing
tests/issue460_terminator_less_then_regressions.rs(19 tests): the issue's minimal repro, function brace/subshell/same-line/nested-group bodies,elifchains, terminator shapes (;/newline/none), arithmetic-predecessor forms, and[[ ]]non-regression. Every accept/reject verdict was pinned against the GNU oracle.D:\Git\usr\bin\bash.exe,bash -n). The ISSUE records WSL GNU bash 5.3.0 with identical verdicts on the repro; no 5.2/5.3 behavioral split was observed for this grammar production, but reviewers should note the recorded 5.3 oracle if any divergence surfaces in CI.cargo test --no-fail-faston this branch vs. stashed master: per-target results identical; no new failures (the pre-existingpwdlogical-mode andcli_testsbashdb/examples failures reproduce on master in this environment). The parser suite actually gains ~16 passes from the(( ))-form convergence. Related suites (issue322_cond_*,issue360_parser_overlax_*,issue443_*,issue424_*) all green.cargo fmtapplied (pre-commit hook passed).