diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-12-18 17:24:52 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-12-18 17:24:52 -0500 |
| commit | 37b13bf1512d8eed7308a2194c1935d91a33796c (patch) | |
| tree | 42b6d1d4b6ddd16c7f69c4bdd15677a720609cf3 /src/parser.cpp | |
| parent | e50ced44a2cf6268c19df901ad56b367d8d802fe (diff) | |
| download | zig-37b13bf1512d8eed7308a2194c1935d91a33796c.tar.gz zig-37b13bf1512d8eed7308a2194c1935d91a33796c.zip | |
hello.zig working with all structs anonymous
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 0ee984d7fa..54994034f9 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -684,11 +684,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo AstNode *node = ast_create_node(pc, NodeTypeErrorType, token); *token_index += 1; return node; - } else if (token->id == TokenIdKeywordExtern) { - *token_index += 1; - AstNode *node = ast_parse_fn_proto(pc, token_index, true, VisibModPrivate); - node->data.fn_proto.is_extern = true; - return node; } else if (token->id == TokenIdAtSign) { *token_index += 1; Token *name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); @@ -742,6 +737,13 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo if (container_decl) return container_decl; + if (token->id == TokenIdKeywordExtern) { + *token_index += 1; + AstNode *node = ast_parse_fn_proto(pc, token_index, true, VisibModPrivate); + node->data.fn_proto.is_extern = true; + return node; + } + if (!mandatory) return nullptr; @@ -2224,28 +2226,39 @@ static AstNode *ast_parse_use(ParseContext *pc, size_t *token_index, VisibMod vi } /* -ContainerDecl = ("struct" | "enum" | "union") "{" many(StructMember) "}" +ContainerDecl = option("extern") ("struct" | "enum" | "union") "{" many(StructMember) "}" StructMember = (StructField | FnDef | GlobalVarDecl) StructField = Symbol option(":" Expression) ",") */ static AstNode *ast_parse_container_decl(ParseContext *pc, size_t *token_index, bool mandatory) { Token *first_token = &pc->tokens->at(*token_index); + Token *container_kind_token; + + bool is_extern; + if (first_token->id == TokenIdKeywordExtern) { + container_kind_token = &pc->tokens->at(*token_index + 1); + is_extern = true; + } else { + container_kind_token = first_token; + is_extern = false; + } ContainerKind kind; - if (first_token->id == TokenIdKeywordStruct) { + if (container_kind_token->id == TokenIdKeywordStruct) { kind = ContainerKindStruct; - } else if (first_token->id == TokenIdKeywordEnum) { + } else if (container_kind_token->id == TokenIdKeywordEnum) { kind = ContainerKindEnum; - } else if (first_token->id == TokenIdKeywordUnion) { + } else if (container_kind_token->id == TokenIdKeywordUnion) { kind = ContainerKindUnion; } else if (mandatory) { - ast_invalid_token_error(pc, first_token); + ast_invalid_token_error(pc, container_kind_token); } else { return nullptr; } - *token_index += 1; + *token_index += is_extern ? 2 : 1; AstNode *node = ast_create_node(pc, NodeTypeContainerDecl, first_token); + node->data.container_decl.is_extern = is_extern; node->data.container_decl.kind = kind; ast_eat_token(pc, token_index, TokenIdLBrace); |
