zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ac0c5a3707c4a79c27e60242e44231cc05964f0f (tree)
parent 9b477230e0142e46d1276873d739cd7bac8b4e86
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Mon, 30 Nov 2015 01:26:01 -0700

minor parser refactoring

Diffstat:
MREADME.md | 3+++
Msrc/parser.cpp | 26+++++++++++++++-----------
2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/README.md b/README.md @@ -42,6 +42,9 @@ make ## Roadmap + * ability to specify version + * cli ability to override library export locations + * add test for building library * variables and parameters * Export .so library * Multiple files diff --git a/src/parser.cpp b/src/parser.cpp @@ -1254,21 +1254,25 @@ static AstNode *ast_parse_root_export_decl(ParseContext *pc, int *token_index) { /* Root : RootExportDecl many(TopLevelDecl) token(EOF) */ -AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens) { - ParseContext pc = {0}; - pc.buf = buf; - pc.root = ast_create_node(NodeTypeRoot, &tokens->at(0)); - pc.tokens = tokens; +static AstNode *ast_parse_root(ParseContext *pc, int *token_index) { + AstNode *node = ast_create_node(NodeTypeRoot, &pc->tokens->at(*token_index)); - int token_index = 0; - - pc.root->data.root.root_export_decl = ast_parse_root_export_decl(&pc, &token_index); + node->data.root.root_export_decl = ast_parse_root_export_decl(pc, token_index); - ast_parse_top_level_decls(&pc, &token_index, &pc.root->data.root.top_level_decls); + ast_parse_top_level_decls(pc, token_index, &node->data.root.top_level_decls); - if (token_index != tokens->length - 1) { - ast_invalid_token_error(&pc, &tokens->at(token_index)); + if (*token_index != pc->tokens->length - 1) { + ast_invalid_token_error(pc, &pc->tokens->at(*token_index)); } + return node; +} + +AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens) { + ParseContext pc = {0}; + pc.buf = buf; + pc.tokens = tokens; + int token_index = 0; + pc.root = ast_parse_root(&pc, &token_index); return pc.root; }