EBNF StringTerminal

This commit is contained in:
Greg Shuflin 2024-01-31 00:47:45 -08:00
parent a55a806a60
commit be501f540e

View File

@ -28,6 +28,7 @@ pub enum EBNF {
None,
Nonterminal(String),
CharTerminal(char),
StringTerminal(String),
Alternation(Vec<EBNF>),
}
@ -46,6 +47,7 @@ impl fmt::Display for EBNF {
write!(f, "")
}
EBNF::Nonterminal(name) => write!(f, "{name}"),
EBNF::StringTerminal(term) => write!(f, r#""{term}""#),
}
}
}
@ -69,7 +71,8 @@ mod tests {
EBNF::Nonterminal("other-rule".into()),
EBNF::CharTerminal('q'),
EBNF::CharTerminal('m'),
EBNF::StringTerminal("focus".into()),
]);
assert_eq!(example.to_string(), "other-rule | 'q' | 'm'");
assert_eq!(example.to_string(), "other-rule | 'q' | 'm' | \"focus\"");
}
}