From a55a806a601b2531ed52b392b353f7a3a0fc1ff4 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Wed, 31 Jan 2024 00:31:16 -0800 Subject: [PATCH] EBNF: nonterminals --- src/representation.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/representation.rs b/src/representation.rs index acd33e7..ceb0fd7 100644 --- a/src/representation.rs +++ b/src/representation.rs @@ -26,6 +26,7 @@ impl Representation { #[derive(Debug)] pub enum EBNF { None, + Nonterminal(String), CharTerminal(char), Alternation(Vec), } @@ -44,6 +45,7 @@ impl fmt::Display for EBNF { } write!(f, "") } + EBNF::Nonterminal(name) => write!(f, "{name}"), } } } @@ -62,5 +64,12 @@ mod tests { ]); assert_eq!(example.to_string(), "'f' | 'a' | 'k' | 'e'"); + + let example = EBNF::Alternation(vec![ + EBNF::Nonterminal("other-rule".into()), + EBNF::CharTerminal('q'), + EBNF::CharTerminal('m'), + ]); + assert_eq!(example.to_string(), "other-rule | 'q' | 'm'"); } }