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-- }

View File

@ -153,7 +153,7 @@ function Lisp (lib = {}, includes = []) {
}
const tokenize = function (input) {
const i = input.replace(/^\;.*\n?/gm, '').replace('λ','lambda ').split('"')
const i = input.replace(/^\;.*\n?/gm, '').replace('λ', 'lambda ').split('"')
return i.map(function (x, i) {
return i % 2 === 0
? x.replace(/\(/g, ' ( ')