cli: add deterministic source formatter
This commit is contained in:
1 parent
d901d5227b
commit
462ddd2c5c
14 files changed
+787
-13
No files matched your search
@@ -426,11 +426,18 @@ Its diagnostics keep their AIR codes, reported at the source location.
|
||||
| `aji lower file.aji` | print the canonical AIR |
|
||||
| `aji lower --stats file.aji` | source and AIR size, expansion ratios and the two `mechanical_air_eliminated` metrics below |
|
||||
| `aji lower --annotate file.aji` | the same with `; line:col-line:col` source spans before each instruction (not canonical; for debugging) |
|
||||
| `aji fmt file.aji` | print formatted source; leave the file unchanged |
|
||||
| `aji fmt --check file.aji` | emit a JSON format record; exit 0 if formatted, 1 if formatting is needed |
|
||||
| `aji fmt --write file.aji` | atomically replace a regular file when needed; emit a JSON format record |
|
||||
|
||||
`check`, `lower`, `report`, `run` and `explore` also accept `--manifest PATH` for explicit package inputs (§14, spec 12 §1.3). Check/lower/report do not instantiate grants.
|
||||
|
||||
Lowering is deterministic: the same source inputs and compiler give byte-identical AIR, and the lowered AIR is canonical (parse → print reproduces it). The conformance runner checks both for every accepted `.aji` test.
|
||||
|
||||
**Source formatting.** `fmt` MUST parse one `.aji` file without linking, specializing, verifying or executing it. Libraries without `main`, unresolved imports and semantically rejected programs MAY be formatted. A syntax error MUST produce the existing E7001 JSON diagnostic and exit 1, with no formatted output or file modification; usage/I/O errors or an internal token-preservation failure exit 2 with a note on stderr. There is no manifest/directory discovery. `--check` and `--write` are mutually exclusive. Their record is `{ "file": PATH, "status": "formatted" | "needs_format", "changed": BOOL }`; `changed` reports whether the input differs from the formatted bytes, and `--write` reports `formatted` after a successful write. An unchanged file MUST NOT be rewritten. `--write` MUST preserve file permissions and reject non-regular files, including symbolic links. Atomic replacement changes one directory entry; other hard links retain the previous contents.
|
||||
|
||||
Formatting MUST preserve the ordered token spellings, comment contents (including trailing spaces/tabs, apart from terminal CR bytes normalized to LF) and declaration order, changing only whitespace between tokens and around comments. The result MUST parse to the same AST, ignoring source positions, and formatting it again MUST be byte-identical. Thus ownership/effects/capabilities, literal bytes, operator grouping and generated AIR remain unchanged; source diagnostic positions follow the formatted text. The reference layout uses LF, one final newline, four-space block/continuation indentation, expanded declaration/match bodies and compact struct literals. It retains at most one existing blank line between statements. Operators are spaced, type/application angles and paths are compact, and commas separate inline lists or start the next line in expanded bodies. Comments remain at their token boundary; trailing comments stay with the preceding token. Formatting MUST NOT introduce a line-width limit, reorder effects/imports or repair code.
|
||||
|
||||
**Size metrics** (`--stats`, non-normative tooling with a fixed definition):
|
||||
|
||||
- With `--manifest`, source sizes count the entry file only; AIR sizes count the combined module. These ratios MUST NOT be interpreted as whole-package compression.
|
||||
|
||||
Reference in new issue
Block a user