From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id iNW1FAYZAGeHYwEA62LTzQ:P1 (envelope-from ) for ; Fri, 04 Oct 2024 18:34:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id iNW1FAYZAGeHYwEA62LTzQ (envelope-from ) for ; Fri, 04 Oct 2024 18:34:14 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b="UFtv/kNV"; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=CIe60cVh; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1"); spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht ARC-Seal: i=2; s=key1; d=johnnyrichard.com; t=1728059654; a=rsa-sha256; cv=pass; b=G4jpDdUZ834W1c4rBMlnJfBTXP/WR5g0wk51lxdNK00JlOcU4IqgXQj+AO8pJz4zLi3Ae1 MMkpWsnc3CilsPBhaAarlqVrmnsXubbETf0bexEjF1gQ1/Hw4L/dvSaxHc112dLkFxUquN uSnDczlYFVgzFv7lw9kO5OXIdv6//IohTSjGClaZgKTU5284plVsy3303ixthrtFC/gaDh j07flZJrvU5ruK3/8Akn0Nh2Yws4Btr5R9M/+jhYt4BjlQPYkBRT2ZXC1vgjM+JsGH4T/T YrwUUJ9wlXjo43eevvROd8MPpnkXIMV8pwlYTg8gyZwzVMu9+S6KggAXyu+qHw== ARC-Authentication-Results: i=2; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b="UFtv/kNV"; dkim=pass header.d=maniero.me header.s=hostingermail1 header.b=CIe60cVh; dmarc=pass (policy=none) header.from=maniero.me; arc=pass ("mailchannels.net:s=arc-2022:i=1"); spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1728059654; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=o9j4/Tvp/OmNy29FgNz1mFO2DYVyPtIrJi+sN1hgKzE=; b=E1bUZuB28houQnr7yfuLXDkn6q9kNpdUje2AP49kvIPafnkIAKExklZN3lc00MK8m9sp8I nMscZbbIMYXUxjHXu1FJZnJMbrYlbmD1qeYMOOpAogHDmWhEId3vSDz3Oo14eRblDDF5so mDIUnTALwZ9ln68osWT0cqq6CKSZT7ej/WJQxa6dKMpNIVZ0beyozJY2yJxcoG+pjA7Ct+ lp1fP5JQgZQq93GYbLBfmYPuIqTDYy+pfphCpD2jOv7/ERNcJCF+g2VrEF6IKNYBPu+knm ce5j7J5tpSiNK9C7tYDas3OWVuQI8Y1AJjuyBkP2Xvpc1mRXM6S9j3P3pkFotg== Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1C7881E60B for ; Fri, 04 Oct 2024 18:34:14 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=sMd72ErBYOA76Qou1ddwCWrxVcKObVBDTLJ/NaeHR3I=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1728059647; v=1; b=UFtv/kNVpZdZ8jXtzOy++UdObjime6awIxKTquQBgdcqPfXHq1rFwwu6jH3BF63JkCDAI2Bh SuG4zrbOTNWAwNg3rVldhDbdxdNms0bzc0iLlNPbfqdssc5ZzGZBLNiAtl7Q6drbwjsKxITM56N pPznxHzPrr97cjUoDNT/m3x6BhggFJErt3QQC+WEQEcW8DW+TW2qk7zuidoCcyQMQwal9Z4ApBh /MVUSHmJTDtxZ7Atm2MoWshV+gncMpJDjjngs7y4axVol7htSXTXuB6XLyuBsNcyyhWNiHgMolp SQIIxwBmH9FOdLL3LLN4JDAGmdI+oYPNieViwY3pMzKCg== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id AF8242022D for ; Fri, 04 Oct 2024 16:34:07 +0000 (UTC) Received: from cornsilk.maple.relay.mailchannels.net (cornsilk.maple.relay.mailchannels.net [23.83.214.40]) by mail-a.sr.ht (Postfix) with ESMTPS id 8D69720222 for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 04 Oct 2024 16:34:06 +0000 (UTC) X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 29608823945 for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 4 Oct 2024 16:34:05 +0000 (UTC) Received: from uk-fast-smtpout10.hostinger.io (trex-1.trex.outbound.svc.cluster.local [100.96.80.58]) (Authenticated sender: hostingeremail) by relay.mailchannels.net (Postfix) with ESMTPA id 67EB98236C5 for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 4 Oct 2024 16:34:04 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1728059644; a=rsa-sha256; cv=none; b=cgV/Mc9oeOZQVo7f+52BMXgwlKTwScug3OIPJcSbYbmT5TNXI/KOv1lKEkIVNRLvQUkYRJ xtMz7BIe49rxFvhu0TG18fHEuekffELZoiyxxOS5q5fw4zUmv7XFJNMt0ZO+Sci6v4sjOk gjP1I4yrpkXkB5PFaoDJUQgHN5mFOzd3Iml6qDjl45mdwy8IS+yJaoXalCLC2P3+MxwWzb 1w/8sVdlUPlsPE24q/6UqNOwzdL7yDU5cRoyrE3sOzHfv/kPE7gDats+kcCqr8RXXzPPsy RFX7ONvHwrbCcOyggKjhfu7AElJec/qKEmQa1OpdI9yRftUUPsQQ+kF07A29gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1728059644; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:dkim-signature; bh=o9j4/Tvp/OmNy29FgNz1mFO2DYVyPtIrJi+sN1hgKzE=; b=BqalhGU/wwtxAFZWxsqWrPfw7tDMWHk9lIWW2c7lG9eFkVWW8nPouPEcbocdttG069FwcC ZCUeh6qClDHBfcPOghm4aAVwKoaFPI0g7M+TY2pyBs7a2grv7a0fyjwXCgCUpESGtyEpYi tyjNw5FaUByp/Vc9YFMWBb5VxaDM2vKa+OdQshhCg7sAum5M7v0yABNtD2PLIHZpTWc/th 3PzkdCPnzjPnTztu5T3FTVEGXioo6m+Ix6xa4kINUeurRh7yuNagjXF7FVdjin5oRkMDGW xEyxEFXUh+1IcGQ5OY6dBjurngSgupC9TtC5n4RcIdSb8ROlef27OPUhOw+YUQ== ARC-Authentication-Results: i=1; rspamd-5778c966d7-9mzw8; auth=pass smtp.auth=hostingeremail smtp.mailfrom=carlos@maniero.me X-Sender-Id: hostingeremail|x-authuser|carlos@maniero.me X-MC-Relay: Neutral X-MailChannels-SenderId: hostingeremail|x-authuser|carlos@maniero.me X-MailChannels-Auth-Id: hostingeremail X-Power-Hook: 1a113d0a42665953_1728059645005_1339378877 X-MC-Loop-Signature: 1728059645005:1559512380 X-MC-Ingress-Time: 1728059645005 Received: from uk-fast-smtpout10.hostinger.io (uk-fast-smtpout10.hostinger.io [145.14.155.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.96.80.58 (trex/7.0.2); Fri, 04 Oct 2024 16:34:05 +0000 From: Carlos Maniero DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=maniero.me; s=hostingermail1; t=1728059642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=o9j4/Tvp/OmNy29FgNz1mFO2DYVyPtIrJi+sN1hgKzE=; b=CIe60cVhzjLdUR+Bu04Ha4R2BhJ7Gbws83vfj+zQccWnXpKt/SV8QvWGC00PEc9bvoiFqs O2DdaE22DfoMrMEoa+4ZHaY29fu8Hd8Lc87Wrhqql1TuHNn+w7DcmnS9ch1NFI2m1SY94M Db5N4ZGS71CkBUgYNO/18+RT6DDsa0CfijLlWs5VHug/j+gatjdmq2GyCMdaP7VcNOVcWF KHrNEgmuVO1XOppopsoIKWUOotIH/yyo/+aLDUeQ8WbXqxV1sWHJaNt3N3XbPe3JZJ3S91 E+oRf/gfnNExvMXdWL7S5q5u1uuiLj2FhlLYhVcsAjJdM2B/GDtQX6LSGAFLMQ== To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang] lexer: add source code abstraction Message-Id: <20241004163339.46748-1-carlos@maniero.me> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Date: Fri, 04 Oct 2024 16:34:02 +0000 (UTC) X-CM-Analysis: v=2.4 cv=TcnEtgQh c=1 sm=1 tr=0 ts=670018fa a=WwxFCuf3mf1fs3oSi6/dng==:117 a=WwxFCuf3mf1fs3oSi6/dng==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=mDV3o1hIAAAA:8 a=FWS8LoH7_3U_ljtToowA:9 a=BXDaF_L80NY05PYiAFlV:22 X-CM-Envelope: MS4xfPF89trrE/M+PAXKXL1b8KPoPoZPEx9NTVCOxW7xjscBv/fuXw6suu4E8pLXY02EOE9k+024H7+xh3Y4HwmGyFsssPsfMNQayF30PI+Em8Z+SZxuPEYr GiaYkQIZ/MMxvY2wAqGxSjVp9v5srfMUHmDel2dYuEZi88uCFW2QRjurUwGm9G7O1XO8+QZr6jNv9d4mlEtheMsLrEzJ2LnSLIhtQW7EZVmd/MNWYJm5sLgD X-AuthUser: carlos@maniero.me X-Sourcehut-Patchset-Status: PROPOSED List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Country: NL X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -5.75 X-Spam-Score: -5.75 X-Migadu-Queue-Id: 1C7881E60B X-Migadu-Scanner: mx10.migadu.com X-TUID: rcAm2XY8qHoH This struct stores the source code string and its filepath. This will be used in the near future to create token's locations. Signed-off-by: Carlos Maniero --- src/cli.c | 2 +- src/cli.h | 2 +- src/lexer.c | 20 ++++++------- src/lexer.h | 5 ++-- src/main.c | 64 ++++++++++++++++++++-------------------- src/source_code.h | 28 ++++++++++++++++++ tests/unit/parser_test.c | 8 ++--- 7 files changed, 79 insertions(+), 50 deletions(-) create mode 100644 src/source_code.h diff --git a/src/cli.c b/src/cli.c index fa73b60..9d0f875 100644 --- a/src/cli.c +++ b/src/cli.c @@ -57,7 +57,7 @@ cli_parse_args(int argc, char **argv) opts.options |= CLI_OPT_SYSROOT; cli_opts_parse_sysroot(&opts, &args); } else { - opts.file_path = arg; + opts.filepath = arg; } arg = cli_args_shift(&args); } diff --git a/src/cli.h b/src/cli.h index 3f4c3a9..1a93443 100644 --- a/src/cli.h +++ b/src/cli.h @@ -32,7 +32,7 @@ typedef struct cli_opts char *arch; char *sysroot; char *compiler_path; - char *file_path; + char *filepath; string_view_t output_bin; } cli_opts_t; diff --git a/src/lexer.c b/src/lexer.c index 8de40a0..523822f 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -22,10 +22,10 @@ #include void -lexer_init(lexer_t *lexer, string_view_t source) +lexer_init(lexer_t *lexer, source_code_t src) { assert(lexer); - lexer->source = source; + lexer->src = src; lexer->cur.offset = 0; lexer->cur.row = 0; lexer->cur.bol = 0; @@ -90,7 +90,7 @@ lexer_next_token(lexer_t *lexer, token_t *token) current_char = lexer_current_char(lexer); } - string_view_t text = { .chars = lexer->source.chars + start_cur.offset, + string_view_t text = { .chars = lexer->src.code.chars + start_cur.offset, .size = lexer->cur.offset - start_cur.offset }; lexer_init_str_value_token(lexer, token, lexer_str_to_token_kind(text), start_cur); @@ -359,13 +359,13 @@ token_kind_is_binary_op(token_kind_t kind) static char lexer_current_char(lexer_t *lexer) { - return lexer->source.chars[lexer->cur.offset]; + return lexer->src.code.chars[lexer->cur.offset]; } static void lexer_skip_char(lexer_t *lexer) { - assert(lexer->cur.offset < lexer->source.size); + assert(lexer->cur.offset < lexer->src.code.size); if (lexer_current_char(lexer) == '\n') { lexer->cur.row++; lexer->cur.bol = ++lexer->cur.offset; @@ -377,7 +377,7 @@ lexer_skip_char(lexer_t *lexer) static bool lexer_is_eof(lexer_t *lexer) { - return lexer->cur.offset >= lexer->source.size; + return lexer->cur.offset >= lexer->src.code.size; } static bool @@ -395,14 +395,14 @@ _isspace(char c) static void lexer_init_char_value_token(lexer_t *lexer, token_t *token, token_kind_t kind) { - string_view_t str = { .chars = lexer->source.chars + lexer->cur.offset, .size = 1 }; + string_view_t str = { .chars = lexer->src.code.chars + lexer->cur.offset, .size = 1 }; *token = (token_t){ .kind = kind, .value = str, .cur = lexer->cur }; } static void lexer_init_str_value_token(lexer_t *lexer, token_t *token, token_kind_t kind, lexer_cursor_t cur) { - string_view_t str = { .chars = lexer->source.chars + cur.offset, .size = lexer->cur.offset - cur.offset }; + string_view_t str = { .chars = lexer->src.code.chars + cur.offset, .size = lexer->cur.offset - cur.offset }; *token = (token_t){ .kind = kind, .value = str, .cur = cur }; } @@ -461,9 +461,9 @@ string_view_t lexer_get_token_line(lexer_t *lexer, token_t *token) { size_t offset = token->cur.bol; - string_view_t line = { .chars = lexer->source.chars + offset, .size = 0 }; + string_view_t line = { .chars = lexer->src.code.chars + offset, .size = 0 }; - while ((line.size + offset) < lexer->source.size && line.chars[line.size] != '\n' && line.chars[line.size] != 0) { + while ((line.size + offset) < lexer->src.code.size && line.chars[line.size] != '\n' && line.chars[line.size] != 0) { ++line.size; } diff --git a/src/lexer.h b/src/lexer.h index 1aecb11..c5a342a 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -17,6 +17,7 @@ #ifndef LEXER_H #define LEXER_H +#include "source_code.h" #include "string_view.h" #include #include @@ -30,7 +31,7 @@ typedef struct lexer_cursor typedef struct lexer { - string_view_t source; + source_code_t src; lexer_cursor_t cur; } lexer_t; @@ -92,7 +93,7 @@ typedef struct token } token_t; void -lexer_init(lexer_t *lexer, string_view_t source); +lexer_init(lexer_t *lexer, source_code_t src); void lexer_next_token(lexer_t *lexer, token_t *token); diff --git a/src/main.c b/src/main.c index 9d66455..4c8f2a5 100644 --- a/src/main.c +++ b/src/main.c @@ -44,10 +44,10 @@ void handle_codegen_linux(cli_opts_t *opts); static void -print_token(char *file_path, token_t *token); +print_token(char *filepath, token_t *token); -string_view_t -read_entire_file(char *file_path, arena_t *arena); +source_code_t +read_entire_file(char *filepath, arena_t *arena); int main(int argc, char **argv) @@ -75,24 +75,24 @@ main(int argc, char **argv) void handle_dump_tokens(cli_opts_t *opts) { - if (opts->file_path == NULL) { + if (opts->filepath == NULL) { cli_print_usage(stderr, opts->compiler_path); exit(EXIT_FAILURE); } arena_t arena = arena_new(ARENA_CAPACITY); - string_view_t file_content = read_entire_file(opts->file_path, &arena); + source_code_t src = read_entire_file(opts->filepath, &arena); lexer_t lexer = { 0 }; - lexer_init(&lexer, file_content); + lexer_init(&lexer, src); token_t token = { 0 }; lexer_next_token(&lexer, &token); while (token.kind != TOKEN_EOF) { - print_token(opts->file_path, &token); + print_token(opts->filepath, &token); lexer_next_token(&lexer, &token); } - print_token(opts->file_path, &token); + print_token(opts->filepath, &token); arena_free(&arena); } @@ -100,7 +100,7 @@ handle_dump_tokens(cli_opts_t *opts) void handle_dump_ast(cli_opts_t *opts) { - if (opts->file_path == NULL) { + if (opts->filepath == NULL) { cli_print_usage(stderr, opts->compiler_path); exit(EXIT_FAILURE); } @@ -109,10 +109,10 @@ handle_dump_ast(cli_opts_t *opts) lexer_t lexer = { 0 }; parser_t parser = { 0 }; - string_view_t file_content = read_entire_file(opts->file_path, &arena); + source_code_t src = read_entire_file(opts->filepath, &arena); - lexer_init(&lexer, file_content); - parser_init(&parser, &lexer, &arena, opts->file_path); + lexer_init(&lexer, src); + parser_init(&parser, &lexer, &arena, opts->filepath); ast_node_t *ast = parser_parse_translation_unit(&parser); @@ -122,7 +122,7 @@ handle_dump_ast(cli_opts_t *opts) void handle_codegen_linux(cli_opts_t *opts) { - if (opts->file_path == NULL) { + if (opts->filepath == NULL) { cli_print_usage(stderr, opts->compiler_path); exit(EXIT_FAILURE); } @@ -131,9 +131,9 @@ handle_codegen_linux(cli_opts_t *opts) lexer_t lexer = { 0 }; parser_t parser = { 0 }; - string_view_t file_content = read_entire_file(opts->file_path, &arena); - lexer_init(&lexer, file_content); - parser_init(&parser, &lexer, &arena, opts->file_path); + source_code_t src = read_entire_file(opts->filepath, &arena); + lexer_init(&lexer, src); + parser_init(&parser, &lexer, &arena, opts->filepath); ast_node_t *ast = parser_parse_translation_unit(&parser); @@ -204,48 +204,48 @@ handle_codegen_linux(cli_opts_t *opts) arena_free(&arena); } -string_view_t -read_entire_file(char *file_path, arena_t *arena) +source_code_t +read_entire_file(char *filepath, arena_t *arena) { - FILE *stream = fopen(file_path, "rb"); + FILE *stream = fopen(filepath, "rb"); if (stream == NULL) { - fprintf(stderr, "error: could not open file %s: %s\n", file_path, strerror(errno)); + fprintf(stderr, "error: could not open file %s: %s\n", filepath, strerror(errno)); exit(EXIT_FAILURE); } - string_view_t file_content = { 0 }; + string_view_t code = { 0 }; fseek(stream, 0, SEEK_END); - file_content.size = ftell(stream); + code.size = ftell(stream); fseek(stream, 0, SEEK_SET); - assert(file_content.size * 2 < ARENA_CAPACITY); + assert(code.size * 2 < ARENA_CAPACITY); - file_content.chars = (char *)arena_alloc(arena, (size_t)file_content.size); + code.chars = (char *)arena_alloc(arena, (size_t)code.size); - if (file_content.chars == NULL) { - fprintf(stderr, "error: could not read file %s: %s\n", file_path, strerror(errno)); + if (code.chars == NULL) { + fprintf(stderr, "error: could not read file %s: %s\n", filepath, strerror(errno)); exit(EXIT_FAILURE); } - size_t read_bytes = fread(file_content.chars, 1, file_content.size, stream); + size_t read_bytes = fread(code.chars, 1, code.size, stream); - if (read_bytes != file_content.size) { - fprintf(stderr, "error: failed to read all file bytes %s\n", file_path); + if (read_bytes != code.size) { + fprintf(stderr, "error: failed to read all file bytes %s\n", filepath); exit(EXIT_FAILURE); } fclose(stream); - return file_content; + return (source_code_t){ .filepath = filepath, .code = code }; } static void -print_token(char *file_path, token_t *token) +print_token(char *filepath, token_t *token) { printf("%s:%lu:%lu: <%s>\n", - file_path, + filepath, token->cur.row + 1, (token->cur.offset - token->cur.bol) + 1, token_kind_to_cstr(token->kind)); diff --git a/src/source_code.h b/src/source_code.h new file mode 100644 index 0000000..2c774c7 --- /dev/null +++ b/src/source_code.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2024 olang maintainers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "string_view.h" + +#ifndef SOURCE_CODE_H +#define SOURCE_CODE_H + +typedef struct source_code +{ + char *filepath; + string_view_t code; +} source_code_t; + +#endif diff --git a/tests/unit/parser_test.c b/tests/unit/parser_test.c index a7c60d1..9eb56fd 100644 --- a/tests/unit/parser_test.c +++ b/tests/unit/parser_test.c @@ -31,15 +31,15 @@ parse_translation_unit_test(const MunitParameter params[], void *user_data_or_fi { arena_t arena = arena_new(ARENA_CAPACITY); - char *file_path = "main.0"; + char *filepath = "main.0"; char *source_value = "fn main(): u32 {\n\treturn 69\n}"; lexer_t lexer; - string_view_t source = { .chars = source_value, .size = strlen(source_value) }; - lexer_init(&lexer, source); + string_view_t code = { .chars = source_value, .size = strlen(source_value) }; + lexer_init(&lexer, (source_code_t){ .code = code, .filepath = filepath }); parser_t parser; - parser_init(&parser, &lexer, &arena, file_path); + parser_init(&parser, &lexer, &arena, filepath); ast_node_t *translation_unit_node = parser_parse_translation_unit(&parser); assert_not_null(translation_unit_node); base-commit: 978a9914a9abc98ed9f866d528e9a094fbc1b35e -- 2.34.1