use super::lexer::Span;
#[derive(Debug, Clone)]
pub struct File {
pub items: Vec<Item>,
}
#[derive(Debug, Clone)]
pub enum Item {
Decl(Decl),
Use(UseDecl),
LineComment { text: String, span: Span },
FileDoc { text: String, span: Span },
BlankLine,
}
#[derive(Debug, Clone)]
pub struct UseDecl {
pub path: Vec<String>,
pub items: Vec<UseItem>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct UseItem {
pub name: String,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct Decl {
pub doc: Option<DocBlock>,
pub attributes: Vec<Attribute>,
pub kind: DeclKind,
pub span: Span,
}
#[derive(Debug, Clone)]
pub struct DocBlock {
pub lines: Vec<String>,
}
impl DocBlock {
pub fn joined(&self) -> String {
self.lines.join("\n")
}
}
#[derive(Debug, Clone)]
pub struct Attribute {
pub name: String,
pub args: Vec<AttrArg>,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum AttrArg {
Ident(String),
Str(String),
Int(i128),
Bool(bool),
}
#[derive(Debug, Clone)]
pub enum DeclKind {
Namespace(NamespaceDecl),
Const(ConstDecl),
Enum(EnumDecl),
TypeAlias(TypeAliasDecl),
}
#[derive(Debug, Clone)]
pub struct NamespaceDecl {
pub path: Vec<String>,
pub path_span: Span,
}
#[derive(Debug, Clone)]
pub struct ConstDecl {
pub type_expr: TypeExpr,
pub name: String,
pub name_span: Span,
pub value: ValueExpr,
}
#[derive(Debug, Clone)]
pub struct EnumDecl {
pub name: String,
pub name_span: Span,
pub backing: Option<TypeExpr>,
pub variants: Vec<EnumVariantDecl>,
}
#[derive(Debug, Clone)]
pub struct EnumVariantDecl {
pub doc: Option<DocBlock>,
pub name: String,
pub name_span: Span,
pub value: Option<ValueExpr>,
}
#[derive(Debug, Clone)]
pub struct TypeAliasDecl {
pub name: String,
pub name_span: Span,
pub target: TypeExpr,
}
#[derive(Debug, Clone)]
pub struct TypeExpr {
pub kind: TypeExprKind,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum TypeExprKind {
Named { path: Vec<String> },
Array(Box<TypeExpr>),
Optional(Box<TypeExpr>),
ArrayGeneric(Box<TypeExpr>),
FixedArrayGeneric { element: Box<TypeExpr>, length: u32 },
OptionalGeneric(Box<TypeExpr>),
Map {
key: Box<TypeExpr>,
value: Box<TypeExpr>,
},
Tuple(Vec<TypeExpr>),
}
#[derive(Debug, Clone)]
pub struct ValueExpr {
pub kind: ValueExprKind,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum ValueExprKind {
Int {
value: i128,
suffix: Option<String>,
},
Float {
value: f64,
suffix: Option<String>,
},
Bool(bool),
Str(String),
None_,
Path {
path: Vec<String>,
},
Array {
items: Vec<ValueExpr>,
trailing_comma: bool,
},
Map {
entries: Vec<(MapKey, ValueExpr)>,
trailing_comma: bool,
},
Tuple {
items: Vec<ValueExpr>,
trailing_comma: bool,
},
Neg(Box<ValueExpr>),
}
#[derive(Debug, Clone)]
pub struct MapKey {
pub kind: MapKeyKind,
pub span: Span,
}
#[derive(Debug, Clone)]
pub enum MapKeyKind {
Str(String),
Ident(String),
Int(i128),
}