diff --git a/debug-edge-parsing.js b/debug-edge-parsing.js new file mode 100644 index 000000000..88799100e --- /dev/null +++ b/debug-edge-parsing.js @@ -0,0 +1,31 @@ +import { FlowDB } from './packages/mermaid/src/diagrams/flowchart/flowDb.ts'; +import flow from './packages/mermaid/src/diagrams/flowchart/parser/flowParserAdapter.ts'; + +// Set up the test environment +flow.yy = new FlowDB(); +flow.yy.clear(); + +console.log('=== Testing basic edge parsing ==='); +console.log('Input: "graph TD;A-->B;"'); + +try { + const result = flow.parse('graph TD;A-->B;'); + console.log('Parse result:', result); + + const vertices = flow.yy.getVertices(); + const edges = flow.yy.getEdges(); + + console.log('Vertices:', vertices); + console.log('Vertices size:', vertices.size); + console.log('Vertices keys:', Array.from(vertices.keys())); + + console.log('Edges:', edges); + console.log('Edges length:', edges.length); + + // Check specific vertices + console.log('Vertex A:', vertices.get('A')); + console.log('Vertex B:', vertices.get('B')); +} catch (error) { + console.error('Parse error:', error); + console.error('Error stack:', error.stack); +} diff --git a/packages/mermaid/src/diagrams/flowchart/parser/flowLexer.ts b/packages/mermaid/src/diagrams/flowchart/parser/flowLexer.ts index 491d34f16..561f532a3 100644 --- a/packages/mermaid/src/diagrams/flowchart/parser/flowLexer.ts +++ b/packages/mermaid/src/diagrams/flowchart/parser/flowLexer.ts @@ -59,8 +59,7 @@ const EOF = createToken({ // Complex pattern to handle all edge cases including punctuation at start/end const NODE_STRING = createToken({ name: 'NODE_STRING', - pattern: - /\\\w+|\w+\\|&[\w!"#$%&'*+,./:?\\`]+[\w!"#$%&'*+,./:?\\`-]*|-[\w!"#$%&'*+,./:?\\`]+[\w!"#$%&'*+,./:?\\`-]*|[<>^v][\w!"#$%&'*+,./:?\\`]+[\w!"#$%&'*+,./:?\\`-]*|:[\w!"#$%&'*+,./:?\\`]+[\w!"#$%&'*+,./:?\\`-]*|,[\w!"#$%&'*+,./:?\\`]+[\w!"#$%&'*+,./:?\\`-]*|[\w!"#$%&'*+,./:?\\`](?:[\w!"#$%&'*+,./:?\\`]|-(?![.=-])|\.(?!-))*[\w!"#$%&'*+,./:?\\`-]|[\w!"#$%&'*+,./:?\\`]|&|-|\\|\//, + pattern: /[A-Za-z0-9_]+/, }); // ============================================================================ @@ -207,42 +206,36 @@ const ShapeDataStart = createToken({ const LINK = createToken({ name: 'LINK', pattern: /[ox-]/, - longer_alt: NODE_STRING, }); const START_LINK = createToken({ name: 'START_LINK', pattern: /[ox-]?/, - longer_alt: NODE_STRING, }); const START_THICK_LINK = createToken({ name: 'START_THICK_LINK', pattern: /[ox-]?/, - longer_alt: NODE_STRING, }); const START_DOTTED_LINK = createToken({ name: 'START_DOTTED_LINK', pattern: /["'); + +try { + const result = flow.parse('-->'); + console.log('Parse result:', result); +} catch (error) { + console.error('Parse error:', error.message); +} diff --git a/test-lexer.mjs b/test-lexer.mjs new file mode 100644 index 000000000..6279be6b0 --- /dev/null +++ b/test-lexer.mjs @@ -0,0 +1,21 @@ +// Test the actual lexer to see what tokens are generated +import { FlowchartLexer } from './packages/mermaid/src/diagrams/flowchart/parser/flowLexer.ts'; + +const testInputs = ['A', 'A-->B', 'graph TD;A-->B;', '-->', 'A-', '>B']; + +console.log('Testing actual lexer:'); +testInputs.forEach((input) => { + console.log(`\nInput: "${input}"`); + try { + const result = FlowchartLexer.tokenize(input); + if (result.errors.length > 0) { + console.log('Errors:', result.errors); + } + console.log( + 'Tokens:', + result.tokens.map((t) => [t.image, t.tokenType.name]) + ); + } catch (error) { + console.log('Error:', error.message); + } +});