1use serde::Serialize;
2
3pub mod expr;
4pub mod statement;
5pub mod top_level;
6
7pub use expr::*;
8pub use statement::*;
9pub use top_level::*;
10
11#[derive(Debug, Clone, Serialize)]
12pub struct Path(pub Vec<Identifier>);
13
14#[derive(Debug, Clone, Serialize)]
15pub struct Identifier(pub String);
16
17#[derive(Debug, Clone, Serialize, Default)]
18pub struct ParamList(pub Vec<VarDecl>);
19
20#[derive(Debug, Clone, Serialize)]
21pub enum TypeExpr {
22 Ref {
23 lifetime: Option<Identifier>,
24 mutable: bool,
25 ty: Box<TypeExpr>,
26 },
27 Dyn(Box<TypeExpr>),
28 Path(Path, Option<Generics>),
29 Tuple(Vec<TypeExpr>),
30 Lifetime(Identifier),
31}
32
33#[derive(Debug, Clone, Serialize)]
34pub struct Spanned<T> {
35 pub line: usize,
36 pub column: usize,
37 pub item: T,
38}
39
40impl From<GenericDecl> for Generic {
41 fn from(value: GenericDecl) -> Self {
42 match value {
43 GenericDecl::Lifetime(life) => Generic::Lifetime(life),
44 GenericDecl::Type(ty, _) => Generic::Type(TypeExpr::Path(Path(vec![ty]), None)),
45 }
46 }
47}
48
49impl<T> Spanned<T> {
50 pub fn get_comment(&self) -> String {
51 format!("/* {}:{} */", self.line, self.column)
52 }
53}