diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-05-07 17:00:58 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-05-07 17:00:58 -0700 |
| commit | 2ed72022ce56b06bb3e90ca9259065452e209eb9 (patch) | |
| tree | e583301a3d037577ee8aff73f5ad91177d72c98f /src/parser.cpp | |
| parent | 01c46eef3a7e4fd5a96f364541c539746ae1ea3b (diff) | |
| download | zig-2ed72022ce56b06bb3e90ca9259065452e209eb9.tar.gz zig-2ed72022ce56b06bb3e90ca9259065452e209eb9.zip | |
support generic data structures
See #22
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 5cba265ac0..bef763f500 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -762,9 +762,7 @@ static void ast_parse_param_decl_list(ParseContext *pc, int *token_index, { *is_var_args = false; - Token *l_paren = &pc->tokens->at(*token_index); - *token_index += 1; - ast_expect_token(pc, l_paren, TokenIdLParen); + ast_eat_token(pc, token_index, TokenIdLParen); Token *token = &pc->tokens->at(*token_index); if (token->id == TokenIdRParen) { @@ -2606,7 +2604,7 @@ static AstNode *ast_parse_use(ParseContext *pc, int *token_index, } /* -ContainerDecl = ("struct" | "enum" | "union") "Symbol" "{" many(StructMember) "}" +ContainerDecl = ("struct" | "enum" | "union") "Symbol" option(ParamDeclList) "{" many(StructMember) "}" StructMember: many(Directive) option(VisibleMod) (StructField | FnDef) StructField : "Symbol" option(":" Expression) ",") */ @@ -2636,7 +2634,16 @@ static AstNode *ast_parse_container_decl(ParseContext *pc, int *token_index, node->data.struct_decl.top_level_decl.visib_mod = visib_mod; node->data.struct_decl.top_level_decl.directives = directives; - ast_eat_token(pc, token_index, TokenIdLBrace); + Token *paren_or_brace = &pc->tokens->at(*token_index); + if (paren_or_brace->id == TokenIdLParen) { + ast_parse_param_decl_list(pc, token_index, &node->data.struct_decl.generic_params, + &node->data.struct_decl.generic_params_is_var_args); + ast_eat_token(pc, token_index, TokenIdLBrace); + } else if (paren_or_brace->id == TokenIdLBrace) { + *token_index += 1; + } else { + ast_invalid_token_error(pc, paren_or_brace); + } for (;;) { Token *directive_token = &pc->tokens->at(*token_index); |
