| ... | ... | @@ -1254,21 +1254,25 @@ static AstNode *ast_parse_root_export_decl(ParseContext *pc, int *token_index) { |
| 1254 | 1254 | /* |
| 1255 | 1255 | Root : RootExportDecl many(TopLevelDecl) token(EOF) |
| 1256 | 1256 | */ |
| 1257 | | AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens) { |
| 1258 | | ParseContext pc = {0}; |
| 1259 | | pc.buf = buf; |
| 1260 | | pc.root = ast_create_node(NodeTypeRoot, &tokens->at(0)); |
| 1261 | | pc.tokens = tokens; |
| 1257 | static AstNode *ast_parse_root(ParseContext *pc, int *token_index) { |
| 1258 | AstNode *node = ast_create_node(NodeTypeRoot, &pc->tokens->at(*token_index)); |
| 1262 | 1259 | |
| 1263 | | int token_index = 0; |
| 1264 | | |
| 1265 | | pc.root->data.root.root_export_decl = ast_parse_root_export_decl(&pc, &token_index); |
| 1260 | node->data.root.root_export_decl = ast_parse_root_export_decl(pc, token_index); |
| 1266 | 1261 | |
| 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); |
| 1268 | 1263 | |
| 1269 | | if (token_index != tokens->length - 1) { |
| 1270 | | ast_invalid_token_error(&pc, &tokens->at(token_index)); |
| 1264 | if (*token_index != pc->tokens->length - 1) { |
| 1265 | ast_invalid_token_error(pc, &pc->tokens->at(*token_index)); |
| 1271 | 1266 | } |
| 1272 | 1267 | |
| 1268 | return node; |
| 1269 | } |
| 1270 | |
| 1271 | AstNode *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 | 1277 | return pc.root; |
| 1274 | 1278 | } |