1.0 KiB
1.0 KiB
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:
decodal fmt config.dcdl
Format in place:
decodal fmt --write config.dcdl
Read from stdin:
cat config.dcdl | decodal fmt -
Rust
let formatted = decodal::format_source("Server={port=Int default 8080;};")?;
WebAssembly
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.