structemit/ast.ts
2025-03-18 02:10:45 +01:00

37 lines
710 B
TypeScript

export type Struct = {
id: number;
ident: string;
loc: Loc;
generics: Generics | null;
fields: Field[];
};
export type Generics = { params: string[] };
export type Field = {
ident: string;
loc: Loc;
ty: Ty;
};
export type Ty = {
id: number;
loc: Loc;
kind: TyKind;
};
export type TyKind =
| { tag: "array"; length: number | null; ty: Ty }
| { tag: "generic"; ident: string; args: Ty[] }
| { tag: "struct_literal"; fields: Field[] }
| { tag: "ident"; ident: string }
| { tag: "int"; value: number };
export type Loc = {
source: string;
start: Pos;
end: Pos;
};
export type Pos = { offset: number; line: number; column: number };