Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/devyatsu/pkl_fast
A rust library aiming to easily and efficiently work with Apple's PKL format.
https://github.com/devyatsu/pkl_fast
apple crate lexer library parser pkl rust tokenizer
Last synced: about 11 hours ago
JSON representation
A rust library aiming to easily and efficiently work with Apple's PKL format.
- Host: GitHub
- URL: https://github.com/devyatsu/pkl_fast
- Owner: DevYatsu
- License: mit
- Created: 2024-02-11T00:31:10.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-08-20T19:36:16.000Z (3 months ago)
- Last Synced: 2024-10-31T11:45:17.379Z (15 days ago)
- Topics: apple, crate, lexer, library, parser, pkl, rust, tokenizer
- Language: Rust
- Homepage:
- Size: 205 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pkl_fast
Fastest pkl-parsing crate out there (and surely the only one)!
I am currently working on a big rework, as the current lexer (logos) does not cover all the features I need, I am replacing it with the pest crate, all the work on the pkl parser was moved to another crate of my own [pkl-parser](https://crates.io/crates/pkl-parser) which can be considered finished! Just need to adapt interpreting the pkl ast node to this new parser, sry for the delay!
## Features
- Parse Pkl string into a structured representation (hashmap) in rust
- Parse Pkl string into an AST
- Support for strings, integers (decimal, octal, hex, binary), floats, boolean, objects (amends syntax as well), class instances
- Boolean API supported
- String API (mostly) supported
- Int/Float/Duration/DataSize properties and methods supported## Currently Not Supported
- Multiline String containing <<">> not preceded by a backlash, String interpolation and Strings with custom delimiters
- Lists methods API, only properties are supported
- Listings, Mappings, Maps
- functions -> thus also functions and methods taking functions as parameters
- Packages (official or not) imports not supported
- Globbed imports + dynamic imports + amends expresions
- type annotations
- Classes declarations
- If expressions## Installation
When in your rust project, simply run: `cargo add new-pkl` (for the moment use new-pkl crate, new stable release coming to pkl_fast really soon)
## Usage
Here's an example of how to parse a PKL string and retrieve values from the context:
```rust
use new_pkl::{Pkl, PklResult, PklValue};fn main() -> PklResult<()> {
let source = r#"
bool_var = true
int_var = 42
float_var = 3.14
$string_var = "hello"
object_var {
key1 = "value1"
key2 = 2
}
"#;let mut pkl = Pkl::new();
pkl.parse(source)?;println!("{:?}", pkl.get("int_var")); // Ok(PklValue::Int(42))
// Get values
println!("{:?}", pkl.get_bool("bool_var")); // Ok(true)
println!("{:?}", pkl.get_int("int_var")); // Ok(42)
println!("{:?}", pkl.get_float("float_var")); // Ok(3.14)
println!("{:?}", pkl.get_string("$string_var")); // Ok("hello")
println!("{:?}", pkl.get_object("object_var")); // Ok(HashMap with key1 and key2)// Modify values
pkl.set("int_var", PklValue::Int(100));// Remove values
pkl.remove("float_var");
println!("{:?}", pkl.get_float("float_var")); // Err("Variable `float_var` not found")// Or just generate an ast
let mut pkl = Pkl::new();
// the ast contains the start and end indexes of each value and statement
let ast = pkl.generate_ast(source)?;Ok(())
}
```### LICENSE
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.