EBNF: nonterminals

This commit is contained in:
Greg Shuflin 2024-01-31 00:31:16 -08:00
parent 698e05081a
commit a55a806a60

View File

@ -26,6 +26,7 @@ impl Representation {
#[derive(Debug)]
pub enum EBNF {
None,
Nonterminal(String),
CharTerminal(char),
Alternation(Vec<EBNF>),
}
@ -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'");
}
}