/** * Shared parser for graph diagrams. Diagram modules configure it with their * element keywords and implicit-node rules; everything else (declarations, * containers, members, links, notes, hide/remove) is common. * @module diagrams/graph/parse */ import { GraphModel } from "../../model/graph.mjs"; import { braceDelta } from "../../syntax/reader.mjs"; export type GraphNode = import("../../model/graph.mjs").GraphNode; export type SourceLine = import("../../core/source.mjs").SourceLine; export type ElementKind = { shape: string; role: string; /** * Body `{…}` contains members instead of children. */ classLike?: boolean; /** * Always drawn as a container (package, namespace). */ container?: boolean; }; export type GraphParserConfig = { /** * Model kind. */ kind: string; /** * Declaration keywords (lower case). */ keywords: Map; /** * Map an undeclared endpoint token to a node. */ implicit?: (token: string) => { id: string; label: string; keyword: string; } | null; /** * Extra rules tried before the generic ones. */ rules?: import("../../syntax/reader.mjs").Rule[]; /** * Post-processing hook. */ finish?: (model: GraphModel, ctx: GraphContext) => void; }; export type GraphContext = { model: GraphModel; /** * Open containers (`null` for `together`). */ stack: (GraphNode | null)[]; config: GraphParserConfig; module: import("../../core/registry.mjs").ModuleContext; /** * Last declared node (for `note left:` etc.). */ last: GraphNode | null; lastEdge: import("../../model/graph.mjs").GraphEdge | null; noteSeq: number; }; /** Default spot letters and colours for class-like keywords. */ export declare const CLASS_SPOTS: Map; /** * Element keywords shared by component, deployment and use case diagrams. * @type {[string, ElementKind][]} */ export declare const DESCRIPTIVE_KEYWORDS: [string, ElementKind][]; export type Declaration = { keyword: string; id: string; label: string; stereotypes: string[]; colors: import("../../syntax/color.mjs").ColorSpec; link: string | null; opensBlock: boolean; opensDescription: boolean; /** * Inline `[description]` text. */ description: string; /** * Remaining text (class headers: generics, extends …). */ rest: string; }; /** * Parsed element declaration. * @typedef {object} Declaration * @property {string} keyword * @property {string} id * @property {string} label * @property {string[]} stereotypes * @property {import("../../syntax/color.mjs").ColorSpec} colors * @property {string | null} link * @property {boolean} opensBlock * @property {boolean} opensDescription * @property {string} description Inline `[description]` text. * @property {string} rest Remaining text (class headers: generics, extends …). */ /** * Strip endpoint decoration: quotes, `[ ]`, `( )`, `: :`, `()`. * @param {string} token * @returns {{ name: string, form: "plain" | "component" | "usecase" | "actor" | "interface" | "quoted" }} */ export declare function endpointForm(token: string): { name: string; form: "plain" | "component" | "usecase" | "actor" | "interface" | "quoted"; }; /** * Parse ` [as ]` with all PlantUML quoting forms. * @param {string} text * @returns {{ id: string, label: string, form: string } | null} */ export declare function parseNameAlias(text: string): { id: string; label: string; form: string; } | null; /** * Parse an element declaration line. * @param {string} line * @param {Map} keywords * @returns {Declaration | null} */ export declare function parseDeclaration(line: string, keywords: Map): Declaration | null; /** * Parse class body members. * @param {SourceLine[]} lines * @returns {import("../../model/graph.mjs").Compartment[]} */ export declare function parseMembers(lines: SourceLine[]): import("../../model/graph.mjs").Compartment[]; /** * @param {string} raw * @returns {import("../../model/graph.mjs").Member} */ export declare function parseMember(raw: string): import("../../model/graph.mjs").Member; /** * Build a parse function for a graph diagram. * @param {GraphParserConfig} config * @returns {(lines: SourceLine[], module: import("../../core/registry.mjs").ModuleContext) => GraphModel} */ export declare function createGraphParser(config: GraphParserConfig): (lines: SourceLine[], module: import("../../core/registry.mjs").ModuleContext) => GraphModel; /** * Declare (or update) a node from a declaration. * @param {GraphContext} ctx * @param {Declaration} decl * @param {ElementKind} kind * @returns {GraphNode} */ export declare function declare(ctx: GraphContext, decl: Declaration, kind: ElementKind): GraphNode; /** * Resolve an endpoint token to a node, creating it implicitly when needed. * @param {GraphContext} ctx * @param {string} token * @param {string} [keywordHint] * @returns {GraphNode} */ export declare function ensureNode(ctx: GraphContext, token: string, keywordHint?: string): GraphNode; /** Re-exported helper for modules writing custom brace handling. */ export { braceDelta };