20 releases

0.6.0 Mar 11, 2024
0.5.1 Feb 23, 2023
0.5.0 Oct 6, 2022
0.4.0 Jan 19, 2022
0.2.0 Dec 13, 2020

#1035 in Parser implementations

Download history 237/week @ 2024-01-19 224/week @ 2024-01-26 202/week @ 2024-02-02 233/week @ 2024-02-09 171/week @ 2024-02-16 99/week @ 2024-02-23 43/week @ 2024-03-01 159/week @ 2024-03-08 68/week @ 2024-03-15 34/week @ 2024-03-22 34/week @ 2024-03-29 48/week @ 2024-04-05 23/week @ 2024-04-12 14/week @ 2024-04-19 48/week @ 2024-04-26 13/week @ 2024-05-03

104 downloads per month
Used in nextcloud-config-parser

MIT/Apache

80KB
2.5K SLoC

php-literal-parser

parser for php literals.

Usage

Parse into a generic representation

use php_literal_parser::{from_str, Value, ParseError};

fn main() -> Result<(), ParseError> {
    let map = from_str::<Value>(r#"["foo" => true, "nested" => ['foo' => false]]"#)?;

    assert_eq!(map["foo"], true);
    assert_eq!(map["nested"]["foo"], false);
    
    Ok(())
}

Or parse into a specific struct using serde

use php_literal_parser::{from_str, ParseError};
use serde::Deserialize;

#[derive(Debug, Deserialize, PartialEq)]
struct Target {
    foo: bool,
    bars: Vec<u8>
}

fn main() -> Result<(), ParseError> {
    let target = from_str(r#"["foo" => true, "bars" => [1, 2, 3, 4,]]"#)?;

    assert_eq!(Target {
        foo: true,
        bars: vec![1, 2, 3, 4]
    }, target);
    Ok(())
}

lib.rs:

Parser for php literals.

Allows parsing of php string, bool, number and array literals.

Usage

Parse into a generic representation

use php_literal_parser::{from_str, Value};

let map = from_str::<Value>(r#"["foo" => true, "nested" => ['foo' => false]]"#)?;

assert_eq!(map["foo"], true);
assert_eq!(map["nested"]["foo"], false);

Or parse into a specific struct using serde

use php_literal_parser::from_str;
use serde::Deserialize;

#[derive(Debug, Deserialize, PartialEq)]
struct Target {
    foo: bool,
    bars: Vec<u8>
}

let target = from_str(r#"["foo" => true, "bars" => [1, 2, 3, 4,]]"#)?;

assert_eq!(Target {
    foo: true,
    bars: vec![1,2,3,4]
}, target);

Dependencies

~4.5–6.5MB
~90K SLoC