Skip to content

Implement CST Group support for Gale parser generator#731

Merged
gfx merged 8 commits intomainfrom
claude/fix-cst-group-afN1p
Mar 29, 2026
Merged

Implement CST Group support for Gale parser generator#731
gfx merged 8 commits intomainfrom
claude/fix-cst-group-afN1p

Conversation

@gfx
Copy link
Copy Markdown
Member

@gfx gfx commented Mar 29, 2026

Summary

  • Implement CST Group support: (rule_a | rule_b)* patterns now store results as variant-typed arrays in the parse tree
  • Standalone Groups generate Option<GroupVariant> fields (None when no alternative matches)
  • Rewrite SQLite parser tests as XML unparse assertions with strip_indent for readable multi-line expected values

What changed

CST Group for Repeat(Group)(sql_stmt_list | error)* in the parse rule now generates:

  • SqlStmtListOrErrorGroup variant type with cases per alternative
  • sql_stmt_list_or_error_list: Array<SqlStmtListOrErrorGroup> field on ParseNode
  • Walker dispatches via for let item of &node.field_list { match item { ... } }

CST Group for standalone Group(alter_table_stmt | ... | vacuum_stmt) in sql_stmt generates:

  • Option<GroupVariant> field (None-safe when called at EOF after trailing semicolons)
  • Overlap groups use backtracking with Option wrapping

Test rewrite — All SQLite driver tests converted from parse-success checks to assert_xml with expected XML output.

Known limitations (documented in TODO.md)

  • store parameter on gen_element is a naming collision workaround that should be removed (requires dedup_name architecture change)
  • Token-only groups, repeated separators, and multi-element single-alt groups don't generate CST fields yet

Test plan

  • wado test package-gale/src/generator_test.wado — 9 passed
  • wado test package-gale/tests/driver_sqlite_test.wado — 8 passed
  • wado test package-gale/src — 97 passed
  • mise run on-task-done — running

https://claude.ai/code/session_01UScFhoVqHgkzcmAkqa24nZ

claude added 8 commits March 29, 2026 16:02
Store `(rule_a | rule_b)*` results in the parse tree as variant-typed
arrays. Groups inside Repeat elements now generate:
- Variant types (e.g., SqlStmtListOrErrorGroup)
- Array/Option fields on CST structs
- Parser code that wraps results in variant constructors
- Walker code that dispatches via match on group variants

Standalone groups (not inside Repeat) continue to use the existing
non-store parsing behavior to avoid breaking pre-existing parser
generation patterns.

https://claude.ai/code/session_01UScFhoVqHgkzcmAkqa24nZ
Convert all parse-only tests to use assert_roundtrip which verifies the
full parse → to_tree → unparse_xml pipeline. Remove direct CstNode
field inspection tests in favor of XML-based assertions.

Also delete package-gale/TODO.md (CST Group fix is now implemented).

https://claude.ai/code/session_01UScFhoVqHgkzcmAkqa24nZ
Add strip_indent helper that removes leading whitespace per line,
allowing expected XML to be written with indentation in test source.
Convert representative tests (simple SELECT, multiple statements,
whitespace trivia, trailing trivia, comment trivia) to assert_parse_xml
with explicit expected XML. Remaining tests use assert_roundtrip.

https://claude.ai/code/session_01UScFhoVqHgkzcmAkqa24nZ
Standalone Groups (not inside Repeat) now generate Option-wrapped
CST fields. When no alternative matches (e.g., sql_stmt called at, the field is None instead of causing
a panic or error. This avoids backtracking in Star/Plus loops.

- generator: standalone Group → Option<GroupVariant> field
- parser: gen_consume_group_store_optional wraps result in Option
- visitor: standalone Group uses OptionalWrap for walker dispatch
- tests: rewrite SQLite tests to assert_parse_xml with expected XML

https://claude.ai/code/session_01UScFhoVqHgkzcmAkqa24nZ
EOF
)
Document the dedup_name architectural issue that prevents
removing the store=false workaround from parser code generation.

https://claude.ai/code/session_01UScFhoVqHgkzcmAkqa24nZ
Replace all parse-only and CST structure tests with assert_xml tests
that compare parse → to_tree → unparse_xml output against expected XML.
Each test uses multi-line string literals with strip_indent for readable
expected values.

8 representative tests covering SELECT, CREATE TABLE, INSERT, DELETE,
UPDATE, DROP TABLE, and BEGIN statements.

https://claude.ai/code/session_01UScFhoVqHgkzcmAkqa24nZ
Add section describing missing tokens/nodes in XML unparse output:
repeated separators, token-only groups, and multi-element groups.

https://claude.ai/code/session_01UScFhoVqHgkzcmAkqa24nZ
@gfx gfx merged commit c49e461 into main Mar 29, 2026
10 checks passed
@gfx gfx deleted the claude/fix-cst-group-afN1p branch March 29, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants