zignet
Version:
MCP server for Zig — AI-powered code analysis, validation, and documentation with fine-tuned LLM
325 lines • 6.67 kB
TypeScript
//#region src/ast.d.ts
/**
* Abstract Syntax Tree (AST) Node Types for Zig
*/
/**
* Base interface for all AST nodes
*/
interface ASTNode {
type: string;
line?: number;
column?: number;
}
/**
* Program node - root of the AST
*/
interface Program extends ASTNode {
type: 'Program';
body: Declaration[];
}
/**
* All possible declaration types
*/
type Declaration = FunctionDeclaration | VariableDeclaration | StructDeclaration | UnionDeclaration | EnumDeclaration;
/**
* Function declaration
* Example: fn add(a: i32, b: i32) i32 { return a + b; }
*/
interface FunctionDeclaration extends ASTNode {
type: 'FunctionDeclaration';
name: string;
parameters: Parameter[];
returnType: TypeAnnotation;
body: BlockStatement;
isInline?: boolean;
isComptime?: boolean;
errorUnion?: boolean;
}
/**
* Function parameter
*/
interface Parameter extends ASTNode {
type: 'Parameter';
name: string;
typeAnnotation: TypeAnnotation;
isComptime?: boolean;
}
/**
* Variable declaration (const or var)
*/
interface VariableDeclaration extends ASTNode {
type: 'VariableDeclaration';
isConst: boolean;
name: string;
typeAnnotation?: TypeAnnotation;
initializer?: Expression;
}
/**
* Struct declaration
* Example: const Point = struct { x: i32, y: i32 };
*/
interface StructDeclaration extends ASTNode {
type: 'StructDeclaration';
name: string;
fields: StructField[];
}
/**
* Struct field
*/
interface StructField extends ASTNode {
type: 'StructField';
name: string;
typeAnnotation: TypeAnnotation;
}
/**
* Union declaration
*/
interface UnionDeclaration extends ASTNode {
type: 'UnionDeclaration';
name: string;
fields: StructField[];
}
/**
* Enum declaration
*/
interface EnumDeclaration extends ASTNode {
type: 'EnumDeclaration';
name: string;
members: EnumMember[];
}
/**
* Enum member
*/
interface EnumMember extends ASTNode {
type: 'EnumMember';
name: string;
value?: Expression;
}
/**
* Type annotation
*/
type TypeAnnotation = PrimitiveType | IdentifierType | PointerType | ArrayType | ErrorUnionType | OptionalType;
/**
* Primitive type (i32, f64, bool, void, etc.)
*/
interface PrimitiveType extends ASTNode {
type: 'PrimitiveType';
name: string;
}
/**
* Identifier type (custom types, structs, etc.)
*/
interface IdentifierType extends ASTNode {
type: 'IdentifierType';
name: string;
}
/**
* Pointer type (*T)
*/
interface PointerType extends ASTNode {
type: 'PointerType';
pointeeType: TypeAnnotation;
}
/**
* Array type ([N]T)
*/
interface ArrayType extends ASTNode {
type: 'ArrayType';
size?: number;
elementType: TypeAnnotation;
}
/**
* Error union type (!T)
*/
interface ErrorUnionType extends ASTNode {
type: 'ErrorUnionType';
valueType: TypeAnnotation;
}
/**
* Optional type (?T)
*/
interface OptionalType extends ASTNode {
type: 'OptionalType';
valueType: TypeAnnotation;
}
/**
* All statement types
*/
type Statement = BlockStatement | ReturnStatement | IfStatement | WhileStatement | ForStatement | BreakStatement | ContinueStatement | ExpressionStatement | VariableDeclaration | ComptimeStatement;
/**
* Block statement { ... }
*/
interface BlockStatement extends ASTNode {
type: 'BlockStatement';
statements: Statement[];
}
/**
* Return statement
*/
interface ReturnStatement extends ASTNode {
type: 'ReturnStatement';
value?: Expression;
}
/**
* If statement
*/
interface IfStatement extends ASTNode {
type: 'IfStatement';
condition: Expression;
consequent: Statement;
alternate?: Statement;
}
/**
* While statement
*/
interface WhileStatement extends ASTNode {
type: 'WhileStatement';
condition: Expression;
body: Statement;
}
/**
* For statement
*/
interface ForStatement extends ASTNode {
type: 'ForStatement';
initializer?: Expression | VariableDeclaration;
condition?: Expression;
increment?: Expression;
body: Statement;
}
/**
* Break statement
*/
interface BreakStatement extends ASTNode {
type: 'BreakStatement';
}
/**
* Continue statement
*/
interface ContinueStatement extends ASTNode {
type: 'ContinueStatement';
}
/**
* Expression statement (expression followed by semicolon)
*/
interface ExpressionStatement extends ASTNode {
type: 'ExpressionStatement';
expression: Expression;
}
/**
* Comptime statement
*/
interface ComptimeStatement extends ASTNode {
type: 'ComptimeStatement';
body: BlockStatement;
}
/**
* All expression types
*/
type Expression = BinaryExpression | UnaryExpression | CallExpression | MemberExpression | IndexExpression | Identifier | NumberLiteral | StringLiteral | BooleanLiteral | StructLiteral | ArrayLiteral | AssignmentExpression;
/**
* Binary expression (a + b, a * b, etc.)
*/
interface BinaryExpression extends ASTNode {
type: 'BinaryExpression';
operator: string;
left: Expression;
right: Expression;
}
/**
* Unary expression (-a, !a, etc.)
*/
interface UnaryExpression extends ASTNode {
type: 'UnaryExpression';
operator: string;
operand: Expression;
}
/**
* Function call expression
*/
interface CallExpression extends ASTNode {
type: 'CallExpression';
callee: Expression;
arguments: Expression[];
}
/**
* Member access expression (obj.field)
*/
interface MemberExpression extends ASTNode {
type: 'MemberExpression';
object: Expression;
property: string;
}
/**
* Index expression (arr[i])
*/
interface IndexExpression extends ASTNode {
type: 'IndexExpression';
object: Expression;
index: Expression;
}
/**
* Identifier
*/
interface Identifier extends ASTNode {
type: 'Identifier';
name: string;
}
/**
* Number literal
*/
interface NumberLiteral extends ASTNode {
type: 'NumberLiteral';
value: number;
}
/**
* String literal
*/
interface StringLiteral extends ASTNode {
type: 'StringLiteral';
value: string;
}
/**
* Boolean literal
*/
interface BooleanLiteral extends ASTNode {
type: 'BooleanLiteral';
value: boolean;
}
/**
* Struct literal
* Example: Point{ .x = 1, .y = 2 }
*/
interface StructLiteral extends ASTNode {
type: 'StructLiteral';
typeName: string;
fields: StructLiteralField[];
}
/**
* Struct literal field
*/
interface StructLiteralField extends ASTNode {
type: 'StructLiteralField';
name: string;
value: Expression;
}
/**
* Array literal
* Example: [_]i32{1, 2, 3}
*/
interface ArrayLiteral extends ASTNode {
type: 'ArrayLiteral';
elements: Expression[];
}
/**
* Assignment expression
*/
interface AssignmentExpression extends ASTNode {
type: 'AssignmentExpression';
operator: string;
left: Expression;
right: Expression;
}
//#endregion
export { Program as t };
//# sourceMappingURL=ast-DVcyx7L5.d.ts.map