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

Commit 2f51e07

Browse files
committed
Support more parsers for debug nodes
1 parent dec5492 commit 2f51e07

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

src/blanket.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ where
66
I: Input<'src>,
77
E: ParserExtra<'src, I>,
88
{
9+
fn node_info(&self, scope: &mut debug::NodeScope) -> debug::NodeInfo {
10+
(*self).node_info(scope)
11+
}
12+
913
fn go<M: Mode>(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult<M, O>
1014
where
1115
Self: Sized,

src/combinator.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,15 @@ where
13091309
>,
13101310
>,
13111311
{
1312+
#[doc(hidden)]
1313+
#[cfg(feature = "debug")]
1314+
fn node_info(&self, scope: &mut debug::NodeScope) -> debug::NodeInfo {
1315+
debug::NodeInfo::NestedIn(
1316+
Box::new(self.parser_a.node_info(scope)),
1317+
Box::new(self.parser_b.node_info(scope)),
1318+
)
1319+
}
1320+
13121321
#[inline(always)]
13131322
fn go<M: Mode>(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult<M, O> {
13141323
let before = inp.save();

src/debug.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub enum NodeInfo {
4444
OrNot(Box<Self>),
4545
Labelled(String, Box<Self>),
4646
Builtin(String),
47+
NestedIn(Box<Self>, Box<Self>),
4748
}
4849

4950
impl NodeInfo {
@@ -92,6 +93,11 @@ impl NodeInfo {
9293
}
9394
Self::Any => "any".to_string(),
9495
Self::Builtin(s) => s.to_string(),
96+
Self::NestedIn(a, b) => format!(
97+
"({}).nested_in({})",
98+
a.bnf_inner(depth, defs, 0),
99+
b.bnf_inner(depth, defs, 0)
100+
),
95101
Self::Padded(inner) | Self::Filter(inner) | Self::Labelled(_, inner) => {
96102
inner.bnf_inner(depth, defs, ctx)
97103
}
@@ -146,6 +152,20 @@ impl NodeInfo {
146152
NonTerminal::new(label.to_string()),
147153
)),
148154
Self::Builtin(s) => Box::new(Terminal::new(s.to_string())),
155+
Self::NestedIn(inner, outer) => Box::new(LabeledBox::new(
156+
Box::new(LabeledBox::new(
157+
outer.railroad_inner(defs),
158+
NonTerminal::new("outer".to_string()),
159+
)),
160+
Box::new(LabeledBox::new(
161+
Sequence::new(vec![
162+
Box::new(SimpleStart) as Box<dyn Node>,
163+
inner.railroad_inner(defs),
164+
Box::new(SimpleEnd),
165+
]),
166+
NonTerminal::new("inner".to_string()),
167+
)),
168+
)),
149169
Self::Any => Box::new(Terminal::new("any".to_string())),
150170
Self::OrNot(inner) => Box::new(Optional::new(inner.railroad_inner(defs))),
151171
}

src/recursive.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,25 @@ where
159159
I: Input<'src>,
160160
E: ParserExtra<'src, I>,
161161
{
162+
#[doc(hidden)]
163+
#[cfg(feature = "debug")]
164+
fn node_info(&self, scope: &mut debug::NodeScope) -> debug::NodeInfo {
165+
// Debug features don't fall under MSRV
166+
#[allow(clippy::incompatible_msrv)]
167+
let ptr = match &self.inner {
168+
RecursiveInner::Owned(x) => Rc::as_ptr(x).addr(),
169+
RecursiveInner::Unowned(x) => rc::Weak::as_ptr(x).addr(),
170+
};
171+
scope.lookup_rec(ptr, |scope| {
172+
self.parser()
173+
.inner
174+
.get()
175+
.expect("Recursive parser used before being defined")
176+
.as_ref()
177+
.node_info(scope)
178+
})
179+
}
180+
162181
#[inline]
163182
fn go<M: Mode>(&self, inp: &mut InputRef<'src, '_, I, E>) -> PResult<M, O> {
164183
recurse(move || {

0 commit comments

Comments
 (0)