Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Commit 4731f2f

Browse files
authored
Make nested_in more flexible (#899)
* Make nested_in more flexible * Semver break
1 parent 0ffb88e commit 4731f2f

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "chumsky"
3-
version = "0.11.1"
3+
version = "0.12.0"
44
description = "A parser library for humans with powerful error recovery"
55
authors = ["Joshua Barretto <joshua.s.barretto@gmail.com>", "Elijah Hartvigsen <elijah.reed@hartvigsen.xyz", "Jakob Wiesmore <runetynan@gmail.com>"]
66
repository = "https://github.com/zesterer/chumsky"

src/combinator.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,15 +1157,15 @@ where
11571157
}
11581158

11591159
/// See [`Parser::nested_in`].
1160-
pub struct NestedIn<A, B, J, F, O, E> {
1160+
pub struct NestedIn<A, B, J, O, E> {
11611161
pub(crate) parser_a: A,
11621162
pub(crate) parser_b: B,
11631163
#[allow(dead_code)]
1164-
pub(crate) phantom: EmptyPhantom<(J, F, O, E)>,
1164+
pub(crate) phantom: EmptyPhantom<(J, O, E)>,
11651165
}
11661166

1167-
impl<A: Copy, B: Copy, J, F, O, E> Copy for NestedIn<A, B, J, F, O, E> {}
1168-
impl<A: Clone, B: Clone, J, F, O, E> Clone for NestedIn<A, B, J, F, O, E> {
1167+
impl<A: Copy, B: Copy, J, O, E> Copy for NestedIn<A, B, J, O, E> {}
1168+
impl<A: Clone, B: Clone, J, O, E> Clone for NestedIn<A, B, J, O, E> {
11691169
fn clone(&self) -> Self {
11701170
Self {
11711171
parser_a: self.parser_a.clone(),
@@ -1175,14 +1175,32 @@ impl<A: Clone, B: Clone, J, F, O, E> Clone for NestedIn<A, B, J, F, O, E> {
11751175
}
11761176
}
11771177

1178-
impl<'src, I, J, E, F, A, B, O> Parser<'src, I, O, E> for NestedIn<A, B, J, F, O, E>
1178+
impl<'src, I, J, E, A, B, O> Parser<'src, I, O, E> for NestedIn<A, B, J, O, E>
11791179
where
11801180
I: Input<'src>,
11811181
E: ParserExtra<'src, I>,
1182+
// These bounds looks silly, but they basically just ensure that the extra type of the inner parser is compatible with the extra of the outer parser
1183+
E: ParserExtra<
1184+
'src,
1185+
J,
1186+
Error = <E as ParserExtra<'src, I>>::Error,
1187+
State = <E as ParserExtra<'src, I>>::State,
1188+
Context = <E as ParserExtra<'src, I>>::Context,
1189+
>,
1190+
<E as ParserExtra<'src, I>>::Error: Error<'src, J>,
1191+
<E as ParserExtra<'src, I>>::State: Inspector<'src, J>,
11821192
B: Parser<'src, I, J, E>,
11831193
J: Input<'src>,
1184-
F: ParserExtra<'src, J, State = E::State, Context = E::Context, Error = E::Error>,
1185-
A: Parser<'src, J, O, F>,
1194+
A: Parser<
1195+
'src,
1196+
J,
1197+
O,
1198+
extra::Full<
1199+
<E as ParserExtra<'src, I>>::Error,
1200+
<E as ParserExtra<'src, I>>::State,
1201+
<E as ParserExtra<'src, I>>::Context,
1202+
>,
1203+
>,
11861204
{
11871205
#[inline(always)]
11881206
fn go<M: Mode>(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult<M, O> {

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ pub trait Parser<'src, I: Input<'src>, O, E: ParserExtra<'src, I> = extra::Defau
10871087
///
10881088
/// assert_eq!(tl.parse(&tokens).into_result(), Ok(vec![("foo", vec!["a", "b"])]));
10891089
/// ```
1090-
fn nested_in<B: Parser<'src, J, I, F>, J, F>(self, other: B) -> NestedIn<Self, B, J, F, O, E>
1090+
fn nested_in<B: Parser<'src, J, I, F>, J, F>(self, other: B) -> NestedIn<Self, B, I, O, F>
10911091
where
10921092
Self: Sized,
10931093
I: 'src,

0 commit comments

Comments
 (0)