import { Opcode } from './opcodes'; export type FAST_NULL = 0; export declare const FAST_NULL: FAST_NULL; export declare enum Operator { OR = 0, AND = 1 } export type Reference = (string | number)[]; export type Arguments = [string[], string]; export type FormatterCall = [string] | [string, Arguments]; export type Binding = [string, Reference]; export interface AtomCode { [0]: Opcode.ATOM; [1]: any; } export interface BindvarCode { [0]: Opcode.BINDVAR; [1]: string; [2]: any[]; [3]: FAST_NULL | FormatterCall[]; } export interface CommentCode { [0]: Opcode.COMMENT; [1]: string; [2]: number; } export interface CtxvarCode { [0]: Opcode.CTXVAR; [1]: string; [2]: Binding[]; } export interface EvalCode { [0]: Opcode.EVAL; [1]: string; expr?: any; debug?: boolean; } export interface IfCode { [0]: Opcode.IF; [1]: Operator[]; [2]: Reference[]; [3]: Code[]; [4]: Code | undefined; } export interface IncludeCode { [0]: Opcode.INCLUDE; [1]: string; [2]: Arguments | FAST_NULL; } export interface InjectCode { [0]: Opcode.INJECT; [1]: string; [2]: string; [3]: Arguments | FAST_NULL; } export interface MacroCode { [0]: Opcode.MACRO; [1]: string; [2]: Code[]; } export interface OrPredicateCode { [0]: Opcode.OR_PREDICATE; [1]: string | number; [2]: Arguments | number; [3]: Code[]; [4]: Code | undefined; } export interface PredicateCode { [0]: Opcode.PREDICATE; [1]: string | number; [2]: Arguments | 0; [3]: Code[]; [4]: Code | undefined; } export interface RepeatedCode { [0]: Opcode.REPEATED; [1]: Reference; [2]: Code[]; [3]: Code; [4]: Code[]; } export interface RootCode { [0]: Opcode.ROOT; [1]: number; [2]: Code[]; [3]: Code; } export interface SectionCode { [0]: Opcode.SECTION; [1]: Reference; [2]: Code[]; [3]: Code; } export interface StructCode { [0]: Opcode.STRUCT; [1]: any; [2]: Code[]; } export interface TextCode { [0]: Opcode.TEXT; [1]: string; } export interface VariableCode { [0]: Opcode.VARIABLE; [1]: Reference[]; [2]: FAST_NULL | FormatterCall[]; } export type Code = AtomCode | BindvarCode | CommentCode | CtxvarCode | EvalCode | IfCode | IncludeCode | InjectCode | MacroCode | OrPredicateCode | PredicateCode | RepeatedCode | RootCode | SectionCode | StructCode | TextCode | VariableCode | Opcode.ALTERNATES_WITH | Opcode.END | Opcode.EOF | Opcode.META_LEFT | Opcode.META_RIGHT | Opcode.NEWLINE | Opcode.SPACE | Opcode.TAB | FAST_NULL; export declare class BaseInstruction { readonly type: Opcode; readonly code: Code; constructor(type: Opcode, code: Code); } export type Instruction = Opcode.ALTERNATES_WITH | Opcode.END | Opcode.EOF | Opcode.META_LEFT | Opcode.META_RIGHT | Opcode.NEWLINE | Opcode.SPACE | Opcode.TAB | BaseInstruction; export interface CompositeInstruction { addConsequent(inst: Instruction): void; } export interface BlockInstruction extends CompositeInstruction { setAlternate(inst: Instruction): void; } export declare const getType: (inst: Instruction | Opcode) => Opcode; export declare const getCode: (inst: Instruction) => Code; export declare const orNull: (v?: any[]) => 0 | any[]; /** * Holds a JSON-encodable, opaque value. */ export declare class Atom extends BaseInstruction { constructor(opaque: any); } export declare class Bindvar extends BaseInstruction { constructor(name: string, variables: any[], formatters?: any[]); } export declare class Comment extends BaseInstruction { constructor(text: string, multiline: number | boolean); } export declare class Ctxvar extends BaseInstruction { constructor(name: string, bindings: Binding[]); } export declare class EvalInst extends BaseInstruction { cached: any; constructor(code: string); } export declare class If extends BaseInstruction implements BlockInstruction { constructor(operators: Operator[], variables: Reference[]); addConsequent(inst: Instruction): void; setAlternate(inst: Instruction): void; } export declare class Include extends BaseInstruction { constructor(name: string, args: Arguments | FAST_NULL); } export declare class Inject extends BaseInstruction { constructor(name: string, path: string, args: Arguments | FAST_NULL); } export declare class Macro extends BaseInstruction implements CompositeInstruction { constructor(name: string); addConsequent(inst: Instruction): void; } export declare class OrPredicate extends BaseInstruction { constructor(name?: string | number, args?: Arguments | FAST_NULL); hasPredicate(): boolean; addConsequent(inst: Instruction): void; setAlternate(inst: Instruction): void; } export declare class Predicate extends BaseInstruction implements BlockInstruction { constructor(name: string, args: Arguments | FAST_NULL); addConsequent(inst: Instruction): void; setAlternate(inst: Instruction): void; } export declare class Repeated extends BaseInstruction implements BlockInstruction { constructor(name: Reference); addConsequent(inst: Instruction): void; setAlternate(inst: Instruction): void; setAlternatesWith(inst: Instruction): void; } export declare class Root extends BaseInstruction implements BlockInstruction { constructor(); addConsequent(inst: Instruction): void; setAlternate(inst: Instruction): void; } export declare class Section extends BaseInstruction implements BlockInstruction { constructor(name: Reference); addConsequent(inst: Instruction): void; setAlternate(inst: Instruction): void; } /** * Generic block that does nothing but hold a JSON-encodable, opaque value and an * array of child nodes. */ export declare class Struct extends BaseInstruction implements CompositeInstruction { constructor(opaque: any); addConsequent(inst: Instruction): void; } export declare class Text extends BaseInstruction { constructor(text: string); } export declare class VariableInst extends BaseInstruction { constructor(variables: Reference[], formatters: FormatterCall[]); }