ebnf repeated

This commit is contained in:
Greg Shuflin 2024-01-31 15:43:43 -08:00
parent 9c2228dbff
commit a189f34c37
2 changed files with 13 additions and 1 deletions

View File

@ -1,6 +1,6 @@
use std::marker::PhantomData;
use crate::{ParseResult, Parser};
use crate::{ParseResult, Parser, representation::Representation};
pub fn repeated<P, I, O, E>(parser: P) -> Repeated<P, I, O, E>
where
@ -94,6 +94,16 @@ where
}
Ok((results, input))
}
fn name(&self) -> Option<String> {
self.inner_parser.name()
}
fn representation(&self) -> Representation {
let at_least = self.at_least.unwrap_or(0);
let at_most = self.at_most.unwrap_or(u32::MAX);
Representation::new()
}
}
pub struct SeparatedBy<D, P, I, O, E>

View File

@ -38,6 +38,7 @@ pub enum EBNF {
StringTerminal(String),
LabeledTerminal(String),
Alternation(Vec<EBNF>),
Repeated(Box<EBNF>),
}
impl fmt::Display for EBNF {
@ -57,6 +58,7 @@ impl fmt::Display for EBNF {
EBNF::Nonterminal(name) => write!(f, "{name}"),
EBNF::StringTerminal(term) => write!(f, r#""{term}""#),
EBNF::LabeledTerminal(s) => write!(f, "<{s}>"),
EBNF::Repeated(inner) => write!(f, "[ {inner} ]")
}
}
}