UNPKG

@mojir/lits

Version:

Lits is a pure functional programming language implemented in TypeScript

113 lines (112 loc) 4.05 kB
import type { ContextStack } from '../evaluator/ContextStack'; import type { EvaluateNode, ExecuteFunction } from '../evaluator/interface'; import type { GetUndefinedSymbols, UndefinedSymbols } from '../getUndefinedSymbols'; import type { Any, Arr } from '../interface'; import type { SpecialExpressionNode } from '../parser/types'; import type { SourceCodeInfo } from '../tokenizer/token'; import type { MaybePromise } from '../utils/maybePromise'; import type { SpecialExpressions } from '.'; export type Arity = { min?: number; max?: number; }; declare const dataTypes: readonly ["number", "string", "object", "array", "vector", "matrix", "grid", "boolean", "function", "integer", "any", "null", "collection", "sequence", "regexp", "never"]; export type DataType = typeof dataTypes[number]; export declare function isDataType(arg: string): arg is DataType; export declare const categoryRecord: { readonly 'special-expression': true; readonly predicate: true; readonly sequence: true; readonly collection: true; readonly array: true; readonly object: true; readonly string: true; readonly math: true; readonly functional: true; readonly 'regular-expression': true; readonly bitwise: true; readonly misc: true; readonly meta: true; readonly assertion: true; readonly vector: true; readonly 'linear-algebra': true; readonly matrix: true; readonly grid: true; readonly 'number-theory': true; readonly random: true; readonly convert: true; readonly shorthand: true; readonly datatype: true; }; export type Category = keyof typeof categoryRecord; export declare const categories: Category[]; export declare const moduleCategories: Category[]; export declare const coreCategories: Category[]; export interface TypedValue { type: DataType[] | DataType; rest?: true; array?: true; } export type Argument = TypedValue & { description?: string; }; export interface Variant { argumentNames: string[]; } export interface FunctionDocs { category: Category; description: string; returns: TypedValue; args: Record<string, Argument>; variants: Variant[]; examples: string[]; seeAlso?: string[]; hideOperatorForm?: true; tags?: string[]; } export interface CustomDocs { category: Category; description: string; customVariants: string[]; details?: [string, string, string | undefined][]; returns?: TypedValue; examples: string[]; seeAlso?: string[]; tags?: string[]; } export type SpecialExpressionDocs = FunctionDocs | CustomDocs; export declare function isFunctionDocs(docs: SpecialExpressionDocs): docs is FunctionDocs; type NormalExpressionEvaluator<T> = (params: Arr, sourceCodeInfo: SourceCodeInfo | undefined, contextStack: ContextStack, { executeFunction }: { executeFunction: ExecuteFunction; }) => MaybePromise<T>; export interface BuiltinNormalExpression<T> { evaluate: NormalExpressionEvaluator<T>; pure?: boolean; name?: string; arity: Arity; docs?: FunctionDocs; } export type BuiltinNormalExpressions = Record<string, BuiltinNormalExpression<Any>>; type BuiltinAllNormalExpressions = BuiltinNormalExpression<Any>[]; interface EvaluateHelpers { evaluateNode: EvaluateNode; builtin: Builtin; getUndefinedSymbols: GetUndefinedSymbols; } export interface BuiltinSpecialExpression<T, N extends SpecialExpressionNode> { evaluate: (node: N, contextStack: ContextStack, helpers: EvaluateHelpers) => MaybePromise<T>; evaluateAsNormalExpression?: NormalExpressionEvaluator<T>; arity: Arity; docs?: SpecialExpressionDocs; getUndefinedSymbols: (node: N, contextStack: ContextStack, params: { getUndefinedSymbols: GetUndefinedSymbols; builtin: Builtin; evaluateNode: EvaluateNode; }) => UndefinedSymbols; } export interface Builtin { normalExpressions: BuiltinNormalExpressions; allNormalExpressions: BuiltinAllNormalExpressions; specialExpressions: SpecialExpressions; } export {};