import { Cell, Sym } from '@stemcmicro/atoms';
import { ExprContext, LambdaExpr, ExprHandler } from '@stemcmicro/context';
import { U, Atom, Cons } from '@stemcmicro/tree';

interface RenderConfig {
    format: "Ascii" | "Human" | "Infix" | "LaTeX" | "SExpr" | "SVG";
    useCaretForExponentiation: boolean;
    useParenForTensors: boolean;
}
declare enum Concept {
    Last = 1,
    TTY = 2
}
interface CellListener {
    reset(from: U, to: U, source: Cell): void;
}
interface ExprEngineListener {
    output(output: string): void;
}
interface ExprHandlerBuilder<T extends U> {
    create(): ExprHandler<T>;
}
interface ExprEngine extends Pick<ExprContext, "clearBindings">, Pick<ExprContext, "pushDirective" | "popDirective"> {
    clearBindings(): void;
    defineAtomHandler<T extends Atom>(builder: ExprHandlerBuilder<T>, type: string, guard: (expr: Atom) => boolean): void;
    defineFunction(name: Sym, lambda: LambdaExpr): void;
    parse(sourceText: string): {
        trees: U[];
        errors: Error[];
    };
    valueOf(expr: U): U;
    getBinding(opr: Sym, target: Cons): U;
    hasBinding(opr: Sym, target: Cons): boolean;
    setBinding(opr: Sym, binding: U): void;
    hasUserFunction(name: Sym): boolean;
    getUserFunction(name: Sym): U;
    setUserFunction(name: Sym, userfunc: U): void;
    symbol(concept: Concept): Sym;
    renderAsString(expr: U, config?: Partial<RenderConfig>): string;
    addCellListener(listener: CellListener): void;
    removeCellListener(listener: CellListener): void;
    addListener(listener: ExprEngineListener): void;
    removeListener(listener: ExprEngineListener): void;
    release(): void;
}
interface EngineConfig {
    allowUndeclaredVars: "Err" | "Nil";
    prolog: string[];
    traceLevel: 0 | 1;
    useCaretForExponentiation: boolean;
    useDerivativeShorthandLowerD: boolean;
    useIntegersForPredicates: boolean;
}
declare function create_engine(options?: Partial<EngineConfig>): ExprEngine;

export { type CellListener, type EngineConfig, type ExprEngine, type ExprEngineListener, create_engine };
