
const lineRegex = /^\s*(?<name>[a-z-]+)\s+(?:\((?<emotion>[a-z-]+)\))?\s*"(?<text>(?:[^"\\]|\\.)*)"\s*$/;

export const parseMathuscript = (script: string) => {
	return script.split("\n").filter(Boolean).map(line => {
		const match = line.match(lineRegex);
		if (!match) {
			throw Error(`Bad Line: ${JSON.stringify(line)}`);
		}
		return match.groups as Mathuscript[number];
	}).filter(Boolean);
}

export type Mathuscript = {name: string, emotion: string | undefined, text: string}[];