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> {
|
fn json_array() -> impl JsonParser<'static, JsonValue> {
|
||||||
move |input| {
|
move |input| {
|
||||||
let val = json_value().delimited(whitespace(), whitespace());
|
let val = json_value().surrounded_by(whitespace());
|
||||||
|
|
||||||
repeated(val)
|
repeated(val)
|
||||||
.separated_by(literal(","), false)
|
.separated_by(literal(","), false)
|
||||||
@ -112,6 +112,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fn json_object() -> impl JsonParser<'static, JsonValue> {}
|
||||||
|
|
||||||
fn json_value() -> impl JsonParser<'static, JsonValue> {
|
fn json_value() -> impl JsonParser<'static, JsonValue> {
|
||||||
choice((
|
choice((
|
||||||
json_null(),
|
json_null(),
|
||||||
|
@ -92,6 +92,25 @@ where
|
|||||||
crate::sequence::seq((left, self, right)).map(|(_, output, _)| output)
|
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>
|
fn optional<'a>(self) -> BoxedParser<'a, I, Option<O>, E>
|
||||||
where
|
where
|
||||||
I: Clone + 'a,
|
I: Clone + 'a,
|
||||||
|
Loading…
Reference in New Issue
Block a user