UNPKG

@mojir/lits

Version:

Lits is a Lisp dialect implemented in TypeScript

55 lines (54 loc) 1.89 kB
import type { Context } from '../evaluator/interface'; import type { Any } from '../interface'; import type { Ast, LitsFunction } from '../parser/types'; import type { TokenStream } from '../tokenizer/tokenize'; import { Cache } from './Cache'; export interface LitsRuntimeInfo { astCache: Cache | null; astCacheSize: number | null; debug: boolean; } export interface LazyValue { read: () => unknown; [key: string]: unknown; } export interface JsFunction { fn: (...args: any[]) => unknown; } export interface ContextParams { globalContext?: Context; contexts?: Context[]; values?: Record<string, unknown>; lazyValues?: Record<string, LazyValue>; jsFunctions?: Record<string, JsFunction>; } export interface MinifyParams { minify?: boolean; } export interface FilePathParams { filePath?: string; } interface LitsConfig { initialCache?: Record<string, Ast>; astCacheSize?: number | null; debug?: boolean; } export declare class Lits { private astCache; private astCacheSize; private debug; constructor(config?: LitsConfig); getRuntimeInfo(): LitsRuntimeInfo; run(program: string, params?: ContextParams & FilePathParams): unknown; context(programOrAst: string | Ast, params?: ContextParams & FilePathParams): Context; getUndefinedSymbols(programOrAst: string | Ast, params?: ContextParams): Set<string>; tokenize(program: string, tokenizeParams?: FilePathParams & MinifyParams): TokenStream; parse(tokenStream: TokenStream): Ast; evaluate(ast: Ast, params: ContextParams): Any; transformSymbols(tokenStream: TokenStream, transformer: (symbol: string) => string): TokenStream; untokenize(tokenStream: TokenStream): string; apply(fn: LitsFunction, fnParams: unknown[], params?: ContextParams): Any; private generateApplyFunctionCall; private generateAst; } export {};