Skip to content

Commit

Permalink
Add better list parser
Browse files Browse the repository at this point in the history
  • Loading branch information
pyldin601 committed Oct 27, 2017
1 parent 80d70a4 commit 6a6e732
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const toListInternal = (tokens: IToken[], depth = 0): any[] => {
const iterateList = optimizeTailCall(([head, ...tail]: IToken[], acc) => {
if (_.isNil(head)) {
if (depth > 0) {
throw new Error('0 non-closed parenthesis found');
throw new Error(`${depth} non-closed parenthesis found`);
}
return { acc, tail: [] };
}
Expand All @@ -166,7 +166,8 @@ const toListInternal = (tokens: IToken[], depth = 0): any[] => {
}
if (head === CLOSE_PARENTHESIS) {
if (depth === 0) {
throw new Error('0 superfluous open parenthesis found');
const supCloseCount = _.size(_.findWhere(tail, tok => tok === CLOSE_PARENTHESIS));
throw new Error(`${supCloseCount + 1} superfluous close parenthesis found`);
}
return { acc, tail };
}
Expand Down

0 comments on commit 6a6e732

Please sign in to comment.