From 528eb9c74dc29e8f86554852862cdea941dda7a5 Mon Sep 17 00:00:00 2001 From: Linus Lee Date: Thu, 24 Sep 2020 07:55:24 -0400 Subject: [PATCH] Add support for exprgroups guraded by parens --- static/js/lang.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/static/js/lang.js b/static/js/lang.js index fe6f25b..0782e64 100644 --- a/static/js/lang.js +++ b/static/js/lang.js @@ -414,6 +414,17 @@ class Parser { type: N.ExprGroup, exprs: exprs, }; + } else if (next === T.LParen) { + // block, but guarded by parens, for binary exprs + const exprs = []; + while (this.tokens.hasNext() && this.tokens.peek() !== T.RParen) { + exprs.push(this.expr()); + } + this.tokens.expect(T.RParen); + return { + type: N.ExprGroup, + exprs: exprs, + }; } throw new Error(`Parsing error: expected ident, literal, or block, got ${ @@ -471,7 +482,6 @@ class Parser { const atom = this.atom(); if (BINARY_OPS.includes(this.tokens.peek())) { // infix binary ops - // TODO: support operator precedence const left = atom; const op = this.tokens.next(); const right = this.atom();