Skip to content

Define the canonical formatter contract - #3

Merged
konojunya merged 1 commit into
mainfrom
jj/canonical-formatter-contract
Sep 3, 2026
Merged

Define the canonical formatter contract#3
konojunya merged 1 commit into
mainfrom
jj/canonical-formatter-contract

Conversation

@konojunya

Copy link
Copy Markdown
Contributor

Background

Task 5 requires one implementation-independent canonical representation for .stack source before the lossless compiler model and formatter are implemented. The previous language text left ordering, comments, escapes, and byte-level output partly advisory.

Implementation

  • add a normative formatter specification covering indentation, braces, blank lines, authored declaration/property order, lists, string escapes, comments, UTF-8/LF output, and the final newline
  • add a CRLF formatter input plus canonical expected source and normalized IR covering leading, trailing, between-declaration, and nested comments
  • define exact-byte, idempotence, and semantic-preservation checks for formatter runners
  • validate formatter fixture layout, expected UTF-8/LF bytes, the final newline, and normalized IR in CI

Testing

  • python3 scripts/validate-compiler-diagnostics.py
  • python3 scripts/validate-formatter-fixtures.py
  • check-jsonschema --check-metaschema schemas/*.json
  • check-jsonschema --schemafile schemas/normalized-ir.schema.json conformance/valid/*/expected.ir.json conformance/formatter/*/expected.ir.json
  • diagnostic expectation schema validation
  • existing stack-compiler conformance runner against temporary valid cases for both formatter input and expected source
  • git diff --check

Review focus / concerns

  • declaration, property, layout-statement, and list order is intentionally preserved rather than sorted so normalized IR order and comment token gaps remain stable
  • canonical strings emit direct UTF-8 scalars except escaped quotes and backslashes; \uXXXX spellings are normalized away
  • the CRLF input is marked binary only to preserve its fixture bytes through Git; expected canonical output remains reviewable UTF-8/LF text
  • compiler-error input is explicitly outside successful formatting, while warnings remain formattable

@konojunya
konojunya merged commit e40ad5d into main Sep 3, 2026
1 check passed
@konojunya
konojunya deleted the jj/canonical-formatter-contract branch September 3, 2026 04:30
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.

1 participant