Repository navigation
fix(parser): if-construct error attribution with arithmetic commands (Refs #3184) - #3934
Merged
Merged
Conversation
…(Refs #3184) Two defects in the `if` diagnostic family, both about which token GNU's report_syntax_error (parse.y:6841) is reached with — yyerror (parse.y:6724) fires at the first offending token in stream order: 1. if_frame_offender (the resync scan used when parse_if_command fails) treated the lexer's folded arithmetic-command token — one Keyword token carrying the whole `((…))` text — as an illegal phase keyword and blamed it. An unclosed `if` whose condition or body holds a `((…))` reported `syntax error near unexpected token `((1))'` instead of `syntax error: unexpected end of file from `if' command on line 1`. GNU accepts ARITH_CMD wherever a command is accepted (parse.y:1203 arith_command); the scan now treats the folded token as the phase's command. 2. When a section of the `if` (condition, then/elif/else body, elif condition) errored and boundary recovery (find_if_then / scan_if_section_end) could not place a closer, the latched body error was discarded and the resync guessed another token. The if parser now returns the latched error itself on recovery failure: an argument-position `((` inside the construct names `(` (the lexer returns the bare `(` there — parse_dparen, parse.y:4895, is gated by reserved_word_acceptable, parse.y:4926), never an earlier `((…))` and never the EOF form. Regression pins: tests/issue3184_if_arith_eof_attribution.rs (14 defect cells + 7 controls, byte-compared against GNU Bash 5.3.20 script-file probes).
caomengxuan666
marked this pull request as ready for review
November 19, 2026 01:44
caomengxuan666
added a commit
that referenced
this pull request
Nov 19, 2026
## 概要 统一仓内对 `pwd` usage 行的互斥断言。产品侧的 usage/short-doc 早已是 `pwd [-LPW]`(`-W` 为 niu #993 §6 的既定扩展,见 `src/builtins/pwd.rs:123`、`src/builtins/help_texts.rs:1332`、`src/builtins/help.rs:608`),且 PR #3922 已把 issue3185 期望网格对齐到 `[-LPW]`;但 issue705 与 issue3348 的四处钉仍断言 GNU 形状 `pwd [-LP]`,与产品现状及其余钉(issue2753 / issue2791 / niubash993 / part_021 / issue3185 / issue3330)互斥。本 PR 把这四处断言 rubash 自身输出的钉对齐到 `[-LPW]`。 Refs #3924 ## 改动(逐钉) | 文件:行 | 原断言 | 处置 | | --- | --- | --- | | tests/issue705_error_branding.rs:395 | `pwd: usage: pwd [-LP]`(rubash `-c "pwd -Q"` 的 stderr 全文断言) | 改 `[-LPW]` | | tests/issue3348_comsub_forged_pwd_logical_regressions.rs:255 | `stderr.contains("pwd: usage: pwd [-LP]")` | 改 `[-LPW]` | | tests/issue3348_comsub_forged_pwd_logical_regressions.rs:269 | 同上 | 改 `[-LPW]` | | tests/issue3348_comsub_forged_pwd_logical_regressions.rs:298 | `stdout.starts_with("pwd: pwd [-LP]\n")`(`pwd --help` 首行) | 改 `[-LPW]` | 四处均经上下文核读,断言对象均为 rubash 自身输出,无一为 GNU 对照期望。 ## 本 PR 删除了什么 无删除。纯测试断言对齐:2 文件、4 行字符串内容变更;`src/` 一行未动;`tests/gnu-compat/upstream-rights/builtins.right:358,452` 的 GNU oracle golden(`pwd [-LP]`,GNU 本尊输出)原样保留。 ## 验证 服务器腿在工作区 REPORT 中记录(base fail-first + 对齐后逐 stem 跑绿 + issue3185 对照)。 UNVERIFIED-BY-CAPTAIN ## 队长复核(头 f66fd22) - 头 CI census 68:相对尖集**零新增**;issue3348 茎 18/18 绿、issue705 断言格全绿;goldens 基线二名;CLI 唯一红 = 已裁定 coproc flake。 - 对齐面:仅四处断言(issue705:395、issue3348:255/269/298)由 `[-LP]` 改为 `[-LPW]`;GNU golden builtins.right:358,452 原样保留,文档注释不动。旧断言对现产品必然假(产品串 `pwd [-LPW]` 不含 `pwd [-LP]` 子串),fail-first 由字面量分析成立。 - 注:车道 REPORT 的「腿结果」节为空(服务器腿未落盘);复核证据取头 CI census 按名裁定(两茎逐格绿),与现尖零交集已核(merge-base 以来仅 #3934 合入 parser 面),免 update-branch。合后手关 #3924。
caomengxuan666
added a commit
that referenced
this pull request
Nov 19, 2026
… shape (Refs #3936) parse_loop_command discarded latched parse errors in three places (#3184 defect B, same family, different file): parse_loop_body's None swallowed the body error, the condition vec was dropped with it, and find_loop_do's None never parsed the condition at all. GNU report_syntax_error (parse.y:6841) reports the first offending token in stream order, so an argument-position (( names ( (parse_dparen, parse.y:4895). Mirror PR #3934's latched-error return pattern: on recovery failure return the latched error (condition before body); with no latched error keep the None so the caller's EOF / mismatched-closer shape is unchanged.
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.
Refs #3184
本 PR 做了什么
修复 #3184 在当前 master(622ee661)上复验后剩余的唯一分歧家族:
if构造(condition / then / elif / else 各段)内含算术命令时的语法错误归因。冻结观察中的其余形状(run-parser 的 esac/do、run-comsub-posix 回显、run-arith 的"+ "、run-array 的<>、x1 shopt 回显)在当前尖已逐字与 GNU 一致,本 PR 不动。两处机制缺陷(GNU 锚:parse.y:6724 yyerror 于流序首个出错 token 触发;parse.y:6841 report_syntax_error):
parse_if_command失败后if_frame_offender决定报 mismatched-closer 还是 EOF 形;它把词法器折叠的算术命令令牌(单个 Keyword 令牌、值即整个((…)))当作非法 phase 关键字点名。未闭合if含((…))时误报syntax error near unexpected token '((1))',GNU 为syntax error: unexpected end of file from 'if' command on line 1(parse.y:6899)。GNU 文法在凡可接受命令处接受 ARITH_CMD(parse.y:1203),扫描现按 phase 的命令处理折叠令牌。find_if_then/scan_if_section_end找不到边界时,已锁存的段内错误被丢弃、由回退层猜测另一 token。现改为恢复失败时直接返回 latched error:构造内参数位的((报((词法器在该位置返回裸(——parse_dparen parse.y:4895 受 reserved_word_acceptable parse.y:4926 门控,参数位不通过),不再误报更早的((…))或 EOF 形。本 PR 删除了什么
无删除(纯增性修法 + 新回归钉文件)。
验证
tests/issue3184_if_arith_eof_attribution.rs:14 缺陷格 + 7 对照格,期望全部与 GNU bash 5.3.20 脚本文件探针逐字对齐(服务器腿结果见车道 REPORT)。