Skip to content

Commit d231a85

Browse files
committed
Improve error message for extra parentheses
1 parent 1f7a5b4 commit d231a85

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

server/src/septic/algParser.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,21 @@ export class AlgParser extends Parser<AlgTokenType, AlgExpr> {
7070
parse(): AlgExpr {
7171
const expr = this.comparison();
7272
if (!this.isAtEnd()) {
73-
this.error("Calculation can only contain a single expression", {
74-
start: this.tokens[0].start,
75-
end: this.tokens[this.tokens.length - 1].end,
76-
type: AlgTokenType.error,
77-
content: "",
78-
});
73+
if (this.peek().type === AlgTokenType.rightParen) {
74+
this.error("Mismatch in opening and closing parentheses", {
75+
start: this.tokens[0].start,
76+
end: this.peek().end,
77+
type: AlgTokenType.error,
78+
content: "",
79+
});
80+
} else {
81+
this.error("Calculation can only contain a single expression", {
82+
start: this.tokens[0].start,
83+
end: this.tokens[this.tokens.length - 1].end,
84+
type: AlgTokenType.error,
85+
content: "",
86+
});
87+
}
7988
}
8089
return expr;
8190
}

0 commit comments

Comments
 (0)