Add Decodal formatter

This commit is contained in:
2026-07-09 17:39:32 +09:00
parent 16006d000a
commit 22f6bc1ab9
16 changed files with 606 additions and 24 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ The public surface is intentionally organized by use case: execute Decodal with
### Rust crate
The `decodal` crate is the primary Rust runtime and embedding API.
It owns parsing, evaluation, materialization, diagnostics, host-provided values, and schema/decode traits.
It owns parsing, formatting, evaluation, materialization, diagnostics, host-provided values, and schema/decode traits.
Rust applications should use this crate when they want to load Decodal source, evaluate it, or embed Decodal into a host program.
Important paths:
+50
View File
@@ -0,0 +1,50 @@
# Formatting
Decodal includes an initial source formatter for parsed Decodal code.
The formatter is available from the Rust crate, the CLI, the WebAssembly package, and the playground.
## CLI
Print formatted source to stdout:
```sh
decodal fmt config.dcdl
```
Format in place:
```sh
decodal fmt --write config.dcdl
```
Read from stdin:
```sh
cat config.dcdl | decodal fmt -
```
## Rust
```rust
let formatted = decodal::format_source("Server={port=Int default 8080;};")?;
```
## WebAssembly
```js
import init, { formatSource } from 'decodal-wasm';
await init();
const result = JSON.parse(formatSource('Server={port=Int default 8080;};'));
if (result.ok) {
console.log(result.source);
} else {
console.error(result.error);
}
```
## Current limitation
The formatter currently rejects source containing line comments rather than silently dropping them.
Comment-preserving formatting requires attaching comments to syntax nodes or formatting from a concrete syntax tree, and should be implemented before comment-heavy source is formatted automatically.
+5 -4
View File
@@ -7,7 +7,8 @@ Decodal は Deferred Constraint Data Language、略称 DCDL のプロジェク
1. [Introduction](./introduction.md)
2. [Components](./components.md)
3. [Language Specification](./language/index.md)
3. [Formatting](./formatting.md)
4. [Language Specification](./language/index.md)
1. [Lexical Structure and Syntax](./language/syntax.md)
2. [Value](./language/value/index.md)
1. [String](./language/value/string.md)
@@ -36,7 +37,7 @@ Decodal は Deferred Constraint Data Language、略称 DCDL のプロジェク
9. [Materialization and Errors](./language/materialization-and-errors.md)
10. [Naming Conventions](./language/naming.md)
11. [Examples](./language/examples.md)
4. [Implementation Design](./design/index.md)
5. [Implementation Design](./design/index.md)
1. [Execution Pipeline](./design/execution-pipeline.md)
2. [Runtime Model](./design/runtime-model.md)
3. [Thunk and Lazy Evaluation](./design/thunk-and-lazy-evaluation.md)
@@ -44,5 +45,5 @@ Decodal は Deferred Constraint Data Language、略称 DCDL のプロジェク
5. [Diagnostics and Fallback](./design/diagnostics-and-fallback.md)
6. [Embedding API](./design/embedding-api.md)
7. [Features](./design/features.md)
5. [Development](./development.md)
6. [Open Issues](./open-issues.md)
6. [Development](./development.md)
7. [Open Issues](./open-issues.md)