From 73845224d573ac8f60680a4ce03ff75679485453 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Fri, 21 Oct 2022 21:56:08 -0700 Subject: [PATCH] Start working on bnf() --- src/bnf.rs | 5 ++++- src/parser.rs | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/bnf.rs b/src/bnf.rs index bb36eca..20f9dc6 100644 --- a/src/bnf.rs +++ b/src/bnf.rs @@ -1 +1,4 @@ -pub struct Bnf {} +#[derive(Debug, Clone)] +pub enum Bnf { + Production, +} diff --git a/src/parser.rs b/src/parser.rs index 9676a3c..7b2019b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -147,6 +147,10 @@ impl<'a, I: ParserInput, O, E> Parser for BoxedParser<'a, I, O, E> { fn parse(&self, input: I) -> ParseResult { self.inner.parse(input) } + + fn bnf(&self) -> Option { + self.inner.bnf() + } } impl Parser for F @@ -158,6 +162,19 @@ where } } +impl Parser for (F, Bnf) +where + F: Fn(I) -> ParseResult, +{ + fn parse(&self, input: I) -> ParseResult { + self.0(input) + } + + fn bnf(&self) -> Option { + Some(self.1.clone()) + } +} + impl Parser for Rc where I: ParserInput, @@ -166,4 +183,8 @@ where fn parse(&self, input: I) -> ParseResult { self.as_ref().parse(input) } + + fn bnf(&self) -> Option { + self.as_ref().bnf() + } }