minor parser refactoring

This commit is contained in:
Andrew Kelley 2015-11-30 01:26:01 -07:00
parent 9b477230e0
commit ac0c5a3707
2 changed files with 18 additions and 11 deletions

View File

@ -42,6 +42,9 @@ make
## Roadmap ## Roadmap
* ability to specify version
* cli ability to override library export locations
* add test for building library
* variables and parameters * variables and parameters
* Export .so library * Export .so library
* Multiple files * Multiple files

View File

@ -1254,21 +1254,25 @@ static AstNode *ast_parse_root_export_decl(ParseContext *pc, int *token_index) {
/* /*
Root : RootExportDecl many(TopLevelDecl) token(EOF) Root : RootExportDecl many(TopLevelDecl) token(EOF)
*/ */
static AstNode *ast_parse_root(ParseContext *pc, int *token_index) {
AstNode *node = ast_create_node(NodeTypeRoot, &pc->tokens->at(*token_index));
node->data.root.root_export_decl = ast_parse_root_export_decl(pc, token_index);
ast_parse_top_level_decls(pc, token_index, &node->data.root.top_level_decls);
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) { AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens) {
ParseContext pc = {0}; ParseContext pc = {0};
pc.buf = buf; pc.buf = buf;
pc.root = ast_create_node(NodeTypeRoot, &tokens->at(0));
pc.tokens = tokens; pc.tokens = tokens;
int token_index = 0; int token_index = 0;
pc.root = ast_parse_root(&pc, &token_index);
pc.root->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);
if (token_index != tokens->length - 1) {
ast_invalid_token_error(&pc, &tokens->at(token_index));
}
return pc.root; return pc.root;
} }