diff --git a/examples/hello.v b/examples/hello.v index 3d16d61..377d337 100644 --- a/examples/hello.v +++ b/examples/hello.v @@ -54,16 +54,3 @@ fn main(a int) int { } fn (v Typ) voidfunc() {} - -struct Foo { - a int -mut: - b int - c int -pub: - d int -pub mut: - e int -pub mut mut: - f int -} diff --git a/src/ast.zig b/src/ast.zig index baa49eb..91a045d 100644 --- a/src/ast.zig +++ b/src/ast.zig @@ -227,10 +227,8 @@ pub const FieldList = std.ArrayList(StructField); pub const StructField = struct { name: Token, typ: Token, - - mutable: bool = false, - public: bool = false, - mutable_outside: bool = false, + mutable: bool = true, + public: bool = true, }; pub const Struct = struct { diff --git a/src/ast_printer.zig b/src/ast_printer.zig index 25f90b4..3a0ed4f 100644 --- a/src/ast_printer.zig +++ b/src/ast_printer.zig @@ -107,10 +107,6 @@ pub fn printNode(node: *Node, ident: usize) void { std.debug.warn("pub "); } - if (field.mutable_outside) { - std.debug.warn("MUT_OUT "); - } - std.debug.warn("{} {})\n", field.name.lexeme, field.typ.lexeme); } print(ident, "))\n"); diff --git a/src/parser.zig b/src/parser.zig index 9c0d436..02e9d22 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -18,12 +18,6 @@ const Stmt = ast.Stmt; const TokenList = std.ArrayList(Token); -const FieldState = struct { - public: bool = false, - mutable: bool = false, - mutable_outside: bool = false, -}; - pub const Parser = struct { allocator: *Allocator, scanner: *Scanner, @@ -411,6 +405,8 @@ pub const Parser = struct { while (self.peek().ttype != .RightParen) { const param_name = try self.consumeSingle(.Identifier); + + // TODO dedicated function to consume a type? const param_type = try self.consumeSingle(.Identifier); try param_list.append(ast.ParamDecl{ @@ -499,25 +495,14 @@ pub const Parser = struct { _ = try self.consumeSingle(.LeftBrace); - var field_state = FieldState{}; - while (!self.check(.RightBrace)) { - try self.parseFieldModifiers(&field_state); - + // TODO mut and pub const field_name = try self.consumeSingle(.Identifier); const field_type = try self.consumeSingle(.Identifier); - // we could create a FieldState on the heap and copy our current - // field state into a StructField.state, but copying via this makes - // things so much nicer. - try fields.append(ast.StructField{ .name = field_name, .typ = field_type, - - .mutable = field_state.mutable, - .public = field_state.public, - .mutable_outside = field_state.mutable_outside, }); } @@ -526,51 +511,6 @@ pub const Parser = struct { return Node.mkStructDecl(self.allocator, name, fields); } - fn parseFieldModifiers(self: *@This(), field_state: *FieldState) !void { - - // there are five access modifiers: - // - none (private immutable) - // - mut (private mutable) - // - pub (public immutable) - // - pub mut (public mutable only in module) - // - pub mut mut (public mutable everywhere) - - // this function takes care of that by changing the current FieldState - // to what the modifiers dictate. - switch (self.peek().ttype) { - .Mut => { - // There are no oher modifiers that start with mut, so we - // can just go the way of marking it as mutable - _ = try self.consumeSingle(.Mut); - _ = try self.consumeSingle(.Colon); - - field_state.mutable = true; - }, - - // 'pub', 'pub mut', and 'pub mut mut' are all handled here - .Pub => { - _ = try self.consumeSingle(.Pub); - field_state.public = true; - - if (self.check(.Mut)) { - _ = try self.consumeSingle(.Mut); - - field_state.mutable = true; - if (self.check(.Mut)) { - _ = try self.consumeSingle(.Mut); - field_state.mutable_outside = true; - } - } - - _ = try self.consumeSingle(.Colon); - }, - - // if it isn't mut or pub we're likely in an identifier, just - // ignore it. - else => return, - } - } - fn parseTopDecl(self: *@This()) !*Node { return switch (self.peek().ttype) { .Fn => try self.parseFnDecl(), diff --git a/src/scanner.zig b/src/scanner.zig index 76a9c7e..2ee42d1 100644 --- a/src/scanner.zig +++ b/src/scanner.zig @@ -51,7 +51,6 @@ const keywords = [_][]const u8{ "None", "println", "loop", - "pub", }; const keyword_ttypes = [_]TokenType{ @@ -81,7 +80,6 @@ const keyword_ttypes = [_]TokenType{ .None, .Println, .Loop, - .Pub, }; fn getKeyword(keyword: []const u8) ?TokenType { diff --git a/src/tokens.zig b/src/tokens.zig index 1a79a13..360c6b6 100644 --- a/src/tokens.zig +++ b/src/tokens.zig @@ -75,7 +75,6 @@ pub const TokenType = enum { None, Println, - Pub, EOF, };