Test for number of parens

This commit is contained in:
Devine Lu Linvega 2019-07-21 10:01:03 +09:00
parent 938a9d22ec
commit 3093a74d57
2 changed files with 5 additions and 1 deletions

View File

@ -46,6 +46,10 @@ function Commander (ronin) {
this.reindent = function () {
let val = this._input.value.replace(/\n/g, '').replace(/ +(?= )/g, '').replace(/\( \(/g, '((').replace(/\) \)/g, '))').trim()
let depth = 0
if (val.split('(').length !== val.split(')').length) {
ronin.log('Uneven number of parens.')
return
}
for (let i = 0; i < val.length; i++) {
const c = val.charAt(i)
if (c === '(') { depth++ } else if (c === ')') { depth-- }