starting json array
This commit is contained in:
parent
03ff159c95
commit
e279fe314f
13
src/lib.rs
13
src/lib.rs
@ -96,6 +96,19 @@ mod tests {
|
|||||||
.map(|(_, s, _)| JsonValue::Str(s.to_string()))
|
.map(|(_, s, _)| JsonValue::Str(s.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn whitespace() -> impl JsonParser<'static, ()> {
|
||||||
|
repeated(literal_char(' ')).to(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn json_array() -> impl JsonParser<'static, JsonValue> {
|
||||||
|
let val = whitespace().ignore_then(json_value()).then_ignore(whitespace());
|
||||||
|
|
||||||
|
literal_char('[')
|
||||||
|
.ignore_then(repeated(val))
|
||||||
|
.then_ignore(literal_char(']'))
|
||||||
|
.map(JsonValue::Array)
|
||||||
|
}
|
||||||
|
|
||||||
fn json_value() -> impl JsonParser<'static, JsonValue> {
|
fn json_value() -> impl JsonParser<'static, JsonValue> {
|
||||||
choice((json_null(), json_bool(), json_number(), json_string()))
|
choice((json_null(), json_bool(), json_number(), json_string()))
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ pub trait Parser<I, O, E> {
|
|||||||
O: 'a,
|
O: 'a,
|
||||||
O2: 'a,
|
O2: 'a,
|
||||||
E: 'a,
|
E: 'a,
|
||||||
P: Parser<I, O, E> + 'a,
|
P: Parser<I, O2, E> + 'a,
|
||||||
{
|
{
|
||||||
BoxedParser::new(crate::sequence::tuple2(self, next_parser))
|
BoxedParser::new(crate::sequence::tuple2(self, next_parser))
|
||||||
.map(|(this_output, _)| this_output)
|
.map(|(this_output, _)| this_output)
|
||||||
|
Loading…
Reference in New Issue
Block a user