Skip to content

add one-liner parser APIs and clean warnings#16

Merged
tiye merged 1 commit intomainfrom
one-liner
Apr 30, 2026
Merged

add one-liner parser APIs and clean warnings#16
tiye merged 1 commit intomainfrom
one-liner

Conversation

@tiye
Copy link
Copy Markdown
Member

@tiye tiye commented Apr 30, 2026

Summary

  • add MoonBit one-liner parser and formatter APIs to match the Rust implementation
  • add regression coverage for one-liner parsing/formatting
  • clean MoonBit warnings so moon test is clean

Testing

  • moon test

Copilot AI review requested due to automatic review settings April 30, 2026 04:24
@tiye tiye merged commit 4e449ce into main Apr 30, 2026
3 checks passed
@tiye tiye deleted the one-liner branch April 30, 2026 04:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_liner and 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.

Comment thread src/writer.mbt
}

///|
fn generate_statement_one_liner(xs : Array[Cirru]) -> String {
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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()
}

Copilot uses AI. Check for mistakes.
Comment thread src/writer.mbt
Comment on lines +142 to +146
let at_tail = idx > 0 && idx == size - 1
match cursor {
Leaf(s) => ret += generate_leaf(s)
List(ys) =>
if at_tail {
Copy link

Copilot AI Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
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