Add table literal sugar for lists of records - #10796
Open
haydenflinner wants to merge 4 commits into
Open
Conversation
…os example. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Greptile SummaryThe PR adds table-literal syntax and lowers it into existing lists of records, with parser, formatter, canonicalizer, LSP, documentation, and snapshot support.
Confidence Score: 4/5The PR is not yet safe to merge because a valid complete-width table row followed by a newline and comma is still parsed as malformed. The newline branch finishes the row without consuming the comma, and table_row_next immediately starts the next cell at that same comma token, leaving the previously reported parser failure outstanding. Files Needing Attention: src/parse/Parser.zig
|
| Filename | Overview |
|---|---|
| src/parse/Parser.zig | Adds contextual table recognition and row parsing, but the previously reported complete-row newline-before-comma separator failure remains. |
| src/canonicalize/Can.zig | Desugars validated table literals into lists of records and applies optional column annotations. |
| src/fmt/fmt.zig | Formats table headers and rows while integrating table expressions into multiline layout decisions. |
| src/parse/AST.zig | Adds table AST nodes, diagnostics, and S-expression serialization. |
| src/parse/NodeStore.zig | Adds storage, scratch spans, and retrieval APIs for table columns and rows. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Source[Table literal source] --> Parser[Parser row and column handling]
Parser --> AST[Table AST]
AST --> Canonicalizer[Canonicalization]
Canonicalizer --> Records[List of records]
AST --> Formatter[Formatter]
AST --> LSP[LSP selection ranges]
Reviews (3): Last reviewed commit: "Treat table as a table literal only when..." | Re-trigger Greptile
…comma. Co-authored-by: Cursor <cursoragent@cursor.com>
…same line. A value named table followed by another lowercase name on the next line was parsed as a table, which broke host platforms that re-export table. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Sorry about the original contents of this post, Cursor jumped a little ahead -- I ran out of Claude Code earlier today and have been trying the new old tool again :-) The below is human edited.
I had Claude add a table syntax to Roc's syntax, because I like tables, and I wondered if it was possible without knowing Roc to modify it.
Why tables matter
I think tables are critical to the future of computing. Some references:
or in text form:
The homepage todos example (couldn't find the source) is the kind of thing that currently repeats every field name on every row. A table literal makes that more convenient, IMO:
Suggested syntax (taken from Pyret)
Homepage writes:
The suggested change in idiom is:
The most obvious difference compared to Pyret's choice is the lack of
row. Pyret'srow:would enable a single logical row span multiple source lines, I guess. Without it, my intuition is that each table row can only be one row in the source text.Claude says that in the impl vibecoded, newlines at table-body depth end the row; newlines inside
(),[],{}, or a lambda do not.I don't have an opinion on that tradeoff, it's just what fell out.
tableis a contextual keyword (table(x)stays valid, i.e. table is not reserved). Columns may take types (table name : Str, age : U8 { ... }) so numerals pick up the column type instead of defaulting toDec.Implementation
This PR is an allegedly working implementation of the suggested syntax that Claude wrote. I have not personally used it yet, I wanted to discuss the idea more before sinking in more time. I had claude write an impl mostly to see if it was possible.
It claims that this is tested: