diff --git a/src/__tests__/parser.spec.ts b/src/__tests__/parser.spec.ts index 1f0baa3..c5e7910 100644 --- a/src/__tests__/parser.spec.ts +++ b/src/__tests__/parser.spec.ts @@ -272,6 +272,20 @@ describe('Chord parser', () => { expect(cpsFactors[2].monzo.valueOf()).toBeCloseTo(5); expect(cpsFactors[3].monzo.valueOf()).toBeCloseTo(7); }); + + it('parses mixed comma-separated monzos with comma-separated components', () => { + const monzos = parseChord( + '[0, 0, 0>, [-2, 0, 1>,[-1, 1, 0>:[1 0 0>', + 3, + /,|:/ + ).map(interval => + interval.monzo.vector.map(component => component.valueOf()) + ); + expect(arraysEqual(monzos[0], [0, 0, 0])).toBeTruthy(); + expect(arraysEqual(monzos[1], [-2, 0, 1])).toBeTruthy(); + expect(arraysEqual(monzos[2], [-1, 1, 0])).toBeTruthy(); + expect(arraysEqual(monzos[3], [1, 0, 0])).toBeTruthy(); + }); }); describe('Scale parse', () => { diff --git a/src/parser.ts b/src/parser.ts index 19dfbaa..4995c6a 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -438,9 +438,13 @@ export function parseChord( separator: string | RegExp = ':', options?: IntervalOptions ) { + // Protect commas inside monzos + input = input.replace(/\[.*?>/g, match => match.replace(/,/g, '¤')); + const chord: Interval[] = []; input.split(separator).forEach(line => { - line = line.trim(); + // Restore commas + line = line.trim().replace(/¤/g, ','); if (!line.length) { return; }