use serde::Serialize;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum Operator {
ArithmeticOperator,
RelationalOperator,
LogicalOperator,
NegateCondition,
UnaryOperator,
UpdateOperator,
RemovedCall,
ReturnValue,
BooleanLiteral,
StringLiteral,
OptionalChaining,
RegexLiteral,
}
impl Operator {
pub const ALL: [Self; 12] = [
Self::ArithmeticOperator,
Self::RelationalOperator,
Self::LogicalOperator,
Self::NegateCondition,
Self::UnaryOperator,
Self::UpdateOperator,
Self::RemovedCall,
Self::ReturnValue,
Self::BooleanLiteral,
Self::StringLiteral,
Self::OptionalChaining,
Self::RegexLiteral,
];
pub const fn as_str(self) -> &'static str {
match self {
Self::ArithmeticOperator => "arithmetic-operator",
Self::RelationalOperator => "relational-operator",
Self::LogicalOperator => "logical-operator",
Self::NegateCondition => "negate-condition",
Self::UnaryOperator => "unary-operator",
Self::UpdateOperator => "update-operator",
Self::RemovedCall => "removed-call",
Self::ReturnValue => "return-value",
Self::BooleanLiteral => "boolean-literal",
Self::StringLiteral => "string-literal",
Self::OptionalChaining => "optional-chaining",
Self::RegexLiteral => "regex-literal",
}
}
pub fn from_name(name: &str) -> Option<Self> {
Self::ALL
.into_iter()
.find(|operator| operator.as_str() == name)
}
}
impl std::fmt::Display for Operator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}