remove some debug calls

This commit is contained in:
Luna 2019-08-26 15:29:59 -03:00
parent 9e32ff9e16
commit 9eaa71cbd6
2 changed files with 17 additions and 15 deletions

View file

@ -49,4 +49,6 @@ fn main(a int) int {
p.x = 69 p.x = 69
println(a.b(3).c(d)) println(a.b(3).c(d))
v()()()
} }

View file

@ -88,6 +88,8 @@ pub const Parser = struct {
return token; return token;
} }
/// Consume the current token type, then walk to the next token.
/// Returns the consumed token.
fn consume(self: *Parser, ttype: TokenType, comptime msg: []const u8) !Token { fn consume(self: *Parser, ttype: TokenType, comptime msg: []const u8) !Token {
if (self.check(ttype)) { if (self.check(ttype)) {
var tok = self.peek(); var tok = self.peek();
@ -99,16 +101,15 @@ pub const Parser = struct {
return Result.CompileError; return Result.CompileError;
} }
/// Consume the current token. Gives default error messages
fn consumeSingle(self: *Parser, ttype: TokenType) !Token { fn consumeSingle(self: *Parser, ttype: TokenType) !Token {
std.debug.warn("consume {}..?", ttype);
if (self.check(ttype)) { if (self.check(ttype)) {
var cur = self.peek(); var cur = self.peek();
_ = try self.nextToken(); _ = try self.nextToken();
std.debug.warn(" now has {}\n", self.peek());
return cur; return cur;
} }
// TODO maybe this could be entirely comptime?
var buf_main: [1000]u8 = undefined; var buf_main: [1000]u8 = undefined;
var buf = try std.fmt.bufPrint( var buf = try std.fmt.bufPrint(
buf_main[0..], buf_main[0..],
@ -116,11 +117,12 @@ pub const Parser = struct {
ttype, ttype,
self.peek().ttype, self.peek().ttype,
); );
try self.tokenError(self.peek(), buf);
try self.tokenError(self.peek(), buf);
return Result.CompileError; return Result.CompileError;
} }
/// check() against multiple tokens
fn compareAnyOf(self: *@This(), ttypes: []TokenType) bool { fn compareAnyOf(self: *@This(), ttypes: []TokenType) bool {
for (ttypes) |ttype| { for (ttypes) |ttype| {
if (self.check(ttype)) return true; if (self.check(ttype)) return true;
@ -727,18 +729,14 @@ pub const Parser = struct {
return expr; return expr;
} }
/// Parse either:
/// - A function call
/// - A struct initialization (Point.{...})
/// - A struct Get expression (p.x)
fn parseCall(self: *@This()) !*Expr { fn parseCall(self: *@This()) !*Expr {
// we parse a primary expression instead of consuming a .Identifier
// since parseCall is connected to the rest of the parser. doing
// identifiers would break the rest of the rules that want primaries.
// nothing stops us from ensuring expr is a Variable though ;)
var expr = try self.parsePrimary(); var expr = try self.parsePrimary();
while (true) { while (true) {
std.debug.warn("maybe fncall / struct: {}\n", self.peek().ttype);
printer.printExpr(expr);
if (self.check(.LeftParen)) { if (self.check(.LeftParen)) {
_ = try self.consumeSingle(.LeftParen); _ = try self.consumeSingle(.LeftParen);
expr = try self.finishCall(expr); expr = try self.finishCall(expr);
@ -749,7 +747,11 @@ pub const Parser = struct {
_ = try self.consumeSingle(.LeftBrace); _ = try self.consumeSingle(.LeftBrace);
expr = try self.finishStructVal(expr); expr = try self.finishStructVal(expr);
} else { } else {
var name = try self.consume(.Identifier, "Expect property name after '.'"); var name = try self.consume(
.Identifier,
"Expect property name after '.'",
);
expr = try self.mkGet(expr, name); expr = try self.mkGet(expr, name);
} }
} else { } else {
@ -778,7 +780,6 @@ pub const Parser = struct {
} }
} }
// TODO shouldnt consume() return the current token, not nextToken?
var paren = try self.consume(.RightParen, "Expected ')' after arguments"); var paren = try self.consume(.RightParen, "Expected ')' after arguments");
return self.mkCall(callee, paren, args); return self.mkCall(callee, paren, args);
@ -843,7 +844,6 @@ pub const Parser = struct {
}; };
_ = try self.nextToken(); _ = try self.nextToken();
return expr; return expr;
} }
}; };