From e279fe314f6e2628086793c7a9498e0275e2638d Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Thu, 20 Oct 2022 17:55:46 -0700 Subject: [PATCH] starting json array --- src/lib.rs | 13 +++++++++++++ src/parser.rs | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2a64e4a..277e323 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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())) } diff --git a/src/parser.rs b/src/parser.rs index e069cc4..cf42593 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -64,7 +64,7 @@ pub trait Parser { O: 'a, O2: 'a, E: 'a, - P: Parser + 'a, + P: Parser + 'a, { BoxedParser::new(crate::sequence::tuple2(self, next_parser)) .map(|(this_output, _)| this_output)