22 releases

0.6.2 Nov 5, 2024
0.6.1 Jul 20, 2024
0.6.0 Mar 11, 2024
0.5.1 Feb 23, 2023
0.2.0 Dec 13, 2020

#1165 in Parser implementations

Download history 10/week @ 2024-08-23 23/week @ 2024-08-30 17/week @ 2024-09-06 22/week @ 2024-09-13 48/week @ 2024-09-20 50/week @ 2024-09-27 21/week @ 2024-10-04 10/week @ 2024-10-11 4/week @ 2024-10-18 2/week @ 2024-10-25 159/week @ 2024-11-01 95/week @ 2024-11-08 18/week @ 2024-11-15 9/week @ 2024-11-22 10/week @ 2024-11-29 23/week @ 2024-12-06

62 downloads per month
Used in nextcloud-config-parser

MIT/Apache

81KB
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

~5.5–7.5MB
~105K SLoC