fix for latest zig
This commit is contained in:
parent
ff5a532c58
commit
fa47bd7a7e
4 changed files with 11 additions and 12 deletions
|
@ -14,9 +14,9 @@ fn parenthesize(name: []const u8, exprs: []*ast.Expr) void {
|
||||||
|
|
||||||
pub fn printAst(ast_expr: *ast.Expr) void {
|
pub fn printAst(ast_expr: *ast.Expr) void {
|
||||||
switch (ast_expr.*) {
|
switch (ast_expr.*) {
|
||||||
.Binary => |expr| parenthesize(expr.operator.lexeme, &[]*ast.Expr{ expr.left, expr.right }),
|
.Binary => |expr| parenthesize(expr.operator.lexeme, &[_]*ast.Expr{ expr.left, expr.right }),
|
||||||
.Grouping => |expr| parenthesize("group", &[]*ast.Expr{expr.expression}),
|
.Grouping => |expr| parenthesize("group", &[_]*ast.Expr{expr.expression}),
|
||||||
.Unary => |expr| parenthesize(expr.operator.lexeme, &[]*ast.Expr{expr.right}),
|
.Unary => |expr| parenthesize(expr.operator.lexeme, &[_]*ast.Expr{expr.right}),
|
||||||
.Number => |ast_num| {
|
.Number => |ast_num| {
|
||||||
switch (ast_num) {
|
switch (ast_num) {
|
||||||
.Integer32 => |num| std.debug.warn("{}", num),
|
.Integer32 => |num| std.debug.warn("{}", num),
|
||||||
|
|
|
@ -67,8 +67,7 @@ fn runPrompt(allocator: *Allocator) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() anyerror!void {
|
pub fn main() anyerror!void {
|
||||||
var da = std.heap.DirectAllocator.init();
|
var arena = std.heap.ArenaAllocator.init(std.heap.direct_allocator);
|
||||||
var arena = std.heap.ArenaAllocator.init(&da.allocator);
|
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
var allocator = &arena.allocator;
|
var allocator = &arena.allocator;
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ pub const Parser = struct {
|
||||||
fn equality(self: *Parser) !Expr {
|
fn equality(self: *Parser) !Expr {
|
||||||
var expr = try self.comparison();
|
var expr = try self.comparison();
|
||||||
|
|
||||||
while (self.match(&[]TokenType{ TokenType.BangEqual, TokenType.EqualEqual })) {
|
while (self.match(&[_]TokenType{ TokenType.BangEqual, TokenType.EqualEqual })) {
|
||||||
var operator = self.previous();
|
var operator = self.previous();
|
||||||
var right = try self.comparison();
|
var right = try self.comparison();
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ pub const Parser = struct {
|
||||||
fn comparison(self: *Parser) !Expr {
|
fn comparison(self: *Parser) !Expr {
|
||||||
var expr = try self.addition();
|
var expr = try self.addition();
|
||||||
|
|
||||||
while (self.match(&[]TokenType{
|
while (self.match(&[_]TokenType{
|
||||||
TokenType.Greater,
|
TokenType.Greater,
|
||||||
TokenType.GreaterEqual,
|
TokenType.GreaterEqual,
|
||||||
TokenType.Less,
|
TokenType.Less,
|
||||||
|
@ -138,7 +138,7 @@ pub const Parser = struct {
|
||||||
fn addition(self: *Parser) !Expr {
|
fn addition(self: *Parser) !Expr {
|
||||||
var expr = try self.multiplication();
|
var expr = try self.multiplication();
|
||||||
|
|
||||||
while (self.match(&[]TokenType{ TokenType.Minus, TokenType.Plus })) {
|
while (self.match(&[_]TokenType{ TokenType.Minus, TokenType.Plus })) {
|
||||||
var operator = self.previous();
|
var operator = self.previous();
|
||||||
var right = try self.multiplication();
|
var right = try self.multiplication();
|
||||||
expr = ast.mkBinary(&expr, operator, &right);
|
expr = ast.mkBinary(&expr, operator, &right);
|
||||||
|
@ -150,7 +150,7 @@ pub const Parser = struct {
|
||||||
fn multiplication(self: *Parser) anyerror!Expr {
|
fn multiplication(self: *Parser) anyerror!Expr {
|
||||||
var expr = try self.unary();
|
var expr = try self.unary();
|
||||||
|
|
||||||
while (self.match(&[]TokenType{ TokenType.Slash, TokenType.Star })) {
|
while (self.match(&[_]TokenType{ TokenType.Slash, TokenType.Star })) {
|
||||||
var operator = self.previous();
|
var operator = self.previous();
|
||||||
var right = try self.unary();
|
var right = try self.unary();
|
||||||
expr = ast.mkBinary(&expr, operator, &right);
|
expr = ast.mkBinary(&expr, operator, &right);
|
||||||
|
@ -160,7 +160,7 @@ pub const Parser = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unary(self: *Parser) anyerror!Expr {
|
fn unary(self: *Parser) anyerror!Expr {
|
||||||
if (self.match(&[]TokenType{ TokenType.Bang, TokenType.Minus })) {
|
if (self.match(&[_]TokenType{ TokenType.Bang, TokenType.Minus })) {
|
||||||
var operator = self.previous();
|
var operator = self.previous();
|
||||||
var right = try self.unary();
|
var right = try self.unary();
|
||||||
return ast.mkUnary(operator, &right);
|
return ast.mkUnary(operator, &right);
|
||||||
|
|
|
@ -24,7 +24,7 @@ fn isAlphaNumeric(char: u8) bool {
|
||||||
return isAlpha(char) or isDigit(char);
|
return isAlpha(char) or isDigit(char);
|
||||||
}
|
}
|
||||||
|
|
||||||
const keywords = [][]const u8{
|
const keywords = [_][]const u8{
|
||||||
"break",
|
"break",
|
||||||
"const",
|
"const",
|
||||||
"continue",
|
"continue",
|
||||||
|
@ -51,7 +51,7 @@ const keywords = [][]const u8{
|
||||||
"None",
|
"None",
|
||||||
};
|
};
|
||||||
|
|
||||||
const keyword_ttypes = []TokenType{
|
const keyword_ttypes = [_]TokenType{
|
||||||
.Break,
|
.Break,
|
||||||
.Const,
|
.Const,
|
||||||
.Continue,
|
.Continue,
|
||||||
|
|
Loading…
Reference in a new issue