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 +B70K8re3GYLhgAAqHPOHw:P1 (envelope-from ) for ; Sun, 08 Sep 2024 01:16:26 +0200 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 +B70K8re3GYLhgAAqHPOHw (envelope-from ) for ; Sun, 08 Sep 2024 01:16:26 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=c78dfFKD; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=PqK+27AK; 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=1725750986; 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=xRU/fUO2E626kR2EbIC6pt335msQGbEwpe3pHL4FJmHvgk5TQIgb0aFngK6LNjjqvzAibI pdNZMaNje88w1A/XAQbgwwqIifvlqc6rpOkCTnvn+ssceEXDZD+4fOirV/N/K/DuY6/Ur1 XaFTSvfo5C4iUPN3+KdWVGDpNrp+0LaLZ59hNMFWanyyDYxgLp3jLnxuODQSwVdAMRLm9Q L5fx+ZBgqYotzHtbCVi3pHkiZUzzOknajH0Zq5w4XD6SBgQgUMZiPXZDnyVVL+1zbIV9kH NkN9ruZLO8fG5PQ4oStvTx0aF1IMv3mpGFC4Xvh7vC2denAaYbKry76uRFWWbw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=c78dfFKD; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=PqK+27AK; 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=1725750986; a=rsa-sha256; cv=none; b=I4N+dB5DLKDzXcGBhEs9g3NEvH4f6oR30DH0yUlh+387quD/osMmmaD/49gkKbkLz1OdWx GH4XSv1mw+uPswQFKjsrlxciewa7YT61LAsYSgRvcrMtQTeD1mFd1Gzd9/gXFFryXCXTW1 PVRrJqQTvTDBOQkPPpUE/MDwST+SvE2Azd1TsQcp+u9iEYb0Z8WcdX5DWCMuyQFD6xJp/A KO8ENP8zyyVWiDdOgC3YHt3vB6g5gIPasBEu8v8t4Iz7kcwMujWB5vdGyoR1MPfIY7R9Jo rx4AlNSDQf4yBDa03lCVmpzvKdXkEHvSWQ2EylnamxTl8uTfEmlNbG5huzziVw== 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 932727C2C8 for ; Sun, 08 Sep 2024 01:16:26 +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=1725750986; v=1; b=c78dfFKDq6nA0bV2DDSy8r5NXMhtq/OthVx0gL69aQRKnhtza4LxSTSl9ORyJrpjyvy5H2Xg 0uYbBca7iIXqBSttKOPxgvGOozP6dh9IBmbKZNmBzdtZ1Op4FmDSehIgcGteKgP5AfKFPsL1iRJ pIn5xnmYB903XepLyiKI2sUSSnkvJC9Gr34x3wXtjdc1Vq9yBxeeEq4ZBdgf0i7dAV+dLPaHAi2 /MbZ/DaR62vFHHa/92AYmKGDs2FSAN+P3ozeQwKM2RNk2aX7h3AnCg+x5NsJH3NuNVH9LZPAj/1 vukmgm1rCaRnbR3HqaAikb5HFiv2yaQDARSle8WQk/qPA== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 6856320259 for ; Sat, 07 Sep 2024 23:16:26 +0000 (UTC) Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by mail-a.sr.ht (Postfix) with ESMTPS id D898620152 for <~johnnyrichard/olang-devel@lists.sr.ht>; Sat, 07 Sep 2024 23:16:25 +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=1725750985; 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=PqK+27AKGTdVwh5zYwXKWm6aNSTd57beBSKxcrrR66HMb/+eLCkBnanj+OLvgmWaRVhGjB upd2dsa0rbMDyaXq3hkT1ROv1/pNc5BjSuHRJUkcPLFXn/DZWwdCR5Dz4degLJ1Fg6MNnE F9zoSzxotVL5/gcn+qwq7LbmgiJZc+24xGEVtV5LESaOqYUcbhQuQtqrjp6zRWj8azUVtF zVyy+Ty5q5Dvr0hLR12paHjCVSyLtHLFFgYV+N+vSZsuSQBUYizqFM4xfTBk4XTsvjG/MN 9FZWDMCibPQOzqK08R9IzT5S5emP8VkijAVoP1ltVKkkSjNen7F14zZYmUluIw== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Carlos Maniero Subject: [PATCH olang v2 1/4] lexer: add support to if token Date: Sun, 8 Sep 2024 03:10:55 +0200 Message-ID: <20240908011512.152684-3-johnny@johnnyrichard.com> In-Reply-To: <20240908011512.152684-2-johnny@johnnyrichard.com> References: <20240908011512.152684-2-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-Spam-Score: -5.89 X-Migadu-Queue-Id: 932727C2C8 X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -5.89 X-TUID: SVJo4Z6MK+Ta 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