Skip to content

fcoury/husk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Husk - Script Language Inspired by Rust

AIPIM Icon

Build Status License: MIT

Husk is a lightweight scripting language inspired by Rust, designed for simplicity and ease of use while maintaining some of Rust's powerful features.

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

Installation

To install Husk, you need to have Rust and Cargo installed on your system. Then, you can install Husk using:

cargo install husk

Usage

REPL Mode

To start the Husk REPL, run:

husk repl

Script Execution

To execute a Husk script file, use:

husk run path/to/your/script.hk

Transpilation to JavaScript

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

Language Syntax

Here are some examples of Husk syntax:

Variable Declaration

let x = 5;
let name = "Alice";
let is_true = true;

Function Definition

fn add(x: int, y: int) -> int {
    x + y
}

Struct Definition and Instantiation

struct Person {
    name: string,
    age: int,
}

let p = Person {
    name: "Bob",
    age: 30,
};

Enum Definition and Pattern Matching

enum Option {
    Some(int),
    None,
}

let opt = Option::Some(5);

match opt {
    Option::Some(value) => println(value),
    Option::None => println("No value"),
}

Arrays and Ranges

let arr = [1, 2, 3, 4, 5];
let slice = arr[1..3];

for i in 0..5 {
    println(i);
}

Loops

// 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;
    }
}

Development

To set up the development environment:

  1. Clone the repository:

    git clone https://github.com/fcoury/husk.git
    cd husk
  2. Build the project:

    cargo build
  3. Run tests:

    cargo test

Contributing

Contributions to Husk are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

🌳 Script Language Inspired by Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published