Skip to content
3 changes: 2 additions & 1 deletion doc/architecture-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ Behavior policy:
The Godot-port stack reports tokenizer errors (from `ERROR` tokens) and parser errors (ported `push_error` messages) into the same diagnostic list, and recovers with Godot's panic-mode + `synchronize()` policy: advance to a statement/member boundary, then resume sibling parsing. Contract highlights:

- Illegal sources always terminate with diagnostics — never exceptions; a nesting-depth budget (256) guards the JVM stack against pathological nesting (Godot has no such limit; deliberate deviation)
- Failed expression slots keep marker/partial nodes via the parser's sealed `ParseOutcome` protocol: a zero-consumption slot holds a zero-width `ErrorExpression(CstIssueKind.MISSING)` at the failure point, a consumed-but-failed slot holds an `ERROR`-kind fragment over the consumed span, and a missing member name after `.` keeps a `MissingAttributeStep` in the surviving chain; damaged control-flow statements (if/while/for/assert/const/match headers, match guards/patterns, enum values) survive with markers in place. Missing closers (grouping/array/dictionary/call/subscript/annotation/preload/assert) produce zero-width `ERROR` diagnostics carrying a stable `code` plus a same-generation `RecoveryLink` to the owning construct. Constructs with no node able to carry the failure (e.g. a missing function name) are still omitted, and `ErrorStatement` is never synthesized
- Expression and type parsing use five sealed `ParseOutcome` states: `Ok` carries a healthy value, `EnclosedDamage` carries a complete structure with damaged children, and `Damaged` carries a partial value. `Missing` consumes nothing and leaves the context diagnostic to the caller; `Failed` already reported its cause and has no value. Expression slots keep a zero-width `MISSING` marker or an `ERROR` fragment when there is no node to retain. A closed array, dictionary, call, or subscript can preserve child damage and still participate in expression folding and shape checks. A grouping is transparent: with a real `)` it preserves the inner outcome.
- A missing member name after `.` keeps a `MissingAttributeStep` in the surviving chain. Damaged control-flow headers and other expression slots survive with markers in place. Missing closers produce zero-width diagnostics with a stable `code` and a same-generation `RecoveryLink` to the owning construct. Type parsing preserves usable damaged `TypeRef` text and its byte span without changing the public AST or serde. Constructs without a node able to carry the failure (e.g. a missing function name) are still omitted; the parser does not synthesize `ErrorStatement`.
- Known recovery limitation: a depth-budget trip on a multiline grouping continuation line can mis-attribute sibling scopes (registered in `doc/godot-java-parser-implementation.md` §9; diagnostics and termination still hold)

### Parity rule index
Expand Down
290 changes: 290 additions & 0 deletions doc/gdparser-0.7.1-issues-fix-plan.md

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions doc/godot-java-parser-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,11 @@ parity 语料分三类管理(非法源不适用 parity,另有独立验收规
- 中毒区域布局感知消耗:跳闸时记录跳闸行缩进 `poisonedLineIndent`(lexer 布局宽度口径,tab=4/space=1);`synchronize()` 在跳闸期间配对消费垃圾 INDENT/DEDENT(`garbageIndents` 计数)、吃掉 NEWLINE,行首 token 缩进 ≤ 跳闸行时停在边界前,超出配对余额的 DEDENT 停住留给已解析套件帧。
- tokenizer 错误必入诊断:`pushMultiline` 待丢弃 token 走 `scanSkippingErrors` 上报——vendor 裸 `scan()` 会静默丢弃 ERROR token,与「tokenizer 错误必入诊断」政策冲突,此为有意偏差。
- 非法源验收契约(§5.7 非法源条款的落地):不抛异常、可终止;≥1 条 ERROR 诊断且 range 不越界(UTF-8 字节口径);synchronize 后兄弟声明结构正确。
- sealed-outcome 恢复协议:表达式族解析返回密封接口 `ParseOutcome<T>`(`Ok`/`Missing`/`Failed`/`Damaged`)而非可空引用——`Missing` 为零消费且未推诊断(槽位宿主经 `absorbSlot` 补发泛化消息并填零宽 MISSING marker),`Failed` 为已推诊断、无节点(宿主填消费区间 ERROR 片段,不补发),`Damaged` 为已推诊断的部分节点(宿主保留,不补发)——单槽位单根因;Pratt 循环在非 `Ok` 左操作数处停折(与旧 null 停折逐点等价),后缀链内缺名点号续折(`MissingAttributeStep` 充当折叠障碍:后续 `(`/`[` 不再折向前一属性 step)、受损实参/索引走完清理建成节点后即返(不再续折后续 suffix)。语句分派:`Missing` 走旧 null 路径逐字不变;`Failed` 复用同一条丢弃路径(省泛化诊断);`Damaged` 仅在真语句边界(`isStatementEndToken() || lambdaEnded`,`isStatementEnd()` 在 lambda 内恒真不能作门控)存活为 `ExpressionStatement`,否则按丢弃路径处理。
- sealed-outcome 恢复协议:表达式和类型解析返回 `ParseOutcome<T>`。`Ok` 携带健康值,`EnclosedDamage` 携带完整结构及子损伤,`Damaged` 携带部分值,三者均保留已建节点。`Missing` 零消费且未报告,由槽位宿主补发上下文诊断;`Failed` 无值且已报告,不重复补发。表达式槽可用零宽 MISSING 或 ERROR 片段承载无值结果。Pratt 和后缀链在原有边界允许时对三种有值结果继续折叠;完整的数组、字典、调用、下标吸收子损伤而不抹去,闭合分组则透明继承内层结果。缺名点号的 `MissingAttributeStep` 仍阻止调用或下标折到前一属性。语句分派保留有值结果为 `ExpressionStatement`,由 `finishStatement` 结算剩余尾部。
- 类型恢复在内部保留容器标识与 `TypeRef`,公开类型和 serde 不变。非空坏类型保留实际消费的文本与损伤,包括缺名点号、坏闭合及消费 token 时结算的词法错误。`as`/`is` 在有可用类型时保留普通中缀节点,无类型时保留左操作数与恢复 marker;括号诊断沿用表达式宿主,也可由无宿主时建立的 `type.argument` 归属中缀节点。`for` 在类型非 `Ok` 时只在物理同行跳过垃圾,但可匹配通过显式续行直接可见的同一逻辑头 `in`。
- 诊断 code 词汇表(包私有 `DiagnosticCodes` 集中登记):`parse.missing_closer.{grouping,array,dictionary,call,subscript,annotation,preload,assert}`;`parse.missing_expression.<slot>`(由点分槽位名把 `.` 换 `_` 机械推导,与 marker `nodeType`/`RecoveryLink.facet` 共用词汇):`variable.initializer`、`constant.value`、`parameter.default`、`return.value`、`annotation.argument`、`array.element`、`dictionary.key`、`dictionary.value`、`call.argument`、`subscript.index`、`grouping`、`binary.right`、`unary.operand`、`ternary.condition`、`ternary.else`、`assignment.value`、`await.operand`、`preload.path`、`assert.condition`、`assert.message`、`match.value`、`match.guard`、`match.pattern`、`dictionary_pattern.key`、`enum.value`、`if.condition`、`elif.condition`、`while.condition`、`for.iterable`;另有 `parse.attribute.missing_name`、`parse.super.{missing_access,missing_name,missing_call}`、`parse.signature.{mandatory_after_optional,rest_with_default,parameter_after_rest}`。槽位补发之外的既有诊断(如 synchronize/endStatement 类)暂不分配 code。
- owner frame 与可达性清扫:可存活构造在槽位解析前 push owner frame、槽位解析完立即 pop 暂存(先 pop 后进 suite,防止 body 的闭合符诊断误绑头部 facet),节点建成时绑定 `RecoveryLink(owner, facet)`;参数默认值的 frame 延迟到签名最终接纳该参数时绑定(rest 参数的 variadic 重建随帧迁移到重建后节点,被丢弃的重复名参数的 frame 一并丢弃);`parse()` 返回前按对象身份遍历最终 AST 建立可达集合,owner 不可达的 link 一律清空(不回绑外层 owner)。facet 词汇(开 frame 的位点):`variable.initializer`、`constant.value`、`parameter.default`、`return.value`、`assert.condition`、`assert.message`、`assert.arguments`、`match.value`、`match.guard`、`match.pattern`、`if.condition`、`elif.condition`、`while.condition`、`for.iterable`、`enum.value`、`expression`(表达式语句)、`annotation.arguments`。
- owner frame 与可达性清扫:在槽位解析前 push owner frame,完成槽位后 pop 暂存(先 pop 后进 suite,防止 body 诊断误绑头部 facet),节点建成时绑定 `RecoveryLink(owner, facet)`。参数默认值帧延迟到签名接纳参数时绑定,rest 参数重建时迁移,被丢弃的重复参数不作为 owner。`parse()` 返回前按对象身份遍历最终 AST;无存活 owner 时,只沿显式授权链查找支持该 code 的存活 owner/facet,例如将丢弃的 lambda 默认值中的未闭分组归给函数签名。没有合法目标时保留诊断但清空链接。
- 位置决定孤立闭合符的归属:同行语句尾诊断落在原语句的 `statement.trailing`,独立行落在存活的套件或类体,真正无宿主的顶层垃圾保持独立。套件熔断诊断归属存活宿主的 `suite.body`,两者都不使用 `SourceFile` 作为兜底。
- C3 槽位 marker:match guard / enum 值 / elif 条件 / 字典 pattern key 失败不再置 null 或丢槽——guard/enum 值/elif 填槽位 marker 且宿主存活(enum `memberEnd` 扩展到 marker 末端,elif 保留分支与健康 body);字典 pattern 受损 key 有 `: sub-pattern` 载体时保留在 entry,无载体(无冒号、子 pattern 被丢、`..` 误用丢 entry 分支)时整个字典 pattern 回退为 `ErrorExpression(ERROR)` 片段(覆盖实际消费前缀 `[patternStart, extentEnd())`,健康兄弟 entry 一并损失——`DictEntry` 无法表示受损 key 的 key-only 形态,不为受损 key 伪造未开启的 value 槽位);key-only 警告只对未受损 key 发出。这些槽位的 `null` 语义收窄为「从未书写」。
- 参数顺序诊断不丢参数(有意偏离 vendor 的丢弃行为,保留身份与位置供编辑器消费):mandatory-after-optional / rest 带默认值 / rest 后参数报错后参数仍留在签名列表;rest 参数的 variadic 重建保留已解析默认值与参数 range。重复名参数仍丢弃。
- C2 存活偏差:assert/const/match 值失败后语句带 marker 存活并消费成功路径尾部(vendor 丢弃该节点,此处为有意优于 vendor 的恢复);登记同步集早停差异——存活路径把同步关键字当作槽位内容继续解析(`assert(1+, func(): pass)` 的 `func(): pass` 进消息槽),垃圾尾部比旧行为多一条 endStatement 类诊断。
Expand Down
Loading
Loading