This program is a simple minifier for the Zig language. It's small and simple thanks to Zig putting many parts of the compiler into the standard library. This minifier only leverages tokenization so it is unable to perform a number of more complex minifications.
- Stripping unnecessary whitespace
- Stripping of comments
- Renaming of identifiers
- Translating character literals to decimal equivalents (e.g.
'A'
to65
; 3 characters to 2)
Because no AST generation or semantic analysis is performed some optimizations are still the domain of the coder:
- Introducing shorter names for commonly used types
- Inlining functions where it would be more efficient
- Loop rewriting
- and plenty of others
This program will enable to retain your code golf solutions locally in a nice readable form and condense them at the last possible moment. Here's a recommended workflow on Linux:
- Edit code in your favorite editor, save
- Run
zig-minifier <code.zig | xsel -ib
to put the minified code in your clipboard - Paste the result into the textarea on code.golf (Ctrl+a, Ctrl+v)