add group balance checker

This commit is contained in:
Ean Milligan 2025-07-01 02:18:38 -04:00
parent 139ef44556
commit abe49d49c2
1 changed files with 2 additions and 0 deletions

View File

@ -53,10 +53,12 @@ const checkBalance = (conf: MathConf[], openStr: string, closeStr: string, error
};
// assertXBalance verifies the entire conf has balanced X
export const assertGroupBalance = (conf: MathConf[]) => checkBalance(conf, '{', '}', 'Group', false, 0);
export const assertParenBalance = (conf: MathConf[]) => checkBalance(conf, '(', ')', 'Paren', false, 0);
export const assertPrePostBalance = (conf: MathConf[]) => checkBalance(conf, config.prefix, config.postfix, 'PrefixPostfix', false, 0);
// getMatchingXIdx gets the matching X, also partially verifies the conf has balanced X
export const getMatchingGroupId = (conf: MathConf[], openIdx: number): number => checkBalance(conf, '{', '}', 'Group', true, openIdx);
export const getMatchingInternalId = (conf: MathConf[], openIdx: number): number => checkBalance(conf, openInternal, closeInternal, 'Internal', true, openIdx);
export const getMatchingParenId = (conf: MathConf[], openIdx: number): number => checkBalance(conf, '(', ')', 'Paren', true, openIdx);
export const getMatchingPostfixId = (conf: MathConf[], openIdx: number): number => checkBalance(conf, config.prefix, config.postfix, 'PrefixPostfix', true, openIdx);