starting json array

This commit is contained in:
Greg Shuflin 2022-10-20 17:55:46 -07:00
parent 03ff159c95
commit e279fe314f
2 changed files with 14 additions and 1 deletions

View File

@ -96,6 +96,19 @@ mod tests {
.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> {
choice((json_null(), json_bool(), json_number(), json_string()))
}

View File

@ -64,7 +64,7 @@ pub trait Parser<I, O, E> {
O: 'a,
O2: 'a,
E: 'a,
P: Parser<I, O, E> + 'a,
P: Parser<I, O2, E> + 'a,
{
BoxedParser::new(crate::sequence::tuple2(self, next_parser))
.map(|(this_output, _)| this_output)