UNPKG

@player-ui/player

Version:

67 lines 2.34 kB
export interface Node<T extends string> { /** The basic node type */ name: T; } /** * An AST node that represents a nested path in the model * foo.{{bar}}.baz (this is {{bar}}) */ export interface PathNode extends Node<"PathNode"> { /** The path in the model that this node represents */ path: Array<AnyNode>; } /** * A segment representing a query * [foo=bar] */ export interface QueryNode extends Node<"Query"> { /** The key to query */ key: AnyNode; /** The target value */ value?: AnyNode; } /** A simple segment */ export interface ValueNode extends Node<"Value"> { /** The segment value */ value: string | number; } /** A nested expression */ export interface ExpressionNode extends Node<"Expression"> { /** The expression */ value: string; } /** Helper to create a value node */ export declare const toValue: (value: string | number) => ValueNode; /** Helper to create an expression node */ export declare const toExpression: (value: string) => ExpressionNode; /** Helper to create a nested path node */ export declare const toPath: (path: Array<AnyNode>) => PathNode; /** Helper to create a query node */ export declare const toQuery: (key: AnyNode, value?: AnyNode) => QueryNode; /** Create a concat node */ export declare const toConcatenatedNode: (values: Array<PathNode | ValueNode | ExpressionNode>) => PathNode | ValueNode | ConcatenatedNode | ExpressionNode; /** * A binding segment that's multiple smaller ones * {{foo}}_bar_{{baz}} */ export interface ConcatenatedNode extends Node<"Concatenated"> { /** A list of nested paths, or value nodes to concat together to form a segment */ value: Array<PathNode | ValueNode | ExpressionNode>; } export type AnyNode = PathNode | QueryNode | ValueNode | ConcatenatedNode | ExpressionNode; export type Path = Array<AnyNode>; export interface ParserSuccessResult { /** A successful parse result */ status: true; /** The path the binding represents */ path: PathNode; } export interface ParserFailureResult { /** A failed parse result */ status: false; /** The message representing the reason the parse result failed */ error: string; } export type ParserResult = ParserSuccessResult | ParserFailureResult; export type Parser = (raw: string) => ParserResult; //# sourceMappingURL=ast.d.ts.map