From 15ecb45e65764fcd8b78638f8104bb9e6ab4af22 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Tue, 29 Apr 2025 02:41:31 -0400 Subject: [PATCH] add additional paren balance check --- src/solver/parser.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/solver/parser.ts b/src/solver/parser.ts index d5a6fcf..2b2c761 100644 --- a/src/solver/parser.ts +++ b/src/solver/parser.ts @@ -68,6 +68,11 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll } else if (e === ')') { parenCnt--; } + + // If parenCnt ever goes below 0, that means too many closing paren appeared before opening parens + if (parenCnt < 0) { + throw new Error('UnbalancedParens'); + } }); // If the parenCnt is not 0, then we do not have balanced parens and need to error out now