fix(generate): return error when generated grammar's state count exceeds

the maximum allowed value.

Co-authored-by: Amaan Qureshi <git@amaanq.com>
This commit is contained in:
WillLillis 2025-09-25 02:40:08 -05:00 committed by Will Lillis
parent 335bfabc60
commit a9bce7c18a
2 changed files with 6 additions and 0 deletions

View file

@ -100,6 +100,10 @@ pub fn build_tables(
);
}
if parse_table.states.len() > u16::MAX as usize {
Err(ParseTableBuilderError::StateCount(parse_table.states.len()))?;
}
Ok(Tables {
parse_table,
main_lex_table: lex_tables.main_lex_table,

View file

@ -77,6 +77,8 @@ pub enum ParseTableBuilderError {
"The non-terminal rule `{0}` is used in a non-terminal `extra` rule, which is not allowed."
)]
ImproperNonTerminalExtra(String),
#[error("State count `{0}` exceeds the max value {max}.", max=u16::MAX)]
StateCount(usize),
}
#[derive(Default, Debug, Serialize)]