From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.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 SAMEM5GFBWZLWwAAqHPOHw:P1 (envelope-from ) for ; Thu, 28 Mar 2024 15:58:25 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id SAMEM5GFBWZLWwAAqHPOHw (envelope-from ) for ; Thu, 28 Mar 2024 15:58:25 +0100 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=l+EvuhAY; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b="rJW/UbbP"; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1711637905; 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=KT/Abw3nm2AK4hrpJJsfJwZt717NDXrn2ym3umZRHHs=; b=PN+lGP06G2XV7LjvRQ8WkVAanmwEvLfKV54OasuhLQZV6GjFqojGLQEaBNa3bh3tj7bcUN rKzEi5rP0QUtyUu5Sa+Oh4GYhQ+fJebgC7MQi112UtodQo0C3UyC+UUJfzWIULTbDOKW3k Z2u6GEJVNBPzqsv+pWjJkkLTcieIPqn6XCcgLTXwb9TEnNtErsCKeLCXmo14Q21myZQzA8 sf/oX20ltXp+6+cRsKahGwm489KJGC6kA2FTgtjz85bJbPwwK5Yuqbeac7YolAH+f94Qx1 bYCZN7E+2JyHu760l1gZGKYNfPM0pqhosIhcDZQro0poMfnnNB4KCg9MG73u7A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=l+EvuhAY; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b="rJW/UbbP"; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com ARC-Seal: i=1; s=key1; d=johnnyrichard.com; t=1711637905; a=rsa-sha256; cv=none; b=Rg0GAYMaZ9e5y7dm+BfvVQvLfKBTSqKCnXGfwbpaTy5hFddQgPNkvTArvER/ZCazrwyX1V mkAGF2aTOwgG1poX1IXe+rkD0bhZObHmvT6koNz+CC1UPphrTZDIyjYXdVOSx6dMgBVIG9 Zu9GS6KAy8dEm2YikboCjPq3bf1aLKYunygs7eUe5vHGKpdQOvH6+PkFv45aKctb8K2xaw jLtOxxypvMWvxDiijaaRGCRybie1hghfWl+sZPRUx5SfOuXy/6F/Eg698OxRO39q9cBILc CqUHYlQnEJyw183Y8UXv11pIty7frjWIHGJvKslgNWn4dE70dsEAedf/zPSQ3g== 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 7BED569765 for ; Thu, 28 Mar 2024 15:58:25 +0100 (CET) DKIM-Signature: a=rsa-sha256; bh=vd7d5tZYhNy2OtJTfgWPlsEnA7O+DDiIx8zuGcJHL0I=; 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=1711637904; v=1; b=l+EvuhAYJ2ntd2QKLDLU4lSRVs0ojmwl9K5VU4mN4hVh9yh7A/BAcfYQ3cu9j2kSy+IxGCps /eE/cQVX1teb9ikbB7vuYDka1oRuwidW0aQGW3uImIR06N9tazsv1cKgI7dn4GUzvIHTCdrFhdR lJ7qHMOEKY7i8onidhm/5Wpfi8lFCNlaJNL+BeuwrFJI6djZ7WwMP95jCj3h0mDf4WQ+vRJWznv 7cZ1Zx5qIdNlwJCqo5bDzGOusZouwZGwG2xki72pwyVJoxmUCJtdqJOl7Rxs6d8o+X10g0qWXXu ymsmBrSMPjaC0lMnnljDdlQrB7AK4rIYXeXIUy9OZgfEw== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 96290202EF for ; Thu, 28 Mar 2024 14:58:24 +0000 (UTC) Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) by mail-a.sr.ht (Postfix) with ESMTPS id E0EBF202AB for <~johnnyrichard/olang-devel@lists.sr.ht>; Thu, 28 Mar 2024 14:58:23 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1711637903; 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=KT/Abw3nm2AK4hrpJJsfJwZt717NDXrn2ym3umZRHHs=; b=rJW/UbbP2h1wwZlGT9uNIwLW4wndtwSdORMiGOllmE/2OMo02cTbMsUr6RA5mDlruHMngC SjXcYHRy4ZZ4qJ8Pf1Uf19dnvW/URT37N72nV7IbiD7AkMPkn5gHQUhYQxSPuIjakxPc8Q lRuhDtsdRAoNseJAerKOcgwxARCOeowPROny/DZXIByx7adV7s8iU795u0Y5B4EwIxUVtO ME1Gt/uoHqFavBKuC/Af9+hwOcjWMbMhsUzW6tOsAJ6EjUsx6ykghCsjHehwDqfKQ0YKPB 26ctk6B2TxgWnqSsNs/ENZTqpxwWB5NfvLbEvOZCs7czaGKgvus+0hGPf1K6hg== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1] fe: lexer: add single line comments support Date: Thu, 28 Mar 2024 16:58:38 +0100 Message-ID: <20240328155859.607264-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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-Queue-Id: 7BED569765 X-Spam-Score: -9.10 X-Migadu-Spam-Score: -9.10 X-Migadu-Scanner: mx10.migadu.com X-TUID: 31I/AKN4aTNv Signed-off-by: Johnny Richard --- examples/main_exit.ol | 3 +++ src/lexer.c | 7 +++++++ src/parser.c | 1 + tests/integration/cli_test.c | 31 +++++++++++++++++-------------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/examples/main_exit.ol b/examples/main_exit.ol index c86fc68..8952017 100644 --- a/examples/main_exit.ol +++ b/examples/main_exit.ol @@ -1,3 +1,6 @@ +# Expected: +# - output: "" + fn main(): u32 { return 0 } diff --git a/src/lexer.c b/src/lexer.c index 801e4d0..684cad1 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -76,6 +76,13 @@ lexer_next_token(lexer_t *lexer, token_t *token) } while (lexer_is_not_eof(lexer)) { + if (current_char == '#') { + while (current_char != '\n' && lexer_is_not_eof(lexer)) { + lexer_skip_char(lexer); + current_char = lexer_current_char(lexer); + } + } + if (isalpha(current_char)) { size_t start_offset = lexer->offset; while (isalnum(current_char) && lexer_is_not_eof(lexer)) { diff --git a/src/parser.c b/src/parser.c index 76ef91a..b800870 100644 --- a/src/parser.c +++ b/src/parser.c @@ -62,6 +62,7 @@ parser_init(parser_t *parser, lexer_t *lexer, arena_t *arena, char *file_path) ast_node_t * parser_parse_program(parser_t *parser) { + skip_line_feeds(parser->lexer); ast_node_t *fn = parser_parse_fn_definition(parser); if (fn == NULL) { return NULL; diff --git a/tests/integration/cli_test.c b/tests/integration/cli_test.c index d46471b..e7ae059 100644 --- a/tests/integration/cli_test.c +++ b/tests/integration/cli_test.c @@ -25,20 +25,23 @@ test_cli_dump_tokens_example_main_exit(const MunitParameter params[], void *user cli_result_t compilation_result = cli_runner_compiler_dump_tokens("../../examples/main_exit.ol"); munit_assert_int(compilation_result.exec.exit_code, ==, 0); munit_assert_string_equal(compilation_result.exec.stdout_buf, - "../../examples/main_exit.ol:1:1: \n" - "../../examples/main_exit.ol:1:4: \n" - "../../examples/main_exit.ol:1:8: <(>\n" - "../../examples/main_exit.ol:1:9: <)>\n" - "../../examples/main_exit.ol:1:10: <:>\n" - "../../examples/main_exit.ol:1:12: \n" - "../../examples/main_exit.ol:1:16: <{>\n" - "../../examples/main_exit.ol:1:17: \n" - "../../examples/main_exit.ol:2:3: \n" - "../../examples/main_exit.ol:2:10: \n" - "../../examples/main_exit.ol:2:11: \n" - "../../examples/main_exit.ol:3:1: <}>\n" - "../../examples/main_exit.ol:3:2: \n" - "../../examples/main_exit.ol:4:1: \n"); + "../../examples/main_exit.ol:1:12: \n" + "../../examples/main_exit.ol:2:16: \n" + "../../examples/main_exit.ol:3:1: \n" + "../../examples/main_exit.ol:4:1: \n" + "../../examples/main_exit.ol:4:4: \n" + "../../examples/main_exit.ol:4:8: <(>\n" + "../../examples/main_exit.ol:4:9: <)>\n" + "../../examples/main_exit.ol:4:10: <:>\n" + "../../examples/main_exit.ol:4:12: \n" + "../../examples/main_exit.ol:4:16: <{>\n" + "../../examples/main_exit.ol:4:17: \n" + "../../examples/main_exit.ol:5:3: \n" + "../../examples/main_exit.ol:5:10: \n" + "../../examples/main_exit.ol:5:11: \n" + "../../examples/main_exit.ol:6:1: <}>\n" + "../../examples/main_exit.ol:6:2: \n" + "../../examples/main_exit.ol:7:1: \n"); return MUNIT_OK; } base-commit: 117a06874c48c64e8ad4befbab244670f4f9ca9c -- 2.44.0