From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 4MtMKgtv32aRhQAAqHPOHw:P1 (envelope-from ) for ; Mon, 09 Sep 2024 23:56:27 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 4MtMKgtv32aRhQAAqHPOHw (envelope-from ) for ; Mon, 09 Sep 2024 23:56:27 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=T9eAvqDQ; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=K0f6SD8L; 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=1725918987; 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: in-reply-to:in-reply-to:references:references:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=DN35CR4yTPzhhnRC1qLcdSTHtFhAhrkcI+8A92DtFP4=; b=T+FUGVv4+nuB1k/IqQK9G4FSEHme6eGqmsjJ50iyvQ7+bWnbF5bX1in693WffKobhTtiq+ viRsuOR1RAtdWX6dOcip14ZF7v9zcJnMoDitOHPUdOZab1pQ5EkRZB0ddvxrvkmCNsMSKa 03lRzOS18wZ3o8UOpjOd5cc1invqjQbwyGnfaNrxVNSoo2RUmHdVh3UmeNgsJaj9mkmSQZ WT9tentyso7oj4p6M1mSJmJNSToGtIuS89EL5+lXXSMnbe/BLuo4SqiQUMgk2OTyHthjjS wafGSyLpS1zIi6DPrTUV9uA2A3POYGbeWnPmSxAuRgrjXc2gMdwW6MxCGnTdww== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=T9eAvqDQ; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=K0f6SD8L; 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=1725918987; a=rsa-sha256; cv=none; b=Pto3p5gYLN2j/YW1JaSQAz8wAey81ERXr6SbKUL/6eumjY8klMSzQp2hRjLA6sC9KBi31D fnSRwFMlJgAaY6eZGrAm0SmS1h4/5Mjzm8HRSdjHdfwh6ylTNfqEEK1XW4+tYH3hPmKzU7 Nu2kihVmCKbF/bykRithMtHn4YriWFdGB1K48BqomgG0Azae8GOS1izUT2plmljLD/YLfY EbvI5XvDVXgAzDXKCgjQubpu4+quyWjUzaBnfpfLNTYxA5jg/CQr71Iq780UsRR+tCIe3A xwaL7jH0ufVLFK0k89RzzNWJLpZtRXBRhCbJpwg9xbtUqwLy5XrDWmAKYSLsKQ== 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 45981D82A for ; Mon, 09 Sep 2024 23:56:27 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=aZoV03qGCxcw1mLb5FCJPWLiEyLO+JrD066/hxC5520=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1725918987; v=1; b=T9eAvqDQBGwzZ/Szx+eFauTlT1+w1O8Y7eSHthfUJ1g60ul7MH9GPyCy33dEYflqsdMCN6pJ 9GlL7Knxckb90/5fjo5uLLTBuaqNYiUMK+AGSdyu9fbMWFxNfJe7ljdiN2bNNyvqs6CLVW9xWb4 tkhmGUls13TpkCbKzkcH+RXditUjugnGBwynvOLiZMMOVi592u9r7kPBW5ZSuo8d6WK06P5OFq/ 668Z/obi3UYqQbTjS1LnqiRX8HRbCOsNBj9u+as96pkjbl3CI9O2GLKwqILHz5P25DccVjNSZx/ Koah7Ti/RfKMa1Mw+xdRSLBY4Adhb9+TBZINv3NmZmP6Q== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 267F2201F3 for ; Mon, 09 Sep 2024 21:56:27 +0000 (UTC) Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) by mail-a.sr.ht (Postfix) with ESMTPS id 92744200B4 for <~johnnyrichard/olang-devel@lists.sr.ht>; Mon, 09 Sep 2024 21:56:26 +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=1725918986; 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: in-reply-to:in-reply-to:references:references; bh=DN35CR4yTPzhhnRC1qLcdSTHtFhAhrkcI+8A92DtFP4=; b=K0f6SD8LdCyF62xJUDA6y0F1L5F8HzQrjwlS9/YktVsRCzQsr4vB0uLExybXh0AsO/U3V0 zD0Ud9hz7+ndrxyOqkBJDqUHF1PjZnJnwmLmWGNCSUfpuGeIqXqmQRU2iKZsU7AkDT75h6 IK7J/p60LsWp2N4Rlx3mG5NKraFVxNqLZTYs1+Al83pV03MX+Ag2KXeYeayU1Slfv/gOkn Zepm/cJK6+qifll5TJf9oeQ0GZ6SwPBt/fPiVjn2+ivaprPe0ojctNnYJCwG2tGILnUIoY L2hwLLCP7V4yEf7bfpWpckOodn71RfTFT76tI0PUhhHtcb6fESgfrrz1tuO+Ow== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1 1/2] lexer: add support to else keyword token Date: Tue, 10 Sep 2024 01:54:58 +0200 Message-ID: <20240909235611.84414-2-johnny@johnnyrichard.com> In-Reply-To: <20240909235611.84414-1-johnny@johnnyrichard.com> References: <20240909235611.84414-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Sourcehut-Patchset-Status: UNKNOWN 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: 45981D82A X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -5.79 X-Spam-Score: -5.79 X-TUID: a8IioC/32Mlc Signed-off-by: Johnny Richard --- src/lexer.c | 5 ++++ src/lexer.h | 1 + .../integration/tests/0023_else_statement.ol | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/integration/tests/0023_else_statement.ol diff --git a/src/lexer.c b/src/lexer.c index 8147e4d..2129788 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -283,6 +283,7 @@ static char *token_kind_str_table[] = { [TOKEN_FN] = "fn", [TOKEN_RETURN] = "return", [TOKEN_IF] = "if", + [TOKEN_ELSE] = "else", [TOKEN_LF] = "line_feed", [TOKEN_OPAREN] = "(", [TOKEN_CPAREN] = ")", @@ -414,6 +415,10 @@ lexer_str_to_token_kind(string_view_t text) return TOKEN_IF; } + if (string_view_eq_to_cstr(text, "else")) { + return TOKEN_ELSE; + } + if (string_view_eq_to_cstr(text, "return")) { return TOKEN_RETURN; } diff --git a/src/lexer.h b/src/lexer.h index 2ee4405..98a6d87 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -39,6 +39,7 @@ typedef enum token_kind TOKEN_FN, TOKEN_RETURN, TOKEN_IF, + TOKEN_ELSE, // Equality operators TOKEN_CMP_EQ, diff --git a/tests/integration/tests/0023_else_statement.ol b/tests/integration/tests/0023_else_statement.ol new file mode 100644 index 0000000..60096e2 --- /dev/null +++ b/tests/integration/tests/0023_else_statement.ol @@ -0,0 +1,26 @@ +# Copyright (C) 2024 olang mantainers +# +# 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 . + +fn main(): u32 { + if 0 != 0 { + return 1 + } else { + return 0 + } +} + +# TEST test_contains_tokens WITH +# ./tests/0023_else_statement.ol:19:5: +# END -- 2.46.0