fix: ANTLR parser class/style processing timing issue

- Fixed class assignment timing in exitStyledVertex method
- Class assignments (:::) now happen AFTER vertex creation instead of before
- Ensures vertices exist when setClass is called, preventing lost class assignments
- Improved test pass rate from 97.6% to 97.8% (926/947 tests passing)
- flow-style.spec.js now passes 100% (24/24 tests)
- flow-vertice-chaining.spec.js now passes 100% (7/7 tests)

Technical changes:
- Moved class assignment logic after addVertex call in exitStyledVertex
- All ::: syntax now works correctly: B:::C1, D:::C1, E:::C2
- Removed debug logging for clean production code
This commit is contained in:
Ashish Jain
2025-09-15 15:39:53 +02:00
parent bd401079f2
commit 9e7e9377c3

View File

@@ -117,22 +117,7 @@ class FlowchartListener implements ParseTreeListener {
return; // Skip if no valid node ID return; // Skip if no valid node ID
} }
// Check for class application pattern: vertex STYLE_SEPARATOR idString
const children = ctx.children; const children = ctx.children;
if (children && children.length >= 3) {
// Look for STYLE_SEPARATOR (:::) pattern
for (let i = 0; i < children.length - 1; i++) {
if (children[i].getText && children[i].getText() === ':::') {
// Found STYLE_SEPARATOR, next should be the class name
const className = children[i + 1].getText();
if (className) {
// Apply class to vertex: setClass(vertex, className)
this.db.setClass(nodeId, className);
break;
}
}
}
}
// Check if this node already exists in the database // Check if this node already exists in the database
// If it does, it means it was already processed by exitVertexStatement with shape data // If it does, it means it was already processed by exitVertexStatement with shape data
@@ -223,6 +208,22 @@ class FlowchartListener implements ParseTreeListener {
// Add vertex to database (no shape data for styled vertex) // Add vertex to database (no shape data for styled vertex)
this.db.addVertex(nodeId, textObj, nodeShape, [], [], '', {}, ''); this.db.addVertex(nodeId, textObj, nodeShape, [], [], '', {}, '');
// AFTER vertex creation, check for class application pattern: vertex STYLE_SEPARATOR idString
if (children && children.length >= 3) {
// Look for STYLE_SEPARATOR (:::) pattern
for (let i = 0; i < children.length - 1; i++) {
if (children[i].getText && children[i].getText() === ':::') {
// Found STYLE_SEPARATOR, next should be the class name
const className = children[i + 1].getText();
if (className) {
// Apply class to vertex: setClass(vertex, className)
this.db.setClass(nodeId, className);
break;
}
}
}
}
// Note: Subgraph node tracking is handled in edge processing methods // Note: Subgraph node tracking is handled in edge processing methods
// to match Jison parser behavior which collects nodes from statements // to match Jison parser behavior which collects nodes from statements
} catch (_error) { } catch (_error) {