No description
  • Rust 99.6%
  • Nix 0.4%
Find a file
2021-08-29 21:06:52 +02:00
.github/workflows 0.2.9 2021-04-29 18:34:22 +02:00
benches also optimize single quoted strings 2020-12-08 21:36:08 +01:00
examples better array key errors 2021-08-29 21:06:52 +02:00
src better array key errors 2021-08-29 21:06:52 +02:00
tests allow trailing semicolon 2021-02-15 15:38:39 +01:00
.gitignore init repo 2020-12-01 17:44:52 +01:00
Cargo.toml switch to miette for error reporting 2021-08-29 20:30:35 +02:00
README.md finish serde support 2020-12-14 00:11:32 +01:00

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(())
}