modifications to generic parser

This commit is contained in:
Justin Greywolf
2023-08-25 13:08:51 -07:00
parent 8e64995047
commit 3678ad4e9d
2 changed files with 5 additions and 21 deletions

View File

@@ -15,6 +15,7 @@ import {
setDiagramTitle, setDiagramTitle,
getDiagramTitle, getDiagramTitle,
} from '../../commonDb.js'; } from '../../commonDb.js';
import { ClassMember } from './classTypes.js';
import type { import type {
ClassRelation, ClassRelation,
ClassNode, ClassNode,
@@ -22,7 +23,6 @@ import type {
ClassMap, ClassMap,
NamespaceMap, NamespaceMap,
NamespaceNode, NamespaceNode,
ClassMember,
} from './classTypes.js'; } from './classTypes.js';
const MERMAID_DOM_ID_PREFIX = 'classId-'; const MERMAID_DOM_ID_PREFIX = 'classId-';

View File

@@ -181,46 +181,31 @@ export const getMin = function (...values: number[]): number {
export const parseGenericTypes = function (input: string): string { export const parseGenericTypes = function (input: string): string {
const inputSets = input.split(/(,)/); const inputSets = input.split(/(,)/);
const output = []; const output = [];
let finalResult = '';
let skipNextSet = false;
for (let i = 0; i < inputSets.length; i++) { for (let i = 0; i < inputSets.length; i++) {
const previousIndex = i - 1;
const nextIndex = i + 1;
let thisSet = inputSets[i]; let thisSet = inputSets[i];
// based on logic below - if we have already combined this set with the previous, we want to skip it
if (skipNextSet) {
continue;
}
// if the original input included a value such as "~K, V~"", these will be split into // if the original input included a value such as "~K, V~"", these will be split into
// an array of ["~K",","," V~"]. // an array of ["~K",","," V~"].
// This means that on each call of processSet, there will only be 1 ~ present // This means that on each call of processSet, there will only be 1 ~ present
// To account for this, if we encounter a ",", we are checking the previous and next sets in the array // To account for this, if we encounter a ",", we are checking the previous and next sets in the array
// to see if they contain matching ~'s // to see if they contain matching ~'s
// in which case we are assuming that they should be rejoined and sent to be processed // in which case we are assuming that they should be rejoined and sent to be processed
// we are also removing if (thisSet === ',' && i > 0 && i + 1 < inputSets.length) {
if (thisSet === ',' && previousIndex > -1 && nextIndex <= inputSets.length) {
const previousSet = inputSets[i - 1]; const previousSet = inputSets[i - 1];
const nextSet = inputSets[i + 1]; const nextSet = inputSets[i + 1];
if (shouldCombineSets(previousSet, nextSet)) { if (shouldCombineSets(previousSet, nextSet)) {
thisSet = previousSet + ',' + nextSet; thisSet = previousSet + ',' + nextSet;
skipNextSet = true; i++; // Move the index forward to skip the next iteration since we're combining sets
// remove previous set
output.pop(); output.pop();
} }
} else {
skipNextSet = false;
} }
output.push(processSet(thisSet)); output.push(processSet(thisSet));
} }
finalResult = output.join(''); return output.join('');
// one last scan to see if any sets were missed
finalResult = processSet(finalResult);
return finalResult;
}; };
const shouldCombineSets = (previousSet: string, nextSet: string): boolean => { const shouldCombineSets = (previousSet: string, nextSet: string): boolean => {
@@ -234,7 +219,6 @@ const processSet = (input: string): string => {
const chars = [...input]; const chars = [...input];
const tildeCount = chars.reduce((count, char) => (char === '~' ? count + 1 : count), 0); const tildeCount = chars.reduce((count, char) => (char === '~' ? count + 1 : count), 0);
// ignoring any
if (tildeCount <= 1) { if (tildeCount <= 1) {
return input; return input;
} }