From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id CJHIEbLQ4GZuAQEAqHPOHw:P1 (envelope-from ) for ; Wed, 11 Sep 2024 01:05:22 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id CJHIEbLQ4GZuAQEAqHPOHw (envelope-from ) for ; Wed, 11 Sep 2024 01:05:22 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; none 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 3BA4C7C0A9 for ; Wed, 11 Sep 2024 01:05:19 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=qCre38L3ZyGSnvvUn4+TzROjuBmUD9/CpK0sHSXcpfA=; 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=1726009518; v=1; b=dkepDgP8mF/RieVc46ESd/T43Uqw43bQLfA2xXLgwZsqeDOOm0hIFB/CLP38N4s7qsSogLWR TemdXU5BMf/5PZtipulTghDiVgnShHzWag2C32nDUSSh1p4xfcZaZeGTzcXHP1EkmL1ANKB13TT TlK4v/b1gaFvnS01ukFOKwz+qvD6U9QNSKnVQvC5bsAXizMMpfmlFv0+o9sHHJ3YZizv3fzfyMq Gpqdr2oOrb0Qis3sqbIysPJSOXvjqz91YwK6V08o3izfY64hT5ZkyKv6lq+PIPJrdvd2MYdOSDw lvfvTQQPWyjHCP5ty1JNb6dL8nQVlJQeDp/aJ88yIu2VA== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id EA48220289 for ; Tue, 10 Sep 2024 23:05:17 +0000 (UTC) Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.173]) by mail-a.sr.ht (Postfix) with ESMTPS id 29FB820190 for <~johnnyrichard/olang-devel@lists.sr.ht>; Tue, 10 Sep 2024 23:05:17 +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=1726009516; 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=nzWt/gIOiWHnMm1RQxc4tYeBUAmmHkrFS7ehHG6NLkE=; b=P4T2zPl9wuQyEcIsHz1ODuzn2SdkC/4rvNj7poZq7oeRcOauw24eR9H5IlkXCiRGuMOLp/ az1ga0/xpJNsYhXWpfvh+5W/wuNGGHiEpxn+5mkjKxS/liSmUbKKtTNMiwITdiiwezFpAD P1Q37IKyz+eo+KGPmzlDcCG49yP3EzTJIP88b0QAxPC+xRis6SsaUxhNS0D1ks4YmtEBCL 2jl4osp0NO6FJTwsw3YrTAzlcTMf0Lqt/NBwP8T7f3hc81bKiJbtetPZLaxaKwC9v7CGfP Yxp/ipsFltfcvPTZMHsU+mxcqvhjCaPVFujHAKtWhO8Y2KXwX49L43lDOIpIkg== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1 1/2] lexer: add support var keyword Date: Wed, 11 Sep 2024 03:03:46 +0200 Message-ID: <20240911010517.196175-2-johnny@johnnyrichard.com> In-Reply-To: <20240911010517.196175-1-johnny@johnnyrichard.com> References: <20240911010517.196175-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-Queue-Id: 3BA4C7C0A9 X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -4.00 X-Spam-Score: -4.00 X-TUID: ZbDSzdakS7Go Signed-off-by: Johnny Richard --- This lexer is soooo goood!! OMG... src/lexer.c | 5 ++++ src/lexer.h | 1 + .../integration/tests/0024_var_definition.ol | 23 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/integration/tests/0024_var_definition.ol diff --git a/src/lexer.c b/src/lexer.c index 2129788..12b4719 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -284,6 +284,7 @@ static char *token_kind_str_table[] = { [TOKEN_RETURN] = "return", [TOKEN_IF] = "if", [TOKEN_ELSE] = "else", + [TOKEN_VAR] = "var", [TOKEN_LF] = "line_feed", [TOKEN_OPAREN] = "(", [TOKEN_CPAREN] = ")", @@ -419,6 +420,10 @@ lexer_str_to_token_kind(string_view_t text) return TOKEN_ELSE; } + if (string_view_eq_to_cstr(text, "var")) { + return TOKEN_VAR; + } + if (string_view_eq_to_cstr(text, "return")) { return TOKEN_RETURN; } diff --git a/src/lexer.h b/src/lexer.h index 98a6d87..4a0e2e1 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -40,6 +40,7 @@ typedef enum token_kind TOKEN_RETURN, TOKEN_IF, TOKEN_ELSE, + TOKEN_VAR, // Equality operators TOKEN_CMP_EQ, diff --git a/tests/integration/tests/0024_var_definition.ol b/tests/integration/tests/0024_var_definition.ol new file mode 100644 index 0000000..d0b68da --- /dev/null +++ b/tests/integration/tests/0024_var_definition.ol @@ -0,0 +1,23 @@ +# 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 code: u32 = 0; + return code; +} + +# TEST test_contains_tokens WITH +# ./tests/0024_var_definition.ol:17:3: +# END -- 2.46.0