UNPKG

derw

Version:

An Elm-inspired language that transpiles to TypeScript

398 lines (397 loc) 14 kB
import { Maybe } from "@eeue56/ts-core/build/main/lib/maybe"; export type GenericType = { kind: "GenericType"; name: string; }; export declare function GenericType(name: string): GenericType; export type FixedType = { kind: "FixedType"; name: string; args: Type[]; }; export declare function FixedType(name: string, args: Type[]): FixedType; export type ObjectLiteralType = { kind: "ObjectLiteralType"; properties: Record<string, Type>; }; export declare function ObjectLiteralType(properties: Record<string, Type>): ObjectLiteralType; export type FunctionType = { kind: "FunctionType"; args: Type[]; }; export declare function FunctionType(args: Type[]): FunctionType; export type Type = GenericType | FixedType | FunctionType | ObjectLiteralType; export type TagArg = { kind: "TagArg"; name: string; type: Type; }; export declare function TagArg(name: string, type: Type): TagArg; export type Tag = { kind: "Tag"; name: string; args: TagArg[]; }; export declare function Tag(name: string, args: TagArg[]): Tag; export type UnionType = { kind: "UnionType"; type: FixedType; tags: Tag[]; }; export declare function UnionType(type: FixedType, tags: Tag[]): UnionType; export type UnionUntaggedType = { kind: "UnionUntaggedType"; type: FixedType; values: StringValue[]; }; export declare function UnionUntaggedType(type: FixedType, values: StringValue[]): UnionUntaggedType; export type Property = { kind: "Property"; name: string; type: Type; }; export declare function Property(name: string, type: Type): Property; export type TypeAlias = { kind: "TypeAlias"; type: FixedType; properties: Property[]; }; export declare function TypeAlias(type: FixedType, properties: Property[]): TypeAlias; export type TypeclassFunction = { kind: "TypeclassFunction"; name: string; returnType: Type; args: Type[]; }; export declare function TypeclassFunction(name: string, returnType: Type, args: Type[]): TypeclassFunction; export type Typeclass = { kind: "Typeclass"; name: string; variables: GenericType[]; functions: TypeclassFunction[]; }; export declare function Typeclass(name: string, variables: GenericType[], functions: TypeclassFunction[]): Typeclass; export type Impl = { kind: "Impl"; name: string; qualifier: Type; functions: Block[]; }; export declare function Impl(name: string, qualifier: Type, functions: Block[]): Impl; export type FunctionArg = { kind: "FunctionArg"; name: string; type: Type; }; export declare function FunctionArg(name: string, type: Type): FunctionArg; export type AnonFunctionArg = { kind: "AnonFunctionArg"; index: number; type: Type; }; export declare function AnonFunctionArg(index: number, type: Type): AnonFunctionArg; export type FunctionArgsUnion = FunctionArg | AnonFunctionArg; export type Value = { kind: "Value"; body: string; }; export declare function Value(body: string): Value; export type ObjectLiteralBase = Value | null; export type Field = { kind: "Field"; name: string; value: Expression; }; export declare function Field(name: string, value: Expression): Field; export type ObjectLiteral = { kind: "ObjectLiteral"; base: ObjectLiteralBase; fields: Field[]; }; export declare function ObjectLiteral(base: ObjectLiteralBase, fields: Field[]): ObjectLiteral; export type StringValue = { kind: "StringValue"; body: string; }; export declare function StringValue(body: string): StringValue; export type ListValue = { kind: "ListValue"; items: Expression[]; }; export declare function ListValue(items: Expression[]): ListValue; export type ListRange = { kind: "ListRange"; start: Value; end: Value; }; export declare function ListRange(start: Value, end: Value): ListRange; export type FormatStringValue = { kind: "FormatStringValue"; body: string; }; export declare function FormatStringValue(body: string): FormatStringValue; export type Destructure = { kind: "Destructure"; constructor: string; pattern: string; }; export declare function Destructure(constructor: string, pattern: string): Destructure; export type Constructor = { kind: "Constructor"; constructor: string; pattern: ObjectLiteral; }; export declare function Constructor(constructor: string, pattern: ObjectLiteral): Constructor; export type ElseIfStatement = { predicate: Expression; body: Expression; letBody: Block[]; }; export declare function ElseIfStatement(predicate: Expression, body: Expression, letBody: Block[]): { kind: string; predicate: Expression; body: Expression; letBody: Block[]; }; export type IfStatement = { kind: "IfStatement"; predicate: Expression; ifBody: Expression; ifLetBody: Block[]; elseIf: ElseIfStatement[]; elseBody: Expression; elseLetBody: Block[]; }; export declare function IfStatement(predicate: Expression, ifBody: Expression, ifLetBody: Block[], elseIf: ElseIfStatement[], elseBody: Expression, elseLetBody: Block[]): IfStatement; export type Addition = { kind: "Addition"; left: Expression; right: Expression; }; export declare function Addition(left: Expression, right: Expression): Addition; export type Subtraction = { kind: "Subtraction"; left: Expression; right: Expression; }; export declare function Subtraction(left: Expression, right: Expression): Subtraction; export type Multiplication = { kind: "Multiplication"; left: Expression; right: Expression; }; export declare function Multiplication(left: Expression, right: Expression): Multiplication; export type Division = { kind: "Division"; left: Expression; right: Expression; }; export declare function Division(left: Expression, right: Expression): Division; export type Mod = { kind: "Mod"; left: Expression; right: Expression; }; export declare function Mod(left: Expression, right: Expression): Mod; export type And = { kind: "And"; left: Expression; right: Expression; }; export declare function And(left: Expression, right: Expression): And; export type Or = { kind: "Or"; left: Expression; right: Expression; }; export declare function Or(left: Expression, right: Expression): Or; export type ListPrepend = { kind: "ListPrepend"; left: Expression; right: Expression; }; export declare function ListPrepend(left: Expression, right: Expression): ListPrepend; export type LeftPipe = { kind: "LeftPipe"; left: Expression; right: LeftPipeableExpression; }; export declare function LeftPipe(left: Expression, right: LeftPipeableExpression): LeftPipe; export type RightPipe = { kind: "RightPipe"; left: Expression; right: Expression; }; export declare function RightPipe(left: Expression, right: Expression): RightPipe; export type ModuleReference = { kind: "ModuleReference"; path: string[]; value: Expression; }; export declare function ModuleReference(path: string[], value: Expression): ModuleReference; export type FunctionCall = { kind: "FunctionCall"; name: string; args: Expression[]; }; export declare function FunctionCall(name: string, args: Expression[]): FunctionCall; export type Lambda = { kind: "Lambda"; args: string[]; body: Expression; }; export declare function Lambda(args: string[], body: Expression): Lambda; export type LambdaCall = { kind: "LambdaCall"; args: Expression[]; lambda: Lambda; }; export declare function LambdaCall(lambda: Lambda, args: Expression[]): LambdaCall; export type Default = { kind: "Default"; }; export declare function Default(): Default; export type EmptyList = { kind: "EmptyList"; }; export declare function EmptyList(): EmptyList; export type ListDestructurePart = Value | StringValue | FormatStringValue | EmptyList | Destructure; export type ListDestructure = { kind: "ListDestructure"; parts: ListDestructurePart[]; }; export declare function ListDestructure(parts: ListDestructurePart[]): ListDestructure; export type BranchPattern = Default | Destructure | StringValue | FormatStringValue | EmptyList | ListDestructure; export type Branch = { kind: "Branch"; pattern: BranchPattern; body: Expression; letBody: Block[]; }; export declare function Branch(pattern: BranchPattern, body: Expression, letBody: Block[]): Branch; export type CaseStatement = { kind: "CaseStatement"; predicate: Expression; branches: Branch[]; }; export declare function CaseStatement(predicate: Expression, branches: Branch[]): CaseStatement; export type Equality = { kind: "Equality"; left: Expression; right: Expression; }; export declare function Equality(left: Expression, right: Expression): Equality; export type InEquality = { kind: "InEquality"; left: Expression; right: Expression; }; export declare function InEquality(left: Expression, right: Expression): InEquality; export type LessThan = { kind: "LessThan"; left: Expression; right: Expression; }; export declare function LessThan(left: Expression, right: Expression): LessThan; export type LessThanOrEqual = { kind: "LessThanOrEqual"; left: Expression; right: Expression; }; export declare function LessThanOrEqual(left: Expression, right: Expression): LessThanOrEqual; export type GreaterThan = { kind: "GreaterThan"; left: Expression; right: Expression; }; export declare function GreaterThan(left: Expression, right: Expression): GreaterThan; export type GreaterThanOrEqual = { kind: "GreaterThanOrEqual"; left: Expression; right: Expression; }; export declare function GreaterThanOrEqual(left: Expression, right: Expression): GreaterThanOrEqual; export type Expression = IfStatement | CaseStatement | Addition | Subtraction | Multiplication | Division | Mod | And | Or | ListPrepend | LeftPipe | RightPipe | ModuleReference | FunctionCall | Lambda | LambdaCall | Constructor | StringValue | FormatStringValue | ListValue | ListRange | Equality | InEquality | LessThan | LessThanOrEqual | GreaterThan | GreaterThanOrEqual | ObjectLiteral | Value; export type SimpleValue = "StringValue" | "FormatStringValue" | "ListValue" | "ListRange" | "Value" | "Addition" | "Subtraction" | "Multiplication" | "Division" | "Mod" | "Lambda" | "Equality" | "InEquality" | "LessThan" | "LessThanOrEqual" | "GreaterThan" | "GreaterThanOrEqual" | "And" | "Or" | "ListPrepend" | "ModuleReference" | "FunctionCall" | "LeftPipe" | "ObjectLiteral" | "Constructor"; export declare function isSimpleValue(kind: string): kind is SimpleValue; export type LeftPipeableExpression = LeftPipe | ModuleReference | FunctionCall | Lambda | Value; export declare function isLeftPipeableExpression(expression: Expression): expression is LeftPipeableExpression; export type Function = { kind: "Function"; name: string; returnType: Type; args: FunctionArgsUnion[]; letBody: Block[]; body: Expression; doBody: DoBlock | null; }; export declare function Function(name: string, returnType: Type, args: FunctionArgsUnion[], letBody: Block[], body: Expression, doBody?: DoBlock): Function; export type Const = { kind: "Const"; name: string; type: Type; letBody: Block[]; value: Expression; }; export declare function Const(name: string, type: Type, letBody: Block[], value: Expression): Const; export type ImportNamespace = "Global" | "Relative"; export type ImportModule = { kind: "ImportModule"; name: string; alias: Maybe<string>; exposing: string[]; namespace: ImportNamespace; }; export declare function ImportModule(name: string, alias: Maybe<string>, exposing: string[], namespace: ImportNamespace): ImportModule; export type Import = { kind: "Import"; modules: ImportModule[]; }; export declare function Import(modules: ImportModule[]): Import; export type Export = { kind: "Export"; names: string[]; }; export declare function Export(names: string[]): Export; export type Comment = { kind: "Comment"; body: string; }; export declare function Comment(body: string): Comment; export type MultilineComment = { kind: "MultilineComment"; body: string; }; export declare function MultilineComment(body: string): MultilineComment; export type UnparsedBlockTypes = "ImportBlock" | "ExportBlock" | "UnionTypeBlock" | "TypeAliasBlock" | "TypeclassBlock" | "ImplBlock" | "UnionUntaggedTypeBlock" | "FunctionBlock" | "ConstBlock" | "CommentBlock" | "MultilineCommentBlock" | "UnknownBlock"; export type UnparsedBlock = { kind: UnparsedBlockTypes; lineStart: number; lines: string[]; }; export declare function UnparsedBlock(kind: UnparsedBlockTypes, lineStart: number, lines: string[]): UnparsedBlock; export type BlockKinds = "Import" | "Export" | "UnionType" | "UnionUntaggedType" | "TypeAlias" | "Typeclass" | "Impl" | "Function" | "Const" | "Indent" | "Definition" | "Comment" | "MultilineComment" | "Unknown"; export type Block = UnionType | UnionUntaggedType | TypeAlias | Typeclass | Impl | Function | Const | Import | Export | Comment | MultilineComment; export type TypedBlock = UnionType | TypeAlias | UnionUntaggedType; export type DoExpression = FunctionCall | ModuleReference | IfStatement | Const | Function; export type DoBlock = { kind: "DoBlock"; expressions: DoExpression[]; }; export declare function DoBlock(expressions: DoExpression[]): DoBlock; export type Module = { kind: "Module"; name: string; body: Block[]; errors: string[]; }; export declare function Module(name: string, body: Block[], errors: string[]): Module; export type ContextModule = { kind: "ContextModule"; name: string; body: Block[]; unparsedBody: UnparsedBlock[]; errors: string[]; }; export declare function ContextModule(name: string, body: Block[], unparsedBody: UnparsedBlock[], errors: string[]): ContextModule; export declare function contextModuleToModule(module: ContextModule): Module;