toylang
Version:
A toy programming language built with TypeScript for learning purposes
52 lines (51 loc) • 2.88 kB
TypeScript
import { tl } from "./typings";
declare type ForParams = {
test: tl.ForStatement["test"] | null;
init: tl.ForStatement["init"] | null;
update: tl.ForStatement["update"] | null;
body: tl.ForStatement["body"];
};
declare type ForReturn = {
type: tl.SyntaxKind.ForStatement;
test: tl.ForStatement["test"] | null;
init: tl.ForStatement["init"] | null;
update: tl.ForStatement["update"] | null;
body: tl.ForStatement["body"];
};
export interface ASTFactory {
Program(body: tl.Statement[]): tl.Program;
EmptyStatement(): tl.EmptyStatement;
BlockStatement(body: tl.Statement[]): tl.BlockStatement;
ExpressionStatement(expression: tl.Expression): tl.ExpressionStatement;
IfStatement(test: tl.IfStatement["test"], consequent: tl.IfStatement["consequent"], alternate: tl.IfStatement["alternate"]): tl.IfStatement;
ForStatement(props: ForParams): ForReturn;
ReturnStatement(argument: tl.Expression | null): tl.ReturnStatement;
WhileStatement(test: tl.Expression, body: tl.Statement): tl.WhileStatement;
DoWhileStatement(test: tl.Expression, body: tl.Statement): tl.DoWhileStatement;
VariableStatement(declarations: tl.VariableDeclaration[]): tl.VariableStatement;
VariableDeclaration(id: tl.Identifier, init: tl.VariableDeclaration["init"]): tl.VariableDeclaration;
AssignmentExpression({ operator, left, right, }: Omit<tl.AssignmentExpression, "type">): tl.AssignmentExpression;
BinaryExpression(operator: string, left: tl.BinaryExpression["left"], right: tl.BinaryExpression["right"]): tl.BinaryExpression;
LogicalExpression(operator: string, left: tl.LogicalExpression["left"], right: tl.LogicalExpression["right"]): tl.LogicalExpression;
Identifier(name: string): tl.Identifier;
NullLiteral(): tl.NullLiteral;
ThisExpression(): tl.ThisExpression;
Super(): tl.Super;
BooleanLiteral(value: boolean): tl.BooleanLiteral;
StringLiteral(value: string): tl.StringLiteral;
NumericLiteral(value: number): tl.NumericLiteral;
NewExpression(callee: tl.MemberExpression, args: tl.Arguments): tl.NewExpression;
UnaryExpression(operator: string, argument: tl.CallExpression | tl.CallMemberExpression | tl.UnaryExpression): tl.UnaryExpression;
ClassDeclaration(id: tl.Identifier, body: tl.BlockStatement, superClass: tl.Identifier | null): tl.ClassDeclaration;
FunctionStatement(name: tl.Identifier, body: tl.BlockStatement, params: tl.Identifier[] | null): tl.FunctionDeclaration;
}
export declare const DefaultASTFactory: ASTFactory;
export declare const SExpressionFactory: {
Program(body: any): any[];
EmptyStatement(): void;
BlockStatement(body: any): any[];
ExpressionStatement(expression: any): any;
StringLiteral(value: any): string;
NumericLiteral(value: any): any;
};
export {};