parser: don't skip tokens on groupings
This commit is contained in:
parent
830693d16d
commit
1651a99faf
1 changed files with 8 additions and 2 deletions
|
@ -91,10 +91,12 @@ pub const Parser = struct {
|
|||
}
|
||||
|
||||
fn consumeSingle(self: *Parser, ttype: TokenType) !Token {
|
||||
std.debug.warn("consume {}..?", ttype);
|
||||
|
||||
if (self.check(ttype)) {
|
||||
var cur = self.peek();
|
||||
_ = try self.nextToken();
|
||||
std.debug.warn("consumed {}, now has {}\n", ttype, self.peek());
|
||||
std.debug.warn(" now has {}\n", self.peek());
|
||||
return cur;
|
||||
}
|
||||
|
||||
|
@ -379,6 +381,7 @@ pub const Parser = struct {
|
|||
_ = try self.consumeSingle(.LeftBrace);
|
||||
|
||||
while (self.peek().ttype != .RightBrace) {
|
||||
std.debug.warn("get smt with cur {}\n", self.peek().ttype);
|
||||
var node = try self.parseStmt();
|
||||
ast.printNode(node, 0);
|
||||
try stmts.append(node.Stmt);
|
||||
|
@ -509,7 +512,10 @@ pub const Parser = struct {
|
|||
_ = try self.nextToken();
|
||||
var expr = (try self.parseExpr()).Expr;
|
||||
_ = try self.consume(.RightParen, "Expected ')' after expression");
|
||||
break :blk try self.mkGrouping(expr);
|
||||
|
||||
// for groupings, we don't want to skip tokens as we already
|
||||
// consumed RightParen.
|
||||
return try self.mkGrouping(expr);
|
||||
},
|
||||
|
||||
else => blk: {
|
||||
|
|
Loading…
Reference in a new issue