No description
  • Rust 99.6%
  • Nix 0.4%
Find a file
2025-05-30 16:27:58 +02:00
.forgejo/workflows workflow updates 2025-05-30 16:27:58 +02:00
benches format 2024-11-05 15:50:53 +01:00
examples update miette to 3.0 2022-01-19 15:57:44 +01:00
src make 'null' matching case insensitive 2024-11-05 16:01:31 +01:00
tests fix tests 2021-09-09 15:19:31 +02:00
.envrc flake 2022-10-06 16:21:04 +02:00
.gitignore nix based ci 2024-03-11 15:45:45 +01:00
Cargo.lock update dependencies 2024-11-05 16:04:13 +01:00
Cargo.toml update repo url 2025-05-30 16:25:02 +02:00
flake.lock flake update 2025-05-30 16:24:41 +02:00
flake.nix flake update 2025-05-30 16:24:41 +02:00
README.md format 2024-11-05 15:50:53 +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(())
}