Skip to content

Parser: pretty-printer + parse→print→parse round-trip validation #67

Description

@StreamDemon

Summary

Add a pretty-printer that renders the AST back to Sploosh source, plus a round-trip corpus test (parse → print → parse, asserting AST equality). This validates §16 against the spec's own examples — the v0.5.11 audit found §16 had never been checked against real source, and a round-tripping parser+printer is the mechanism that forces that check.

Part of the Frontend milestone (see the Compiler Roadmap, #66). Was the v0.6.0 stretch goal in the bootstrap scoping.

Spec

  • §16 EBNF grammar (the printer must emit grammar-conforming source); §2 lexical structure (tokens, comments).

Scope

  • AST → source pretty-printer covering every node the parser produces.
  • Round-trip test over tests/corpus/*.sp: parse → print → re-parse, assert the two ASTs are equal (modulo spans).
  • Decide span handling: compare with spans normalized, or make the round-trip assertion span-insensitive.
  • Wire into the corpus harness or a new tests/roundtrip.rs.

Notes

Most valuable once the parser covers more of §16 (the control-flow issues #59#62), but the printer can grow incrementally alongside the AST. Catches grammar drift the moment a spec example fails to round-trip.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions