#pkl #parser #rust

bin+lib pkl-parser

A rust Pkl Parser!

2 unstable releases

0.8.1 Aug 19, 2024
0.1.1 Aug 19, 2024

#838 in Parser implementations

Download history 209/week @ 2024-08-16 26/week @ 2024-08-23

235 downloads per month

MIT license

21KB
246 lines

pkl-parser

This crate exports a parser for Apple's Pkl language.

Features

All the Pkl syntax is supported.

Installation

When in your rust project, simply run: cargo add pkl-parser

Usage

Here's an example of how to parse a PKL string:

use pkl_parser::{parse, pratt, Rule, Error, Pairs};

fn main() -> Result<Pairs<Rule>, Error<Rule>> {
    let source = "//some pkl code";

    let pairs = parse(source)?;
    let file = result.next().unwrap().into_inner();

    for element in file {
        match element.as_rule() {
            // then take care of each stmt separately
            Rule::stmt => (),
            // then take care of each comment/annotation separately
            Rule::COMMENT => (),
            Rule::EOI => (),
            _ => unreachable!(),
        }
    }

    Ok(())
}

LICENSE

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

Dependencies

~2–2.8MB
~57K SLoC