Files
Decodal/doc/manual/souce/formatting.md
T
2026-07-09 17:39:32 +09:00

51 lines
1.0 KiB
Markdown

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