I am writing a parser, and I want to allow only certain types of tokens after certain other types of tokens, like, you can't have a number after another number, only a space or an operator. I have a number of different enums, one for each token, and I can create another enum to wrap all of them into one. Or just merge all those separate enums:
enum WhiteSpace {
WhiteSpace(Vec<char>),
}
pub enum Number {
Integer(Vec<char>),
Decimal(Vec<char>),
}
//etc
Instances of each of those enums are fed characters from the input, and when they get a char that does not belong to that type of token, they return an Error. In that case, I want to try and feed that char to every token type that can follow the current one, and for that I need to have some kind of a table, like:
...
WhiteSpace: [Number, Operator],
Number: [WhiteSpace],
Operator: [WhiteSpace]
But how can I do that?