Husk is a lightweight scripting language inspired by Rust, designed for simplicity and ease of use while maintaining some of Rust's powerful features.
- Rust-inspired syntax
- Static typing
- Support for basic data types: integers, floats, booleans, and strings
- Struct definitions and instantiation
- Function definitions and calls
- Control flow with if-else statements and match expressions
- Enums with associated values
- Arrays and ranges
- Loop constructs: for, while, and loop
- Basic arithmetic and comparison operations
- Interactive REPL (Read-Eval-Print Loop)
- Script execution from files
- Transpilation to JavaScript
To install Husk, you need to have Rust and Cargo installed on your system. Then, you can install Husk using:
cargo install husk
To start the Husk REPL, run:
husk repl
To execute a Husk script file, use:
husk run path/to/your/script.hk
To transpile a Husk script to JavaScript, use:
husk compile path/to/your/script.hk
This will output the transpiled JavaScript code to stdout. If you have node installed you can do:
husk compile path/to/your/script.hk | node
Here are some examples of Husk syntax:
let x = 5;
let name = "Alice";
let is_true = true;
fn add(x: int, y: int) -> int {
x + y
}
struct Person {
name: string,
age: int,
}
let p = Person {
name: "Bob",
age: 30,
};
enum Option {
Some(int),
None,
}
let opt = Option::Some(5);
match opt {
Option::Some(value) => println(value),
Option::None => println("No value"),
}
let arr = [1, 2, 3, 4, 5];
let slice = arr[1..3];
for i in 0..5 {
println(i);
}
// For loop
for x in [1, 2, 3, 4, 5] {
println(x);
}
// While loop
let mut i = 0;
while i < 5 {
println(i);
i += 1;
}
// Infinite loop with break
loop {
println("Hello");
if some_condition {
break;
}
}
To set up the development environment:
-
Clone the repository:
git clone https://github.com/fcoury/husk.git cd husk
-
Build the project:
cargo build
-
Run tests:
cargo test
Contributions to Husk are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.