Repository navigation
fix(lowering): handle line_continuation nodes in CstToAstMapper - #1
Merged
Merged
Conversation
The bundled tree-sitter grammar emits `\` line continuations as named extra nodes, which previously leaked into lowering: - operatorBetween/prefixOperator recovered operator text containing the continuation (e.g. `+ \`, `is \`), corrupting binary, comparison, assignment, augmented assignment and is/as/is not expressions - line_continuation surfaced as a named child of arguments, arrays and other constructs, producing bogus UnknownExpression nodes and "Unsupported expression node" warnings for call arguments and array elements split across lines Skip line_continuation nodes in every child enumeration during lowering via a shared significantNamedChildren helper, and strip continuation sequences (plus whitespace collapsing for `is not`) when recovering operator source text. Add CstToAstMapperLineContinuationTest covering binary/comparison/ assignment/augmented assignment continuations, is/as continuations, and call argument/array element continuations.
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No blocking issues remain; the outstanding nit is non-blocking.
Review effort: Lite
Findings: None
What changed in this PR
Fixes CST-to-AST lowering for GDScript line continuations.
Changes:
- Filters
line_continuationnodes during AST lowering. - Normalizes operators across continued lines.
- Adds regression tests for operators, calls, and arrays.
| File | Summary |
|---|---|
src/test/java/dev/superice/gdparser/frontend/lowering/CstToAstMapperLineContinuationTest.java |
Adds six regression tests for continued-line syntax. |
src/main/java/dev/superice/gdparser/frontend/lowering/CstToAstMapper.java |
Filters continuation nodes and normalizes operator text; one non-blocking nit requests unary-operator coverage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
问题
遇到以
\折行的源码时,CstToAstMapper会生成错误的 AST 结构。上游 tree-sitter 语法(PrestonKnopp/tree-sitter-gdscript)将行尾\折行建模为命名 extra 节点line_continuation(grammar.js中line_continuation: ($) => token(seq("\\", /\r?\n/)),且node-types.json中named: true),它会出现在任何跨行构造的 named children 中,而 mapper 此前对它完全不感知,导致两类故障:operatorBetween/prefixOperator从源码字节区间直接提取操作符,折行时被提取为+ \、> \、= \、is \等脏文本。其中is/as/is not因无法匹配 switch 分支而静默降级为BinaryExpression(本应是TypeTestExpression/CastExpression),其余二元/比较/赋值/复合赋值表达式则带上错误操作符。line_continuation作为命名子节点混入arguments、array等构造的子节点枚举,被当作表达式映射,产生UnknownExpression节点并伴随Unsupported expression node: line_continuation警告,调用参数列表 / 数组元素数量与内容均出错。修复
significantNamedChildren(node)辅助方法,统一在 lowering 的所有子节点枚举点(语句序列、注解、枚举体、if/match 子句、块体、attribute 链、数组、字典、参数列表、实参列表、firstNamedChild系列、findNamedChildByType等)跳过line_continuation节点;CST 层保持对语法树的忠实呈现,不做改动。normalizeOperatorText,在恢复操作符源码文本时先剥离\<换行>续行序列,再折叠空白(保证is not这类多词操作符仍可比较)。测试
新增
CstToAstMapperLineContinuationTest(6 个用例,全部先复现失败、修复后通过):1 + \)a > \)=、+=,含var value = \推导形式)is/is not/as折行(断言映射为TypeTestExpression/CastExpression)本地完整测试套件:116 个测试全部通过(含既有 110 个回归测试)。