2025-01-23 09:28:48 +00:00
|
|
|
import { Span } from "../diagnostics.ts";
|
|
|
|
|
2025-01-22 21:40:29 +00:00
|
|
|
export type File = {
|
|
|
|
stmts: Stmt[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Stmt = {
|
|
|
|
kind: StmtKind;
|
2025-01-23 09:28:48 +00:00
|
|
|
span: Span;
|
2025-01-22 21:40:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type StmtKind =
|
|
|
|
| { tag: "error" }
|
2025-01-23 13:19:27 +00:00
|
|
|
| { tag: "item" } & ItemStmt
|
|
|
|
| { tag: "let" } & LetStmt
|
|
|
|
| { tag: "return" } & ReturnStmt
|
|
|
|
| { tag: "break" } & BreakStmt
|
|
|
|
| { tag: "assign" } & AssignStmt
|
|
|
|
| { tag: "expr" } & ExprStmt;
|
2025-01-22 21:40:29 +00:00
|
|
|
|
2025-01-23 13:19:27 +00:00
|
|
|
export type ItemStmt = { item: Item };
|
|
|
|
|
|
|
|
export type LetStmt = {
|
|
|
|
subject: Pat;
|
|
|
|
expr?: Expr;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type ReturnStmt = { expr?: Expr };
|
|
|
|
export type BreakStmt = { expr?: Expr };
|
|
|
|
|
|
|
|
export type AssignStmt = {
|
|
|
|
assignType: AssignType;
|
|
|
|
subject: Expr;
|
|
|
|
value: Expr;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type AssignType = "=" | "+=" | "-=";
|
|
|
|
|
|
|
|
export type ExprStmt = { expr: Expr };
|
|
|
|
|
|
|
|
export type Item = {
|
|
|
|
kind: ItemKind;
|
|
|
|
span: Span;
|
|
|
|
ident: Ident;
|
|
|
|
pub: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type ItemKind =
|
|
|
|
| { tag: "error" }
|
|
|
|
| { tag: "mod_block" } & ModBlockItem
|
|
|
|
| { tag: "mod_file" } & ModFileItem
|
|
|
|
| { tag: "enum" } & EnumItem
|
|
|
|
| { tag: "struct" } & StructItem
|
|
|
|
| { tag: "fn" } & FnItem
|
|
|
|
| { tag: "use" } & UseItem
|
|
|
|
| { tag: "static" } & StaticItem
|
|
|
|
| { tag: "type_alias" } & TypeAliasItem;
|
|
|
|
|
|
|
|
export type ModBlockItem = {
|
|
|
|
ident: Ident;
|
2025-01-22 21:40:29 +00:00
|
|
|
stmts: Stmt[];
|
|
|
|
};
|
|
|
|
|
2025-01-23 13:19:27 +00:00
|
|
|
export type ModFileItem = {
|
|
|
|
ident: Ident;
|
2025-01-22 21:40:29 +00:00
|
|
|
filePath: string;
|
|
|
|
};
|
2025-01-23 13:19:27 +00:00
|
|
|
|
|
|
|
export type EnumItem = { variants: Variant[] };
|
|
|
|
export type StructItem = { data: VariantData };
|
|
|
|
export type FnItem = { _: 0 };
|
|
|
|
export type UseItem = { _: 0 };
|
|
|
|
export type StaticItem = { _: 0 };
|
|
|
|
export type TypeAliasItem = { _: 0 };
|
|
|
|
|
|
|
|
export type Variant = {
|
|
|
|
ident: Ident;
|
|
|
|
data: VariantData;
|
|
|
|
pub: boolean;
|
|
|
|
span: Span;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type VariantData = {
|
|
|
|
kind: VariantDataKind;
|
|
|
|
span: Span;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type VariantDataKind =
|
|
|
|
| { tag: "error" }
|
|
|
|
| { tag: "unit" }
|
|
|
|
| { tag: "tuple" } & TupleVariantData
|
|
|
|
| { tag: "struct" } & StructVariantData;
|
|
|
|
|
|
|
|
export type TupleVariantData = { elems: VariantData[] };
|
|
|
|
export type StructVariantData = { fields: FieldDef[] };
|
|
|
|
|
|
|
|
export type FieldDef = {
|
|
|
|
ident: Ident;
|
|
|
|
ty: Ty;
|
|
|
|
pub: boolean;
|
|
|
|
span: Span;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Expr = {
|
|
|
|
kind: ExprKind;
|
|
|
|
span: Span;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type ExprKind =
|
|
|
|
| { tag: "error" }
|
|
|
|
| { tag: "ident" } & Ident;
|
|
|
|
|
|
|
|
export type Pat = {
|
|
|
|
kind: PatKind;
|
|
|
|
span: Span;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PatKind =
|
|
|
|
| { tag: "error" }
|
|
|
|
| { tag: "bind" } & BindPat;
|
|
|
|
|
|
|
|
export type BindPat = {
|
|
|
|
ident: Ident;
|
|
|
|
mut: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Ty = {
|
|
|
|
kind: TyKind;
|
|
|
|
span: Span;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type TyKind =
|
|
|
|
| { tag: "error" }
|
|
|
|
| { tag: "ident" } & Ident
|
|
|
|
| { tag: "ref" } & RefTy
|
|
|
|
| { tag: "ptr" } & PtrTy
|
|
|
|
| { tag: "slice" } & SliceTy
|
|
|
|
| { tag: "array" } & ArrayTy;
|
|
|
|
|
|
|
|
export type RefTy = { ty: Ty; mut: boolean };
|
|
|
|
export type PtrTy = { ty: Ty; mut: boolean };
|
|
|
|
export type SliceTy = { ty: Ty };
|
|
|
|
export type ArrayTy = { ty: Ty; length: Expr };
|
|
|
|
export type TupleTy = { elems: Ty[] };
|
|
|
|
export type StructTy = { fields: FieldDef[] };
|
|
|
|
|
|
|
|
export type AnonFieldDef = {
|
|
|
|
ident: Ident;
|
|
|
|
ty: Ty;
|
|
|
|
span: Span;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Ident = { text: string; span: Span };
|