Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds MoonBit “one-liner” parser/formatter APIs for Cirru expressions (to align with the Rust implementation), expands regression tests for one-liner round-tripping, and performs small warning-cleanup refactors.
Changes:
- Add
Cirru::parse_expr_one_linerand one-liner formatting APIs (format_expr_one_liner+format_one_liner). - Implement one-liner statement formatting logic in the writer.
- Add regression tests for one-liner parse/format round-trip and error cases; apply small refactors to remove warnings.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/writer.mbt | Adds one-liner expression formatter and related helper logic; minor boolean/style tweaks. |
| src/parser.mbt | Adds parse_expr_one_liner API to require exactly one expression result. |
| src/primes.mbt | Adds Cirru::format_one_liner convenience method. |
| src/parser_test.mbt | Adds regression coverage for one-liner parsing/formatting and rejection of multiple expressions. |
| src/tree.mbt | Refactors looping / slice conversion to address warnings. |
| src/s_expr.mbt | Refactors boolean/slice conversion to address warnings. |
| README.md | Documents new one-liner APIs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| ///| | ||
| fn generate_statement_one_liner(xs : Array[Cirru]) -> String { |
There was a problem hiding this comment.
generate_statement_one_liner returns an empty string when xs is empty, so Cirru::format_expr_one_liner(List([])) would format to "" instead of the valid empty expr representation "()". Add an explicit empty-case (e.g., return generate_empty_expr() / "()") and consider adding a regression test for formatting/parsing an empty expression.
| fn generate_statement_one_liner(xs : Array[Cirru]) -> String { | |
| fn generate_statement_one_liner(xs : Array[Cirru]) -> String { | |
| if xs.is_empty() { | |
| return generate_empty_expr() | |
| } |
| let at_tail = idx > 0 && idx == size - 1 | ||
| match cursor { | ||
| Leaf(s) => ret += generate_leaf(s) | ||
| List(ys) => | ||
| if at_tail { |
There was a problem hiding this comment.
Tail $ formatting here is triggered for any last List element (idx > 0 && idx == size - 1). In the main formatter (generate_tree), tail handling only applies when the previous node is a Leaf (prev_kind == Leaf). To keep one-liner formatting consistent/canonical, compute at_tail using the previous element kind (e.g., only treat the last list as tail when it is immediately preceded by a leaf).
Summary
Testing