mirror of
https://github.com/edg-l/lalrpop-json.git
synced 2024-10-18 06:53:44 +00:00
readme
This commit is contained in:
parent
9b5cae664b
commit
15e477a04d
15
README.md
Normal file
15
README.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# lalrpop-json
|
||||||
|
A JSON parser using lalrpop.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
|
||||||
|
use lalrpop_json::{parse_value, Value};
|
||||||
|
|
||||||
|
let value: Value = parse_value(r#"
|
||||||
|
{
|
||||||
|
"hello": "world",
|
||||||
|
"array": ["first", 2, true, false, null, { "more": 2 }]
|
||||||
|
}
|
||||||
|
"#).unwrap();
|
||||||
|
|
||||||
|
```
|
|
@ -1,6 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Span {
|
pub struct Span {
|
||||||
pub lo: usize,
|
pub lo: usize,
|
||||||
|
@ -9,9 +8,7 @@ pub struct Span {
|
||||||
|
|
||||||
impl Span {
|
impl Span {
|
||||||
pub fn new(lo: usize, hi: usize) -> Self {
|
pub fn new(lo: usize, hi: usize) -> Self {
|
||||||
Self {
|
Self { lo, hi }
|
||||||
lo, hi
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,5 +43,12 @@ mod test {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_value() {
|
fn test_value() {
|
||||||
parse_value(r#"{ "hello": "world", "a": [2, "s"] }"#).unwrap();
|
parse_value(r#"{ "hello": "world", "a": [2, "s"] }"#).unwrap();
|
||||||
|
parse_value(
|
||||||
|
r#"{
|
||||||
|
"hello": "world",
|
||||||
|
"array": ["first", 2, true, false, null, { "more": 2 }]
|
||||||
|
}"#,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue