diff options
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/parser.c b/src/parser.c index e3f157f..b94087f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -571,6 +571,22 @@ is_next_statement_return(parser_t *parser) } static bool +is_next_function_declaration(parser_t *parser) +{ + token_t token; + lexer_peek_next_token(parser->lexer, &token); + return token.kind == TOKEN_KEYWORD_FN; +} + +static bool +is_next_token_eof(parser_t *parser) +{ + token_t token; + lexer_peek_next_token(parser->lexer, &token); + return token.kind == TOKEN_EOF; +} + +static bool is_block_end(parser_t *parser) { token_t token; @@ -746,3 +762,24 @@ parser_parse_function_declaration(parser_t *parser) return node; } + +ast_node_t * +parser_parse_ns(parser_t *parser) +{ + vector_t *nodes = vector_new(); + + while (!is_next_token_eof(parser)) { + if (is_next_function_declaration(parser)) { + ast_node_t *node = parser_parse_function_declaration(parser); + + if (node == NULL) { + ast_node_destroy_vector(nodes); + return NULL; + } + + vector_push_back(nodes, node); + } + } + + return ast_node_new_namespace(nodes); +} |