authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-11-30 01:26:01-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2015-11-30 01:26:01-07:00
logac0c5a3707c4a79c27e60242e44231cc05964f0f
treec8d874ad7f8a88edd10002cd2a927138a22a8f88
parent9b477230e0142e46d1276873d739cd7bac8b4e86

minor parser refactoring


2 files changed, 18 insertions(+), 11 deletions(-)

README.md+3
...@@ -42,6 +42,9 @@ make...@@ -42,6 +42,9 @@ make
4242
43## Roadmap43## Roadmap
4444
45 * ability to specify version
46 * cli ability to override library export locations
47 * add test for building library
45 * variables and parameters48 * variables and parameters
46 * Export .so library49 * Export .so library
47 * Multiple files50 * Multiple files
src/parser.cpp+15-11
...@@ -1254,21 +1254,25 @@ static AstNode *ast_parse_root_export_decl(ParseContext *pc, int *token_index) {...@@ -1254,21 +1254,25 @@ static AstNode *ast_parse_root_export_decl(ParseContext *pc, int *token_index) {
1254/*1254/*
1255Root : RootExportDecl many(TopLevelDecl) token(EOF)1255Root : RootExportDecl many(TopLevelDecl) token(EOF)
1256 */1256 */
1257AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens) {1257static AstNode *ast_parse_root(ParseContext *pc, int *token_index) {
1258 ParseContext pc = {0};1258 AstNode *node = ast_create_node(NodeTypeRoot, &pc->tokens->at(*token_index));
1259 pc.buf = buf;
1260 pc.root = ast_create_node(NodeTypeRoot, &tokens->at(0));
1261 pc.tokens = tokens;
12621259
1263 int token_index = 0;1260 node->data.root.root_export_decl = ast_parse_root_export_decl(pc, token_index);
1264
1265 pc.root->data.root.root_export_decl = ast_parse_root_export_decl(&pc, &token_index);
12661261
1267 ast_parse_top_level_decls(&pc, &token_index, &pc.root->data.root.top_level_decls);1262 ast_parse_top_level_decls(pc, token_index, &node->data.root.top_level_decls);
12681263
1269 if (token_index != tokens->length - 1) {1264 if (*token_index != pc->tokens->length - 1) {
1270 ast_invalid_token_error(&pc, &tokens->at(token_index));1265 ast_invalid_token_error(pc, &pc->tokens->at(*token_index));
1271 }1266 }
12721267
1268 return node;
1269}
1270
1271AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens) {
1272 ParseContext pc = {0};
1273 pc.buf = buf;
1274 pc.tokens = tokens;
1275 int token_index = 0;
1276 pc.root = ast_parse_root(&pc, &token_index);
1273 return pc.root;1277 return pc.root;
1274}1278}