From a189f34c3718407576e0bcc2cb77f0bc0f887108 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Wed, 31 Jan 2024 15:43:43 -0800 Subject: [PATCH] ebnf repeated --- src/combinators.rs | 12 +++++++++++- src/representation.rs | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/combinators.rs b/src/combinators.rs index 5206f0d..7ef4abd 100644 --- a/src/combinators.rs +++ b/src/combinators.rs @@ -1,6 +1,6 @@ use std::marker::PhantomData; -use crate::{ParseResult, Parser}; +use crate::{ParseResult, Parser, representation::Representation}; pub fn repeated(parser: P) -> Repeated where @@ -94,6 +94,16 @@ where } Ok((results, input)) } + + fn name(&self) -> Option { + 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 diff --git a/src/representation.rs b/src/representation.rs index 89c77dd..3c88523 100644 --- a/src/representation.rs +++ b/src/representation.rs @@ -38,6 +38,7 @@ pub enum EBNF { StringTerminal(String), LabeledTerminal(String), Alternation(Vec), + Repeated(Box), } 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} ]") } } }