2 releases
0.1.2 | Feb 11, 2024 |
---|---|
0.1.1 |
|
0.1.0 | Feb 11, 2024 |
#2628 in Parser implementations
9KB
118 lines
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
-
Clone this repository to your local machine
-
Navigate to the project directory:
-
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:
- Submit a feature request or bug report as an issue.
- Ask for improved documentation as an issue.
- Comment on issues that require feedback.
- Contribute code via pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.