Knitlang is a tiny, playful programming language inspired by knitting terms and patterns. This repository (Knitlang v2) contains a minimal Rust implementation of a lexer, parser, and interpreter that demonstrates the language's core ideas and provides a REPL and file runner.
- Knitting-themed keywords:
cast_on,knit,purl,bind_off,repeat. - Integer arithmetic expressions (
+,-,*,/). - Simple variable environment.
- REPL for interactive experimentation and file-based execution.
Requirements: Rust and Cargo (1.XX+)
- Build and run the REPL:
cargo run- Run a Knitlang source file:
cargo run -- path/to/program.knit- Run the bundled example (from
examples/):
cargo run -- --example hello- Start the REPL explicitly with a flag:
cargo run -- --replSave this as examples/hello.knit and run it with cargo run -- examples/hello.knit:
cast_on stitches = 0;
repeat 3 {
knit stitches = stitches + 1;
purl stitches;
}
bind_off;
Output:
1
2
3
cast_on <name> = <expr>;— create/initialize a variable.knit <name> = <expr>;— assign/update a variable.purl <expr>;— evaluate an expression and print it (used here for demonstration).repeat <expr> { ... }— repeat a block a fixed number of times.bind_off;— stop execution early (used likebreak).
- Add more knitting primitives (
yo,ssk, pattern macros). - Support lists/rows for representing stitches and patterns.
- Add tests and CI, a standard library, and more example patterns.
Contributions are welcome! Open issues for feature requests or bugs, and send PRs for improvements. Keep changes small and add tests where possible.