EBNF: nonterminals
This commit is contained in:
parent
698e05081a
commit
a55a806a60
@ -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'");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user