From: Johnny Richard <johnny@johnnyrichard.com>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang v1 1/2] lexer: add support var keyword
Date: Wed, 11 Sep 2024 03:03:46 +0200 [thread overview]
Message-ID: <20240911010517.196175-2-johnny@johnnyrichard.com> (raw)
In-Reply-To: <20240911010517.196175-1-johnny@johnnyrichard.com>
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
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 <https://www.gnu.org/licenses/>.
+
+fn main(): u32 {
+ var code: u32 = 0;
+ return code;
+}
+
+# TEST test_contains_tokens WITH
+# ./tests/0024_var_definition.ol:17:3: <var>
+# END
--
2.46.0
next prev parent reply other threads:[~2024-09-10 23:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 1:03 [PATCH olang v1 0/2] parser: implement variable definition Johnny Richard
2024-09-10 23:15 ` Carlos Maniero
2024-09-11 1:03 ` Johnny Richard [this message]
2024-09-11 1:03 ` [PATCH olang v1 2/2] parser: add var definition and reference support Johnny Richard
2024-09-10 23:05 ` [olang/patches/.build.yml] build success builds.sr.ht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240911010517.196175-2-johnny@johnnyrichard.com \
--to=johnny@johnnyrichard.com \
--cc=~johnnyrichard/olang-devel@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox