Representation always exists

This commit is contained in:
Greg Shuflin 2024-01-31 02:23:49 -08:00
parent 0829b16fc9
commit 4818b23c3b
3 changed files with 7 additions and 10 deletions

View File

@ -8,7 +8,7 @@ where
{
inner: P,
name: Option<String>,
repr: Option<Representation>,
repr: Representation,
phantom: PhantomData<(I, O, E)>,
}
@ -24,7 +24,7 @@ where
self.name.clone()
}
fn representation(&self) -> Option<Representation> {
fn representation(&self) -> Representation {
self.repr.clone()
}
}
@ -37,7 +37,7 @@ where
Self {
inner,
name: None,
repr: None,
repr: Representation::new(),
phantom: PhantomData,
}
}
@ -50,9 +50,6 @@ where
}
pub fn with_repr(self, repr: Representation) -> Self {
Self {
repr: Some(repr),
..self
}
Self { repr, ..self }
}
}

View File

@ -7,8 +7,8 @@ pub trait Parser<I, O, E> {
fn name(&self) -> Option<String> {
None
}
fn representation(&self) -> Option<Representation> {
None
fn representation(&self) -> Representation {
Representation::new()
}
}

View File

@ -72,7 +72,7 @@ mod tests {
let parser = literal_char('f');
assert_eq!(Ok(('f', "unky")), parser.parse("funky"));
let repr = parser.representation().unwrap();
let repr = parser.representation();
assert!(matches!(repr.production(), EBNF::CharTerminal('f')));
}
}