From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id IAuPLPHU3GbuBQEAe85BDQ:P1 (envelope-from ) for ; Sun, 08 Sep 2024 00:34:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id IAuPLPHU3GbuBQEAe85BDQ (envelope-from ) for ; Sun, 08 Sep 2024 00:34:25 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=XG4nSBF+; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=Ow6ysjjV; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com; 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=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1725748465; 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=THyVkbjuJ//KIfA+cvNrw1hWk1U9/WKNQjzUsjdud2s=; b=2ZnyKFEq+36UCpgjT9cgCIlDtvMQTWkp1EWNqGvfzsh+c/3vlM3A6COaD0XUq0BEKiu2Ut /ov3tGQ7yoD467hwxyAp7agZ5a/mr9rmHe4uvl9hU1eO0DOHxj2jljjPSL3eeY4uOCa2T0 LNn/ivReC2qFAWwGynUmFNFbIi4ROMlow0N4zQ7NPnGiwHaZHewIUIdq40LccJPSH1Cyag VmCTA2rWaz86AJxgDsKJHc7azHTrP4HsSM6U0bq1synXouxLPj06S5bs+ROB+RB271AxOJ KWhOhe/0mJ8ZpgUL+wSLYO0PW6C3PDpenvRVYFyO29rtbpfRf3AFIRJfANWlWw== ARC-Seal: i=1; s=key1; d=johnnyrichard.com; t=1725748465; a=rsa-sha256; cv=none; b=ILbCSKZL0G5UzeQlwMYLbgTBrC2tMcaQzbFk4Ewo0K6yOWYb6wav/FQvvGCtL8gcnOb8ZD 0+SuADFrrz9MHfpqb0/B+hQ1o/sOyUaduoTBDONpaF3pT3JumTKwsClQc8SRyrOCqigCgE Bp69VH5EsaD6nVS/EDHMv11iZd4RrmTeyu+bwl1q+2efWQ+5nxxs6i9ZxrNloygYvXlu1l LLx6kvWicGkQV2l46hFEGpt9Xv44M2k8KDanpZFtQk7WyKwKUq22Y1oGFYo70A8atOAMzO FWO4ay7PZGHHT4NPXBYdfVCbJq57Erpnd2ZedSyt/4cIFgyJrCChTUrhfWvAKQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=XG4nSBF+; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=Ow6ysjjV; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht 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 9B01E75F18 for ; Sun, 08 Sep 2024 00:34:25 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=KjP5jh0vqGZKXwyHPXa1SOQSsFB0ejPDpf+xxpG2rqg=; 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=1725748464; v=1; b=XG4nSBF+wdRbRhH0gxfSreQ56iDxGzkSf5OccQc+RACUHbj47zRXFT/51QStKE+ZvzeT3Y8g AN/S8L3SdV1mnkeRRURNNgSoKjxAu9a0hFyPwNtyOinraIY/ouMtaHCkqNVMJlEB7Mpv430mPiI L51SLhElkK5IVJ8GftFY8yBKtayBCcwN3Qo3MXAn/D8mlPgykaH4n2BTXZ/TZyoKNHbS56Rxgn5 WAQtTb7TIrL8vrthKc2EHJLb7HRP3qhUPwxVfYOE7/b1Kg5X9j3uXpOhyrVAJkUJbZhwWimPR+K 2ucVAmocKF90uGBwRiKIXrlUEKvDp8IyHBf2YCQIRwkQw== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 54E7620265 for ; Sat, 07 Sep 2024 22:34:24 +0000 (UTC) Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) by mail-a.sr.ht (Postfix) with ESMTPS id 9F6B720235 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 07 Sep 2024 22:34: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=1725748463; 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=THyVkbjuJ//KIfA+cvNrw1hWk1U9/WKNQjzUsjdud2s=; b=Ow6ysjjVv34BBfypPm1/mweU9Ob4zA6yFobc2dNDxUrn4+0/bN93n35h6sksYY2gOC3X4z z1SlJj9lwMitriDadJ4TkI3tsgfcgUbVqCv0ZsHlNHdsyqcCkWp6Jy8JbH8UWg4WOFOKA8 rlkWIL3MTuaN0i/hCnMZqPHoaNuTocziBn3ml4cZOpLFAyIWV7yLagjf7L+HHbKbyOFEo9 5SjKqzdiYX/zv9xK/3dTM2hjv7A6vx1FNOcsVkUx/SQg9CSPYHr9tb7n9yXsYgU+vIzPjX WObR8LLTUDi3Ud5CqUAmw+xngpsn7dhgzSBDsmX0DcVqF6Aj/Dd+HZFCfTdndw== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang 1/4] lexer: add support to if token Date: Sun, 8 Sep 2024 02:31:09 +0200 Message-ID: <20240908003402.145538-2-johnny@johnnyrichard.com> In-Reply-To: <20240908003402.145538-1-johnny@johnnyrichard.com> References: <20240908003402.145538-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-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -2.89 X-Spam-Score: -2.89 X-Migadu-Queue-Id: 9B01E75F18 X-Migadu-Scanner: mx11.migadu.com X-TUID: EmIqW2Cmtf+n From: Carlos Maniero Signed-off-by: Carlos Maniero --- src/lexer.c | 5 ++++ src/lexer.h | 1 + tests/integration/tests/0020_if_statement.ol | 25 ++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 tests/integration/tests/0020_if_statement.ol diff --git a/src/lexer.c b/src/lexer.c index 684cad1..8147e4d 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -282,6 +282,7 @@ static char *token_kind_str_table[] = { [TOKEN_NUMBER] = "number", [TOKEN_FN] = "fn", [TOKEN_RETURN] = "return", + [TOKEN_IF] = "if", [TOKEN_LF] = "line_feed", [TOKEN_OPAREN] = "(", [TOKEN_CPAREN] = ")", @@ -409,6 +410,10 @@ lexer_init_eof_token(lexer_t *lexer, token_t *token) static token_kind_t lexer_str_to_token_kind(string_view_t text) { + if (string_view_eq_to_cstr(text, "if")) { + return TOKEN_IF; + } + if (string_view_eq_to_cstr(text, "return")) { return TOKEN_RETURN; } diff --git a/src/lexer.h b/src/lexer.h index 80fb25a..2ee4405 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -38,6 +38,7 @@ typedef enum token_kind // Keywords TOKEN_FN, TOKEN_RETURN, + TOKEN_IF, // Equality operators TOKEN_CMP_EQ, diff --git a/tests/integration/tests/0020_if_statement.ol b/tests/integration/tests/0020_if_statement.ol new file mode 100644 index 0000000..f2f3262 --- /dev/null +++ b/tests/integration/tests/0020_if_statement.ol @@ -0,0 +1,25 @@ +# 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 1 == 1 { + return 0 + } + return 1 +} + +# TEST test_contains_tokens WITH +# ./tests/0020_if_statement.ol:17:3: +# END -- 2.46.0