parser: split into finishAssignment

This commit is contained in:
Luna 2019-08-26 15:19:31 -03:00
parent c3f0b4b4d5
commit 9e32ff9e16

View file

@ -533,7 +533,7 @@ pub const Parser = struct {
var expr: ?*Expr = null;
var body: ast.Block = undefined;
// infinite loop
// 'loop {' = infinite loop
if (self.check(.LeftBrace)) {
body = try self.parseStmtBlock();
} else {
@ -570,7 +570,7 @@ pub const Parser = struct {
}
fn parseAssignment(self: *@This()) anyerror!*Expr {
// there can be two types coming out of this function:
// there can be two assignments coming out of this function:
// - a mutable/immutable variable declaration with :=
// - an assignment to a variable with =
@ -578,24 +578,24 @@ pub const Parser = struct {
// of this is an Expr, we wrap variable assignments in an Expr as well.
var mutable: bool = false;
std.debug.warn("start assignment pass with cur={}\n", self.peek());
if (self.check(.Mut)) {
_ = try self.consumeSingle(.Mut);
mutable = true;
}
var expr = try self.parseOr();
std.debug.warn("lvalue: {}, cur: {}\n", expr, self.peek());
var value: *Expr = undefined;
var op: Token = undefined;
if (self.check(.ColonEqual) or self.check(.Equal)) {
op = self.peek();
return try self.finishAssignment(expr, mutable);
}
return expr;
}
fn finishAssignment(self: *@This(), expr: *Expr, mutable: bool) !*Expr {
var op = self.peek();
_ = try self.nextToken();
value = try self.parseAssignment();
var value = try self.parseAssignment();
switch (expr.*) {
.Variable => {
@ -622,9 +622,6 @@ pub const Parser = struct {
}
}
return expr;
}
fn parseOr(self: *@This()) !*Expr {
var expr = try self.parseAnd();