use crate::ddl_ast::parse::clause::{ClauseCursor, Tok};
use crate::error::SqlError;
pub(super) fn read_engine_suffix(c: &mut ClauseCursor<'_, '_>) -> Result<String, SqlError> {
c.eat_punct('=');
let name = match c.remaining_tokens().first().map(|t| &t.tok) {
Some(Tok::Str(_)) => c.string("ENGINE")?,
Some(Tok::Ident(s)) => {
let s = s.to_string();
c.skip(1);
s
}
Some(Tok::Word(_)) => c.word("ENGINE")?.to_string(),
Some(Tok::Punct('\'' | '"')) => {
return Err(c.error("unterminated quoted engine name in ENGINE clause"));
}
_ => return Err(c.error("missing engine name after ENGINE clause")),
};
let name = name.trim();
if name.is_empty() {
return Err(c.error("empty engine name in ENGINE clause"));
}
Ok(name.to_string())
}