Surrounded by combinator
This commit is contained in:
parent
92155a8f36
commit
c5f971f7ff
@ -102,7 +102,7 @@ mod tests {
|
||||
|
||||
fn json_array() -> impl JsonParser<'static, JsonValue> {
|
||||
move |input| {
|
||||
let val = json_value().delimited(whitespace(), whitespace());
|
||||
let val = json_value().surrounded_by(whitespace());
|
||||
|
||||
repeated(val)
|
||||
.separated_by(literal(","), false)
|
||||
@ -112,6 +112,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
//fn json_object() -> impl JsonParser<'static, JsonValue> {}
|
||||
|
||||
fn json_value() -> impl JsonParser<'static, JsonValue> {
|
||||
choice((
|
||||
json_null(),
|
||||
|
@ -92,6 +92,25 @@ where
|
||||
crate::sequence::seq((left, self, right)).map(|(_, output, _)| output)
|
||||
}
|
||||
|
||||
fn surrounded_by<'a, P, O1>(self, surrounding: P) -> BoxedParser<'a, I, O, E>
|
||||
where
|
||||
Self: Sized + 'a,
|
||||
I: 'a,
|
||||
O1: 'a,
|
||||
O: 'a,
|
||||
E: 'a,
|
||||
P: Parser<I, O1, E> + 'a,
|
||||
{
|
||||
BoxedParser::new(move |input| {
|
||||
let p1 = |i| surrounding.parse(i);
|
||||
let p2 = |i| surrounding.parse(i);
|
||||
let main = |i| self.parse(i);
|
||||
crate::sequence::seq((p1, main, p2))
|
||||
.map(|(_, output, _)| output)
|
||||
.parse(input)
|
||||
})
|
||||
}
|
||||
|
||||
fn optional<'a>(self) -> BoxedParser<'a, I, Option<O>, E>
|
||||
where
|
||||
I: Clone + 'a,
|
||||
|
Loading…
Reference in New Issue
Block a user