Skip to content

ladroid/rusty-pkl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rusty-pkl

rusty-pkl is a Rust library for parsing Pkl configuration files. Pkl is a simple configuration language that supports hierarchical structures and various data types.

Features

  • Parse Pkl files into a structured data representation in Rust.
  • Support for basic Pkl syntax, including key-value pairs, nested objects, and common data types such as strings, integers, floats, and booleans.

Usage

  1. Clone this repository to your local machine

  2. Navigate to the project directory:

  3. Run the parser with the desired Pkl file:

    cargo run --example test.rs

Example

Suppose you have a Pkl file named example.pkl with the following content:

name = "Pkl: Configure your Systems in New Ways"
attendants = 100
isInteractive = true
amountLearned = 13.37

bird {
  name = "Common wood pigeon"
  diet = "Seeds"
  taxonomy {
    species = "Columba palumbus"
  }
}

Running the parser with this file will produce structured output representing the parsed Pkl values.

Advanced Usage

You can also access specific parameters programmatically and assign them to variables using the provided functions in the library. For example, to access the name parameter:

use pkl_rs::*;

fn main() {
    match parse_pkl("examples\\config.pkl") {
        Ok(pkl_value) => {
            println!("Parsed Pkl value: {:?}", pkl_value);
            // You can further process the parsed Pkl value as needed
            if let Some(value) = find_parameter(&pkl_value, "name") {
                println!("Found name parameter: {:?}", value);
            } else {
                println!("Parameter 'name' not found.");
            }
        }
        Err(err) => {
            eprintln!("Error parsing Pkl file: {}", err);
        }
    }
}

Contributing

Contributions are absolutely, positively welcome and encouraged! Contributions come in many forms. You could:

  1. Submit a feature request or bug report as an issue.
  2. Ask for improved documentation as an issue.
  3. Comment on issues that require feedback.
  4. Contribute code via pull requests.

License

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