diff options
| author | Josh Wolfe <thejoshwolfe@gmail.com> | 2015-11-30 22:12:21 -0700 |
|---|---|---|
| committer | Josh Wolfe <thejoshwolfe@gmail.com> | 2015-11-30 22:12:21 -0700 |
| commit | 00f4c05784c05552e1e379b98c09161c936cfb31 (patch) | |
| tree | 5b2234cae585c5ac3a2cb23503908b0a6e2a27e3 /src/parser.cpp | |
| parent | abbc3957019c3a12dacd54869ff18b91c3f07699 (diff) | |
| parent | 55b8472374eede496b59396dbe253b05b16063e1 (diff) | |
| download | zig-00f4c05784c05552e1e379b98c09161c936cfb31.tar.gz zig-00f4c05784c05552e1e379b98c09161c936cfb31.zip | |
merge conflicts
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 10f43d26d4..613c559235 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -100,6 +100,8 @@ const char *node_type_str(NodeType node_type) { return "Symbol"; case NodeTypePrefixOpExpr: return "PrefixOpExpr"; + case NodeTypeUse: + return "Use"; } zig_unreachable(); } @@ -241,6 +243,9 @@ void ast_print(AstNode *node, int indent) { fprintf(stderr, "PrimaryExpr Symbol %s\n", buf_ptr(&node->data.symbol)); break; + case NodeTypeUse: + fprintf(stderr, "%s '%s'\n", node_type_str(node->type), buf_ptr(&node->data.use.path)); + break; } } @@ -1231,7 +1236,36 @@ static AstNode *ast_parse_root_export_decl(ParseContext *pc, int *token_index, b } /* -TopLevelDecl : FnDef | ExternBlock | RootExportDecl +Use : many(Directive) token(Use) token(String) token(Semicolon) +*/ +static AstNode *ast_parse_use(ParseContext *pc, int *token_index, bool mandatory) { + assert(mandatory == false); + + Token *use_kw = &pc->tokens->at(*token_index); + if (use_kw->id != TokenIdKeywordUse) + return nullptr; + *token_index += 1; + + Token *use_name = &pc->tokens->at(*token_index); + *token_index += 1; + ast_expect_token(pc, use_name, TokenIdStringLiteral); + + Token *semicolon = &pc->tokens->at(*token_index); + *token_index += 1; + ast_expect_token(pc, semicolon, TokenIdSemicolon); + + AstNode *node = ast_create_node(NodeTypeUse, use_kw); + + parse_string_literal(pc, use_name, &node->data.use.path); + + node->data.use.directives = pc->directive_list; + pc->directive_list = nullptr; + + return node; +} + +/* +TopLevelDecl : FnDef | ExternBlock | RootExportDecl | Use */ static void ast_parse_top_level_decls(ParseContext *pc, int *token_index, ZigList<AstNode *> *top_level_decls) { for (;;) { @@ -1258,6 +1292,12 @@ static void ast_parse_top_level_decls(ParseContext *pc, int *token_index, ZigLis continue; } + AstNode *use_node = ast_parse_use(pc, token_index, false); + if (use_node) { + top_level_decls->append(use_node); + continue; + } + if (pc->directive_list->length > 0) { ast_error(directive_token, "invalid directive"); } |
