A Go formatter written in Rust for learning purposes.
Note
This project does not aim for full Go language coverage. It exists for learning and experimentation, not as a production-ready tool.
An exploration of formatter design under specific constraints:
- Subject: Go's
gofmtformatting behavior - Language: Rust (ownership, lifetimes, enums)
- Scope: Subset of Go syntax sufficient to explore key design trade-offs
The goal is design exploration, not to build a complete tool.
See design/ for notes on each area.
- A production-ready Go formatter
- Faster or better than gofmt
- Complete Go language coverage
- A starting point for semantic analysis / compiler
grfmt fmt file.go # Format and print
grfmt fmt -w file.go # Format and write back
echo "..." | grfmt fmt - # From stdinsrc/
├── tokenizer.rs # Lexer with LineMap
├── token.rs # Token types
├── span.rs # Byte offset ranges
├── parser.rs # Recursive descent parser
├── ast.rs # AST nodes
├── printer.rs # gofmt-style printer
└── main.rs # CLI
Known unsupported features (documented, not planned to fix):
- Multiple type arguments:
Pair[K, V] - Type union constraints:
int | string - Comment/value alignment
- Blank line preservation
cargo build
cargo testMIT