use serde::Serialize; pub mod expr; pub mod statement; pub mod top_level; pub use expr::*; pub use statement::*; pub use top_level::*; #[derive(Debug, Clone, Serialize)] pub struct Path(pub Vec); #[derive(Debug, Clone, Serialize)] pub struct Identifier(pub String); #[derive(Debug, Clone, Serialize, Default)] pub struct ParamList(pub Vec); #[derive(Debug, Clone, Serialize)] pub enum TypeExpr { Ref { lifetime: Option, mutable: bool, ty: Box, }, UnsafePtr { mutable: bool, ty: Box, }, Dyn(Box), Path(Path, Option), StaticFn(Vec, Option>), Tuple(Vec), Lifetime(Identifier), } #[derive(Debug, Clone, Serialize)] pub struct Spanned { pub line: usize, pub column: usize, pub item: T, } impl From for Generic { fn from(value: GenericDecl) -> Self { match value { GenericDecl::Lifetime(life) => Generic::Lifetime(life), GenericDecl::Type(ty, _) => Generic::Type(TypeExpr::Path(Path(vec![ty]), None)), } } } impl Into> for GenericsDecl { fn into(self) -> Option { if self.0.len() == 0 { None } else { Some(self.into()) } } } impl From for Generics { fn from(value: GenericsDecl) -> Self { Self(value.0.into_iter().map(Generic::from).collect()) } } impl Spanned { pub fn get_comment(&self) -> String { format!("/* {}:{} */", self.line, self.column) } }