Skip to content

takaebato/grfmt-experimental

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grfmt

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.

What This Is

An exploration of formatter design under specific constraints:

  • Subject: Go's gofmt formatting 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.

What This Is Not

  • A production-ready Go formatter
  • Faster or better than gofmt
  • Complete Go language coverage
  • A starting point for semantic analysis / compiler

Usage

grfmt fmt file.go       # Format and print
grfmt fmt -w file.go    # Format and write back
echo "..." | grfmt fmt - # From stdin

Architecture

src/
├── 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

Limitations

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

Building

cargo build
cargo test

License

MIT

About

An experimental Go formatter implementation in Rust, focused on learning formatter internals and design exploration, not production use.

Resources

License

Stars

Watchers

Forks

Contributors

Languages