import { Context } from './context'; import { BindvarCode, Code, CtxvarCode, FormatterCall, EvalCode, IfCode, IncludeCode, InjectCode, MacroCode, PredicateCode, RepeatedCode, RootCode } from './instructions'; import { Variable } from './variable'; import { FormatterMap, PredicateMap } from './plugin'; type Impl = (inst: Code, ctx: Context) => void; type Hook = Impl | null; export interface EngineProps { formatters?: FormatterMap; predicates?: PredicateMap; } /** * Engine that evaluates a tree of instructions and appends output to * the given context. All state for a single execution is maintained * in the Context, so a single Engine instance can be reused for * multiple concurrent compiles. */ export declare class Engine { impls: Hook[]; private formatters; private predicates; constructor(props?: EngineProps); /** * Looks up an opcode and executes the corresponding instruction. */ execute(inst: Code, ctx: Context): void; /** * Executes the root instruction. */ executeRoot(inst: RootCode, ctx: Context): void; /** * Execute a block of instructions. */ executeBlock(block: Code[], ctx: Context): void; /** * Variable instruction. * * inst[1] - list of variable names ['foo.bar', 'baz.quux'] * inst[2] - list of formatters with optional arguments [["html"], ["truncate", "10"]] */ executeVariable(inst: Code, ctx: Context): void; /** * Section instruction. * * inst[1] - single variable name 'foo.bar' * inst[2] - consequent block * inst[3] - alternate instruction */ executeSection(inst: Code, ctx: Context): void; /** * Repeated section instruction. * * inst[1] - single variable name 'foo.bar' * inst[2] - consequent block * inst[3] - alternate instruction * inst[4] - alternates-with block */ executeRepeated(inst: RepeatedCode, ctx: Context): void; /** * Predicate instruction. * * inst[1] - predicate name, or 0 if none. * inst[2] - predicate args, or 0 if none * inst[3] - consequent block * inst[4] - alternate instruction */ executePredicate(inst: PredicateCode, ctx: Context): void; /** * Bindvar instruction. * * inst[1] - variable to define, e.g. '@foo' * inst[2] - list of variable(s) to resolve * inst[3] - list of formatters with optional arguments */ executeBindvar(inst: BindvarCode, ctx: Context): void; /** * Ctxvar instruction. * * inst[1] - variable to define, e.g. '@foo' * inst[2] - list of context bindings, e.g. ['baz', ['foo', 'bar', 'baz']] */ executeCtxvar(inst: CtxvarCode, ctx: Context): void; /** * Eval instruction * * inst[1] - string expression to evaluate */ executeEval(inst: EvalCode, ctx: Context): void; /** * If instruction. * * inst[1] - array of operators (0=OR 1=AND) * inst[2] - array of variables * inst[3] - consequent block * inst[4] - alternate instruction */ executeIf(inst: IfCode, ctx: Context): void; /** * Include instruction. * * inst[1] - name of macro or partial to include * inst[2] - optional arguments */ executeInclude(inst: IncludeCode, ctx: Context): void; /** * Inject instruction. * * inst[1] - variable to define, e.g. '@foo' * inst[2] - file path to resolve (key in the injectables map) * inst[3] - optional arguments (currently unused) */ executeInject(inst: InjectCode, ctx: Context): void; /** * Macro instruction. * * inst[1] - name of the macro * inst[2] - block of instructions to execute */ executeMacro(inst: MacroCode, ctx: Context): void; /** * Resolve one or more variables against the context. Accepts a raw list of * variable names (e.g. ['foo.bar', 'baz.quux']), splits each info parts * (.e.g. [['foo', 'bar'], ['baz', 'quux']]), resolves them against the * context, and wraps in a Variable instance. */ resolveVariables(rawlist: (string | number)[][], ctx: Context): Variable[]; /** * Apply formatters to the list of vars. */ applyFormatters(formatters: FormatterMap, calls: FormatterCall[], vars: Variable[], ctx: Context): void; } export {};