8000 dogwood/dogwood-formatter at v1.1 · dogwood-policy/dogwood · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History

dogwood-formatter

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Dogwood formatter

dogwood-formatter pretty-prints authored Dogwood (.dw) policy source without parsing it into the semantic AST. It uses the shared dogwood-syntax grammar and lossless token stream, preserving macro definitions, strings, comments, and the exact spelling of operators and identifiers.

let formatted = dogwood_formatter::format_policies(
    "permit (principal, action, resource) when { true };",
);
assert_eq!(
    formatted,
    "permit (principal, action, resource)\nwhen { true };",
);

The default layout uses an 80-column target and two-space indentation. It changes whitespace only. If the shared syntax grammar rejects the source, a string is unterminated, or a line comment occurs inside a statement, the formatter returns the original source unchanged.

The dogwood binary exposes this as:

dogwood format policy.dw
0