UNPKG

simc-ast-builder

Version:

Parser and AST generator for SimulationCraft files

73 lines 2.64 kB
/** * Template for creating ExpressionNode instances * Provides a way to define reusable node structures */ import { ExpressionNode } from "../parser/visitors/ast/common-types"; /** * Options for creating a NodeTemplate */ export interface NodeTemplateOptions { /** * Base properties to include in all nodes created from this template */ baseProperties?: Partial<ExpressionNode>; /** * Validator function to ensure nodes created from this template are valid */ validator?: ((node: ExpressionNode) => boolean) | undefined; } /** * Template for creating ExpressionNode instances */ export declare class NodeTemplate { /** * Base properties to include in all nodes created from this template */ readonly baseProperties: Partial<ExpressionNode>; /** * Type of nodes created from this template */ readonly type: string; /** * Validator function to ensure nodes created from this template are valid */ readonly validator: ((node: ExpressionNode) => boolean) | undefined; /** * Create a new NodeTemplate * @param type Type of nodes created from this template * @param options Options for the template */ constructor(type: string, options?: NodeTemplateOptions); /** * Apply the template with values to create a node * @param values Values to override base properties * @returns A new ExpressionNode based on this template * @throws Error if the node is invalid */ apply(values?: Partial<ExpressionNode>): ExpressionNode; /** * Validate a node against this template * @param node Node to validate * @returns True if the node is valid for this template */ validate(node: ExpressionNode): boolean; /** * Create a new template with an additional validator * @param additionalValidator Additional validator function * @returns A new NodeTemplate with both validators */ withAdditionalValidator(additionalValidator: (node: ExpressionNode) => boolean): NodeTemplate; /** * Create a new template with additional base properties * @param properties Additional base properties * @returns A new NodeTemplate with the combined base properties */ withBaseProperties(properties: Partial<ExpressionNode>): NodeTemplate; /** * Create a new template with a different validator * @param validator New validator function * @returns A new NodeTemplate with the new validator */ withValidator(validator: (node: ExpressionNode) => boolean): NodeTemplate; } //# sourceMappingURL=NodeTemplate.d.ts.map