From 4f807b991b0715414d9b97ca284367b2555ab2e7 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 23 Oct 2022 00:25:20 -0700 Subject: [PATCH] Remove current iteration of bnf code --- src/bnf.rs | 6 ---- src/choice/mod.rs | 71 ++------------------------------------ src/lib.rs | 11 ------ src/parser/boxed_parser.rs | 5 --- src/parser/mod.rs | 21 ----------- src/parser/named_parser.rs | 1 - src/sequence/mod.rs | 2 +- 7 files changed, 3 insertions(+), 114 deletions(-) delete mode 100644 src/bnf.rs diff --git a/src/bnf.rs b/src/bnf.rs deleted file mode 100644 index 4de5862..0000000 --- a/src/bnf.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[derive(Debug, Clone, PartialEq)] -pub enum Bnf { - Production, - Choice(Vec), - Unknown, -} diff --git a/src/choice/mod.rs b/src/choice/mod.rs index 8f0e7d5..877c625 100644 --- a/src/choice/mod.rs +++ b/src/choice/mod.rs @@ -1,4 +1,3 @@ -use crate::bnf::Bnf; use crate::parser::{ParseResult, Parser, ParserInput}; pub fn choice2(parser1: P1, parser2: P2) -> impl Parser @@ -10,19 +9,16 @@ where choice((parser1, parser2)) } -pub fn choice(choices: C) -> (impl Parser, Bnf) +pub fn choice(choices: C) -> impl Parser where C: Choice, I: ParserInput + Clone, { - let bnf = choices.bnf(); - (move |input| choices.parse(input), bnf) + move |input| choices.parse(input) } pub trait Choice { fn parse(&self, input: I) -> ParseResult; - - fn bnf(&self) -> Bnf; } impl Choice for (P1, P2) @@ -35,16 +31,6 @@ where let parsers = vec![&self.0 as &dyn Parser, &self.1]; choice_loop(input, parsers) } - - fn bnf(&self) -> Bnf { - let parsers = vec![&self.0 as &dyn Parser, &self.1]; - Bnf::Choice( - parsers - .into_iter() - .map(|p| p.bnf().unwrap_or(Bnf::Unknown)) - .collect(), - ) - } } impl Choice for (P1, P2, P3) @@ -58,16 +44,6 @@ where let parsers = vec![&self.0 as &dyn Parser, &self.1, &self.2]; choice_loop(input, parsers) } - - fn bnf(&self) -> Bnf { - let parsers = vec![&self.0 as &dyn Parser, &self.1, &self.2]; - Bnf::Choice( - parsers - .into_iter() - .map(|p| p.bnf().unwrap_or(Bnf::Unknown)) - .collect(), - ) - } } impl Choice for (P1, P2, P3, P4) @@ -82,16 +58,6 @@ where let parsers = vec![&self.0 as &dyn Parser, &self.1, &self.2, &self.3]; choice_loop(input, parsers) } - - fn bnf(&self) -> Bnf { - let parsers = vec![&self.0 as &dyn Parser, &self.1, &self.2, &self.3]; - Bnf::Choice( - parsers - .into_iter() - .map(|p| p.bnf().unwrap_or(Bnf::Unknown)) - .collect(), - ) - } } impl Choice for (P1, P2, P3, P4, P5) @@ -113,22 +79,6 @@ where ]; choice_loop(input, parsers) } - - fn bnf(&self) -> Bnf { - let parsers = vec![ - &self.0 as &dyn Parser, - &self.1, - &self.2, - &self.3, - &self.4, - ]; - Bnf::Choice( - parsers - .into_iter() - .map(|p| p.bnf().unwrap_or(Bnf::Unknown)) - .collect(), - ) - } } impl Choice for (P1, P2, P3, P4, P5, P6) @@ -152,23 +102,6 @@ where ]; choice_loop(input, parsers) } - - fn bnf(&self) -> Bnf { - let parsers = vec![ - &self.0 as &dyn Parser, - &self.1, - &self.2, - &self.3, - &self.4, - &self.5, - ]; - Bnf::Choice( - parsers - .into_iter() - .map(|p| p.bnf().unwrap_or(Bnf::Unknown)) - .collect(), - ) - } } fn choice_loop(input: I, parsers: Vec<&dyn Parser>) -> ParseResult diff --git a/src/lib.rs b/src/lib.rs index d1e33c1..fd311e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,3 @@ -mod bnf; pub mod choice; pub mod combinators; mod parser; @@ -6,7 +5,6 @@ pub mod primitives; pub mod sequence; #[cfg(test)] -use bnf::Bnf; pub use parser::{ParseResult, Parser, ParserInput}; #[cfg(test)] @@ -223,13 +221,4 @@ mod tests { let parsed_json = json_object().parse(test_json); assert!(parsed_json.is_ok()); } - - #[test] - fn bnf_representation() { - let bnf = json_value().bnf().unwrap(); - assert_eq!(bnf, Bnf::Production); - - let bnf = json_object().bnf().unwrap(); - assert_eq!(bnf, Bnf::Production); - } } diff --git a/src/parser/boxed_parser.rs b/src/parser/boxed_parser.rs index d759a8b..e59da3f 100644 --- a/src/parser/boxed_parser.rs +++ b/src/parser/boxed_parser.rs @@ -1,4 +1,3 @@ -use crate::bnf::Bnf; use crate::parser::{ParseResult, Parser, ParserInput}; pub struct BoxedParser<'a, I, O, E> @@ -27,10 +26,6 @@ impl<'a, I: ParserInput, O, E> Parser for BoxedParser<'a, I, O, E> { self.inner.parse(input) } - fn bnf(&self) -> Option { - self.inner.bnf() - } - fn boxed<'b>(self) -> BoxedParser<'b, I, O, E> where Self: Sized + 'b, diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 13397ca..00eb190 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,7 +1,6 @@ mod boxed_parser; mod named_parser; -use crate::bnf::Bnf; use std::rc::Rc; pub use boxed_parser::BoxedParser; @@ -19,9 +18,6 @@ where I: ParserInput, { fn parse(&self, input: I) -> ParseResult; - fn bnf(&self) -> Option { - None - } fn boxed<'a>(self) -> BoxedParser<'a, I, O, E> where @@ -150,19 +146,6 @@ where } } -impl Parser for (P, Bnf) -where - P: Parser, -{ - fn parse(&self, input: I) -> ParseResult { - self.0.parse(input) - } - - fn bnf(&self) -> Option { - Some(self.1.clone()) - } -} - impl Parser for Rc where I: ParserInput, @@ -171,8 +154,4 @@ where fn parse(&self, input: I) -> ParseResult { self.as_ref().parse(input) } - - fn bnf(&self) -> Option { - self.as_ref().bnf() - } } diff --git a/src/parser/named_parser.rs b/src/parser/named_parser.rs index a85be49..2c630b5 100644 --- a/src/parser/named_parser.rs +++ b/src/parser/named_parser.rs @@ -1,5 +1,4 @@ use crate::parser::{ParseResult, Parser, ParserInput}; -//use crate::bnf::Bnf; use super::boxed_parser::BoxedParser; pub struct NamedParser<'a, I, O, E> diff --git a/src/sequence/mod.rs b/src/sequence/mod.rs index 2c8c3de..08bebad 100644 --- a/src/sequence/mod.rs +++ b/src/sequence/mod.rs @@ -1,4 +1,4 @@ -use crate::{ParseResult, Parser, ParserInput}; +use crate::parser::{ParseResult, Parser, ParserInput}; pub fn tuple2(parser1: P1, parser2: P2) -> impl Parser where