diff options
Diffstat (limited to 'src/parser.c')
-rw-r--r-- | src/parser.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/parser.c b/src/parser.c index 4867201..593f75a 100644 --- a/src/parser.c +++ b/src/parser.c @@ -65,11 +65,11 @@ parser_parse_type(parser_t *parser) { token_t token = expected_token(parser, TOKEN_NAME); - if (strcmp(token.value, "i32") == 0) { + if (string_view_eq(token.value, string_view_from_str("i32"))) { return TYPE_I32; } - fprintf(stderr, "[ERROR]: expected type 'i32' but got '%s'\n", token.value); + fprintf(stderr, "[ERROR]: expected type 'i32' but got '"SVFMT"'\n", SVARG(&token.value)); exit(EXIT_FAILURE); } @@ -79,9 +79,9 @@ parser_parse_return_stmt(parser_t *parser) expected_token(parser, TOKEN_OCURLY); token_t return_keyword_token = expected_token(parser, TOKEN_NAME); - if (strcmp(return_keyword_token.value, "return") != 0) { + if (!string_view_eq(return_keyword_token.value, string_view_from_str("return"))) { // TODO: Add filename:row:col prefix to expected token exceptions - fprintf(stderr, "[ERROR]: expected 'return' keyword but got '%s'\n", return_keyword_token.value); + fprintf(stderr, "[ERROR]: expected 'return' keyword but got '"SVFMT"'\n", SVARG(&return_keyword_token.value)); exit(EXIT_FAILURE); } @@ -89,8 +89,11 @@ parser_parse_return_stmt(parser_t *parser) expected_token(parser, TOKEN_SEMICOLON); expected_token(parser, TOKEN_CCURLY); + char number_as_str[number_token.value.size]; + string_view_to_str(&number_token.value, number_as_str); + return (ast_return_stmt_t) { - .number = atoi(number_token.value) + .number = atoi(number_as_str) }; } @@ -104,7 +107,6 @@ parser_parse_function(parser_t *parser) type_t return_type = parser_parse_type(parser); return (ast_function_t) { - // FIXME: alloc memory for the ast_function.name, it's not a good idea to use the token.value .name = func_name_token.value, .return_type = return_type, .body = parser_parse_return_stmt(parser) |