use clap::ValueEnum;
#[derive(Debug, Clone, ValueEnum)]
pub enum Language {
Python,
Rust,
Pandas,
Mysql,
Postgres,
}
impl From<&String> for Language {
fn from(value: &String) -> Self {
match value.as_str() {
"python3" => Self::Python,
"rust" => Self::Rust,
"pythondata" => Self::Pandas,
"mysql" => Self::Mysql,
"postgresql" => Self::Postgres,
_ => Self::Mysql,
}
}
}
impl From<String> for Language {
fn from(value: String) -> Self {
match value.as_str() {
"python3" => Self::Python,
"rust" => Self::Rust,
"pythondata" => Self::Pandas,
"mysql" => Self::Mysql,
"postgresql" => Self::Postgres,
_ => Self::Mysql,
}
}
}
impl Language {
pub fn to_lang_slug(&self) -> &'static str {
match self {
Language::Python => "python3",
Language::Rust => "rust",
Language::Mysql => "mysql",
Language::Pandas => "pythondata",
Language::Postgres => "postgresql",
}
}
pub fn from_extension(ext: &str) -> Self {
match ext {
"py" => Language::Python,
"rs" => Language::Rust,
"sql" => Language::Mysql,
_ => Language::Mysql,
}
}
pub fn code_extension(&self) -> &'static str {
match self {
Language::Python | Language::Pandas => "py",
Language::Rust => "rs",
Language::Mysql | Language::Postgres => "sql",
}
}
pub fn meta_comment_prefix(&self) -> &'static str {
match self {
Language::Python | Language::Pandas | Language::Mysql => "#",
Language::Rust => "//",
Language::Postgres => "--",
}
}
}
#[derive(Debug, Clone)]
pub enum Identifier {
Number(u64),
String(String),
}