mod elements;
mod webidls;
use convert_case::{Case, Casing};
pub use elements::{parse_elements, parse_struct_name, ParsedElement};
pub use webidls::{parse_webidls, ParsedInterface};
use serde::{Deserialize, Serialize};
use std::fmt::Display;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Attribute {
pub name: String,
pub description: String,
pub field_name: String,
pub ty: AttributeType,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum AttributeType {
Bool,
String,
Integer,
Float,
Identifier(String),
Enumerable(Vec<String>),
}
impl Display for AttributeType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
AttributeType::Bool => write!(f, "bool"),
AttributeType::String => write!(f, "String"),
AttributeType::Integer => write!(f, "i64"),
AttributeType::Float => write!(f, "f64"),
AttributeType::Identifier(_) => todo!("identifier attr not yet implemented"),
AttributeType::Enumerable(_) => todo!("enum attr not yet implemented"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum ParsedCategory {
Metadata,
Flow,
Sectioning,
Heading,
Phrasing,
Embedded,
Interactive,
Palpable,
ScriptSupporting,
Transparent,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum ParsedRelationship {
Element(String),
Category(ParsedCategory),
}
impl From<ParsedCategory> for ParsedRelationship {
fn from(value: ParsedCategory) -> Self {
ParsedRelationship::Category(value)
}
}
pub fn normalize_field_name(name: &str) -> String {
match name.to_case(Case::Snake).as_str() {
"loop" => "loop_".to_owned(),
"type" => "type_".to_owned(),
"for" => "for_".to_owned(),
"as" => "as_".to_owned(),
"async" => "async_".to_owned(),
other => other.to_owned(),
}
}