diff --git a/packages/mermaid/src/diagrams/flowchart/parser/antlr/FlowLexer.g4 b/packages/mermaid/src/diagrams/flowchart/parser/antlr/FlowLexer.g4 index 563b8feba..5e1b01cdf 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/antlr/FlowLexer.g4 +++ b/packages/mermaid/src/diagrams/flowchart/parser/antlr/FlowLexer.g4 @@ -124,7 +124,8 @@ MINUS: '-'; // Node string - allow dashes with lookahead to prevent conflicts with links (matches Jison pattern) // Pattern: ([A-Za-z0-9!"\#$%&'*+\.`?\\_\/]|\-(?=[^\>\-\.])|=(?!=))+ -NODE_STRING: ([A-Za-z0-9!"#$%&'*+.`?\\/_] | '-' ~[>\-.] | '=' ~'=')+; +// Fixed: Use positive lookahead instead of consuming the following character +NODE_STRING: ([A-Za-z0-9!"#$%&'*+.`?\\/_] | '-' {this.inputStream.LA(1) != '>'.charCodeAt(0) && this.inputStream.LA(1) != '-'.charCodeAt(0) && this.inputStream.LA(1) != '.'.charCodeAt(0)}? | '=' ~'=')+; // Unicode text support (simplified from Jison's extensive Unicode ranges) UNICODE_TEXT: [\u00AA\u00B5\u00BA\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE]+; diff --git a/packages/mermaid/src/diagrams/flowchart/parser/antlr/antlr-parser.ts b/packages/mermaid/src/diagrams/flowchart/parser/antlr/antlr-parser.ts index bcf914da2..231106877 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/antlr/antlr-parser.ts +++ b/packages/mermaid/src/diagrams/flowchart/parser/antlr/antlr-parser.ts @@ -22,6 +22,7 @@ class FlowchartListener implements ParseTreeListener { nodes: (string | { stmt: string; value: string })[]; }[] = []; private currentArrowText: string = ''; + private currentLinkData: any = null; constructor(db: any) { this.db = db; @@ -603,7 +604,9 @@ class FlowchartListener implements ParseTreeListener { const vertex = styledVertex.vertex(); if (vertex) { const idCtx = vertex.idString(); - return idCtx ? idCtx.getText() : null; + const nodeId = idCtx ? idCtx.getText() : null; + + return nodeId; } } } @@ -1383,6 +1386,16 @@ class FlowchartListener implements ParseTreeListener { return false; } + // Handle link processing - this is the critical missing method + exitLink = (ctx: any) => { + try { + // Store link data for use in vertexStatement processing + this.currentLinkData = this.extractLinkData(ctx); + } catch (_error) { + // Error handling for link processing + } + }; + // Handle arrow text (pipe-delimited edge text) exitArrowText = (ctx: any) => { try {