remove pub syntax for container fields

This commit is contained in:
Vexu 2019-10-21 22:22:08 +03:00 committed by Andrew Kelley
parent 859cbef8a4
commit 2550cb4638
12 changed files with 54 additions and 66 deletions

View File

@ -10086,8 +10086,8 @@ ContainerMembers
<- TestDecl ContainerMembers
/ TopLevelComptime ContainerMembers
/ KEYWORD_pub? TopLevelDecl ContainerMembers
/ KEYWORD_pub? ContainerField COMMA ContainerMembers
/ KEYWORD_pub? ContainerField
/ ContainerField COMMA ContainerMembers
/ ContainerField
/
TestDecl <- KEYWORD_test STRINGLITERAL Block

View File

@ -17,35 +17,35 @@ const TailQueue = std.TailQueue;
const maxInt = std.math.maxInt;
pub const ChildProcess = struct {
pub pid: if (os.windows.is_the_target) void else i32,
pub handle: if (os.windows.is_the_target) windows.HANDLE else void,
pub thread_handle: if (os.windows.is_the_target) windows.HANDLE else void,
pid: if (os.windows.is_the_target) void else i32,
handle: if (os.windows.is_the_target) windows.HANDLE else void,
thread_handle: if (os.windows.is_the_target) windows.HANDLE else void,
pub allocator: *mem.Allocator,
allocator: *mem.Allocator,
pub stdin: ?File,
pub stdout: ?File,
pub stderr: ?File,
stdin: ?File,
stdout: ?File,
stderr: ?File,
pub term: ?(SpawnError!Term),
term: ?(SpawnError!Term),
pub argv: []const []const u8,
argv: []const []const u8,
/// Leave as null to use the current env map using the supplied allocator.
pub env_map: ?*const BufMap,
env_map: ?*const BufMap,
pub stdin_behavior: StdIo,
pub stdout_behavior: StdIo,
pub stderr_behavior: StdIo,
stdin_behavior: StdIo,
stdout_behavior: StdIo,
stderr_behavior: StdIo,
/// Set to change the user id when spawning the child process.
pub uid: if (os.windows.is_the_target) void else ?u32,
uid: if (os.windows.is_the_target) void else ?u32,
/// Set to change the group id when spawning the child process.
pub gid: if (os.windows.is_the_target) void else ?u32,
gid: if (os.windows.is_the_target) void else ?u32,
/// Set to change the current working directory when spawning the child process.
pub cwd: ?[]const u8,
cwd: ?[]const u8,
err_pipe: if (os.windows.is_the_target) void else [2]os.fd_t,
llnode: if (os.windows.is_the_target) void else TailQueue(*ChildProcess).Node,

View File

@ -338,7 +338,7 @@ pub const HeapAllocator = switch (builtin.os) {
/// This allocator takes an existing allocator, wraps it, and provides an interface
/// where you can allocate without freeing, and then free it all together.
pub const ArenaAllocator = struct {
pub allocator: Allocator,
allocator: Allocator,
child_allocator: *Allocator,
buffer_list: std.SinglyLinkedList([]u8),

View File

@ -28,9 +28,9 @@ fn never_index_default(name: []const u8) bool {
const HeaderEntry = struct {
allocator: *Allocator,
pub name: []const u8,
pub value: []u8,
pub never_index: bool,
name: []const u8,
value: []u8,
never_index: bool,
const Self = @This();

View File

@ -161,7 +161,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
const Self = @This();
const Stream = InStream(Error);
pub stream: Stream,
stream: Stream,
unbuffered_in_stream: *Stream,
@ -273,7 +273,7 @@ pub fn PeekStream(comptime buffer_size: usize, comptime InStreamError: type) typ
pub const Error = InStreamError;
pub const Stream = InStream(Error);
pub stream: Stream,
stream: Stream,
base: *Stream,
// Right now the look-ahead space is statically allocated, but a version with dynamic allocation
@ -336,7 +336,7 @@ pub const SliceInStream = struct {
pub const Error = error{};
pub const Stream = InStream(Error);
pub stream: Stream,
stream: Stream,
pos: usize,
slice: []const u8,
@ -514,9 +514,9 @@ pub const SliceOutStream = struct {
pub const Error = error{OutOfSpace};
pub const Stream = OutStream(Error);
pub stream: Stream,
stream: Stream,
pub pos: usize,
pos: usize,
slice: []u8,
pub fn init(slice: []u8) SliceOutStream {
@ -571,7 +571,7 @@ pub const NullOutStream = struct {
pub const Error = error{};
pub const Stream = OutStream(Error);
pub stream: Stream,
stream: Stream,
pub fn init() NullOutStream {
return NullOutStream{
@ -595,8 +595,8 @@ pub fn CountingOutStream(comptime OutStreamError: type) type {
pub const Stream = OutStream(Error);
pub const Error = OutStreamError;
pub stream: Stream,
pub bytes_written: u64,
stream: Stream,
bytes_written: u64,
child_stream: *Stream,
pub fn init(child_stream: *Stream) Self {
@ -635,7 +635,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
pub const Stream = OutStream(Error);
pub const Error = OutStreamError;
pub stream: Stream,
stream: Stream,
unbuffered_out_stream: *Stream,
@ -1084,7 +1084,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing,
// safety. If it is bad, it will be caught anyway.
const TagInt = @TagType(TagType);
const tag = try self.deserializeInt(TagInt);
inline for (info.fields) |field_info| {
if (field_info.enum_field.?.value == tag) {
const name = field_info.name;

View File

@ -39,8 +39,8 @@ pub const SliceSeekableInStream = struct {
pub const Stream = InStream(Error);
pub const SeekableInStream = SeekableStream(SeekError, GetSeekPosError);
pub stream: Stream,
pub seekable_stream: SeekableInStream,
stream: Stream,
seekable_stream: SeekableInStream,
pos: usize,
slice: []const u8,

View File

@ -290,7 +290,7 @@ pub const Error = union(enum) {
pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{}'");
pub const ExpectedParamType = SimpleError("Expected parameter type");
pub const ExpectedPubItem = SimpleError("Pub must be followed by fn decl, var decl, or container member");
pub const ExpectedPubItem = SimpleError("Expected function or variable declaration after pub");
pub const UnattachedDocComment = SimpleError("Unattached documentation comment");
pub const ExtraAlignQualifier = SimpleError("Extra align qualifier");
pub const ExtraConstQualifier = SimpleError("Extra const qualifier");
@ -757,7 +757,6 @@ pub const Node = struct {
pub const ContainerField = struct {
base: Node,
doc_comments: ?*DocComment,
visib_token: ?TokenIndex,
name_token: TokenIndex,
type_expr: ?*Node,
value_expr: ?*Node,
@ -780,7 +779,6 @@ pub const Node = struct {
}
pub fn firstToken(self: *const ContainerField) TokenIndex {
if (self.visib_token) |visib_token| return visib_token;
return self.name_token;
}

View File

@ -138,9 +138,15 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
continue;
}
if (visib_token != null) {
try tree.errors.push(AstError{
.ExpectedPubItem = AstError.ExpectedPubItem{ .token = it.index },
});
return error.ParseError;
}
if (try parseContainerField(arena, it, tree)) |node| {
const field = node.cast(Node.ContainerField).?;
field.visib_token = visib_token;
field.doc_comments = doc_comments;
try list.push(node);
const comma = eatToken(it, .Comma) orelse break;
@ -149,13 +155,6 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No
continue;
}
// Dangling pub
if (visib_token != null) {
try tree.errors.push(AstError{
.ExpectedPubItem = AstError.ExpectedPubItem{ .token = it.index },
});
}
break;
}
@ -407,7 +406,6 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
node.* = Node.ContainerField{
.base = Node{ .id = .ContainerField },
.doc_comments = null,
.visib_token = null,
.name_token = name_token,
.type_expr = type_expr,
.value_expr = value_expr,

View File

@ -1766,7 +1766,7 @@ test "zig fmt: struct declaration" {
\\const S = struct {
\\ const Self = @This();
\\ f1: u8,
\\ pub f3: u8,
\\ f3: u8,
\\
\\ fn method(self: *Self) Self {
\\ return self.*;
@ -1777,14 +1777,14 @@ test "zig fmt: struct declaration" {
\\
\\const Ps = packed struct {
\\ a: u8,
\\ pub b: u8,
\\ b: u8,
\\
\\ c: u8,
\\};
\\
\\const Es = extern struct {
\\ a: u8,
\\ pub b: u8,
\\ b: u8,
\\
\\ c: u8,
\\};

View File

@ -254,10 +254,6 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i
try renderDocComments(tree, stream, field, indent, start_col);
if (field.visib_token) |visib_token| {
try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
}
if (field.type_expr == null and field.value_expr == null) {
return renderToken(tree, stream, field.name_token, indent, start_col, Space.Comma); // name,
} else if (field.type_expr != null and field.value_expr == null) {
@ -2206,8 +2202,8 @@ const FindByteOutStream = struct {
pub const Error = error{};
pub const Stream = std.io.OutStream(Error);
pub stream: Stream,
pub byte_found: bool,
stream: Stream,
byte_found: bool,
byte: u8,
pub fn init(byte: u8) Self {

View File

@ -990,8 +990,6 @@ struct AstNodeStructField {
// populated if the "align(A)" is present
AstNode *align_expr;
Buf doc_comments;
VisibMod visib_mod;
};
struct AstNodeStringLiteral {

View File

@ -518,8 +518,8 @@ static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) {
// <- TestDecl ContainerMembers
// / TopLevelComptime ContainerMembers
// / KEYWORD_pub? TopLevelDecl ContainerMembers
// / KEYWORD_pub? ContainerField COMMA ContainerMembers
// / KEYWORD_pub? ContainerField
// / ContainerField COMMA ContainerMembers
// / ContainerField
// /
static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
AstNodeContainerDecl res = {};
@ -548,10 +548,13 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
continue;
}
if (visib_token != nullptr) {
ast_error(pc, peek_token(pc), "expected function or variable declaration after pub");
}
AstNode *container_field = ast_parse_container_field(pc);
if (container_field != nullptr) {
assert(container_field->type == NodeTypeStructField);
container_field->data.struct_field.visib_mod = visib_mod;
container_field->data.struct_field.doc_comments = doc_comment_buf;
res.fields.append(container_field);
if (eat_token_if(pc, TokenIdComma) != nullptr) {
@ -561,12 +564,7 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) {
}
}
// We visib_token wasn't eaten, then we haven't consumed the first token in this rule yet.
// It is therefore safe to return and let the caller continue parsing.
if (visib_token == nullptr)
break;
ast_invalid_token_error(pc, peek_token(pc));
break;
}
return res;