21 个版本

0.6.1 2024年7月20日
0.6.0 2024年3月11日
0.5.1 2023年2月23日
0.5.0 2022年10月6日
0.2.0 2020年12月13日

#1040解析器实现

Download history 11/week @ 2024-04-20 54/week @ 2024-04-27 6/week @ 2024-05-04 12/week @ 2024-05-11 30/week @ 2024-05-18 57/week @ 2024-05-25 35/week @ 2024-06-01 15/week @ 2024-06-08 11/week @ 2024-06-15 6/week @ 2024-06-22 14/week @ 2024-06-29 24/week @ 2024-07-06 8/week @ 2024-07-13 141/week @ 2024-07-20 81/week @ 2024-07-27 20/week @ 2024-08-03

每月250 次下载
用于 nextcloud-config-parser

MIT/Apache 许可协议

80KB
2.5K SLoC

php-literal-parser

php 字面量解析器。

用法

解析为通用表示

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

或使用 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:

php 字面量解析器。

允许解析 php 字符串、布尔值、数字和数组字面量。

用法

解析为通用表示

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);

或使用 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);

依赖项

~5–6.5MB
~87K SLoC