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 oAp5J5Y5BWcGMgEAe85BDQ:P1 (envelope-from ) for ; Tue, 08 Oct 2024 15:54:30 +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 oAp5J5Y5BWcGMgEAe85BDQ (envelope-from ) for ; Tue, 08 Oct 2024 15:54:30 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=EdnTVmo8; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b="WzpcM/mU"; 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=1728395670; 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=L5E2v0NPX9vvOZkeu8aya6d2ABW7AeF5pz2oAEg5hdo=; b=LMVD2HgZ/SlSbHoIgrSoW7TLdpUtlPCoEdww77dNt33/iX4oGiGhNrg1UfytZJYyS+8XYE YDNKcksPBbvHk5CEBxXs6m0bsJogPFail+ftASXstKicZfmgppZQOJ7v91NWOGHpp2Mt2Y kOkUUNdiiswbh4A/SKV/GhPfPAoN+ukhys3DGpLtNScQRdqNcVktgtFaZjQjSx5XbDdYXs KIW6plLWge3NPgyYmQdG/4akFsDQKieXOx4pfVIidJGfOTh48N0e0OKgPtmrA3t+tfWYpd 3Ls+Bq42Qp4lD9dnSseav7EkB18ZugWj+Y6qdYdOL47luGuZ4eimMN1GYQI+aQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=EdnTVmo8; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b="WzpcM/mU"; 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=1728395670; a=rsa-sha256; cv=none; b=3SsaZr6aHxPssdDap24ScmAbS5q3uE/Kq/7FsmO1mUZRmAfNkHTXZoR9nu1s9lowJWun+C YGsbd4lOMH4I/HxlgBsgs3nGaa6TKHuEZWf5RZ3NrhnkLseusTs2KUMzNIRqSQrcuyfSzY 5nBKo+fhw9F4Nel/pWX7W/9VSnYoa3gx5ViYwHGTzNJwEmfMJBvrU0R1tclBLMiyWQ8LJ8 RR/jk2c2iJ5OFPlWyw/mPGODGYlKID/Icg4dbJRnEu37DQy/Svx2CXrxZoUR/v0kJPrOZm jDHMr0KVr56532T52xAWG/GXtVAO/PqjtWzY/XJQt33tqFGc65jULAV5Gw8Y5g== 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 0BC207896D for ; Tue, 08 Oct 2024 15:54:30 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=Rh82dcCXFB0dN6I8gjcVVTPAX7WvjY26dbj2jVOyy+Q=; 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=1728395669; v=1; b=EdnTVmo8mIO1LguYZ8LUcTVrrfLF98DnILNVzelsYZ+tYIQ4jJbJaIO4sfhOYwF6kxsl9Q5n X2A4UsHuURsl+S+O9hNfnLDESVWJZf8l9mBEt7TpVghp3Ki4CJB4lLC0Ng3E42YcXI/6V/N1j1q sBYCoz9aPObjyUeExHQTzEz0iYoBuGNDs9sBLo4Zm4vKVMeW0J716tMkQLohwqDB8KKCki9GLF3 FO3iIWJlz1eWpS+81GH390irqU2Crjv/+WPXHApRjXXAVFLg+dR0bLhw9eaAZ/FsYmWuISv69sC w0rD2FRIs1GmHABw8ZQN7yjflRo82g+mg+ipkTrMmTwvg== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 783622015C for ; Tue, 08 Oct 2024 13:54:29 +0000 (UTC) Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by mail-a.sr.ht (Postfix) with ESMTPS id B8EA720133 for <~johnnyrichard/olang-devel@lists.sr.ht>; Tue, 08 Oct 2024 13:54:28 +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=1728395665; 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=L5E2v0NPX9vvOZkeu8aya6d2ABW7AeF5pz2oAEg5hdo=; b=WzpcM/mUCYEZp64DOSYKD6sevB/syxMhrkVFHFF2slH4XX2RTvdLWbHXeH0xwTNn8psV6H 2ESytHLHyiHnMRY4aBRoeZ45KBu8wXUyX5gOytZ8da7wlOZVkc91BfJlo84gfqzFddj0Ix 5JOIyi9FVMMbaR2BEE5mAnpFKWD0LkRZtGbDkOn3KEZPAHsBsqxFRzU3ue0X0o8Q0C4Nqq rUox4Y+Beip61wnZ8NZ5EkpY3e5doNjPDw4z3yfMvBO9oeLx9yHttzZR0zjRrSBhDIr2qM 5BZaoAsN9fv625/utMzgYUhcsyrA+P5V0XpQWhJJ7Wpi/jsh6wAOPhegRT3/tQ== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1] lexer: add 'while' keyword token Date: Tue, 8 Oct 2024 17:53:18 +0200 Message-ID: <20241008155356.177852-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-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -1.62 X-Spam-Score: -1.62 X-Migadu-Queue-Id: 0BC207896D X-TUID: VJSlseEwRQ3m Signed-off-by: Johnny Richard --- docs/info/specification.texi | 3 ++- src/lexer.c | 5 ++++ src/lexer.h | 1 + tests/olc/0030_while_statement.ol | 40 +++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/olc/0030_while_statement.ol diff --git a/docs/info/specification.texi b/docs/info/specification.texi index 9144133..1bac50f 100644 --- a/docs/info/specification.texi +++ b/docs/info/specification.texi @@ -41,8 +41,9 @@ language. ::= '{' ( )* ? '}' ::= ( ',' )* ::= '(' ( | ) ')' - ::= | | | + ::= | | | | ::= 'if' + ::= 'while' ::= 'return' (* Statements *) diff --git a/src/lexer.c b/src/lexer.c index 4784f1c..5b4bbaa 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -290,6 +290,7 @@ static char *token_kind_str_table[] = { [TOKEN_RETURN] = "return", [TOKEN_IF] = "if", [TOKEN_ELSE] = "else", + [TOKEN_WHILE] = "while", [TOKEN_VAR] = "var", [TOKEN_LF] = "line_feed", [TOKEN_OPAREN] = "(", @@ -424,6 +425,10 @@ lexer_str_to_token_kind(string_view_t text) return TOKEN_ELSE; } + if (string_view_eq_to_cstr(text, "while")) { + return TOKEN_WHILE; + } + if (string_view_eq_to_cstr(text, "var")) { return TOKEN_VAR; } diff --git a/src/lexer.h b/src/lexer.h index bb39a70..8beaea8 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -51,6 +51,7 @@ typedef enum token_kind TOKEN_RETURN, TOKEN_IF, TOKEN_ELSE, + TOKEN_WHILE, TOKEN_VAR, // Equality operators diff --git a/tests/olc/0030_while_statement.ol b/tests/olc/0030_while_statement.ol new file mode 100644 index 0000000..eb47ae5 --- /dev/null +++ b/tests/olc/0030_while_statement.ol @@ -0,0 +1,40 @@ +# 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 { + var i: u32 = 0 + + while i < 10 { + i = i + 1 + } + + return i +} + +# XTEST test_compile(exit_code=0) +# +# XTEST test_run_binary(exit_code=9) +# +# XTEST test_ast WITH +# Translation_Unit +# `-Function_Definition +# `-Block +# `-Return_Statement +# `-Literal +# END +# +# TEST test_contains_tokens WITH +# ./0030_while_statement.ol:19:3: +# END base-commit: dbbfdf2acab2b022cc9f0157d4341478d82b8838 -- 2.46.0