public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: Johnny Richard <johnny@johnnyrichard.com>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Johnny Richard <johnny@johnnyrichard.com>
Subject: [PATCH olang v1 2/3] lexer: add token comma
Date: Tue, 24 Sep 2024 00:19:59 +0200	[thread overview]
Message-ID: <20240923222229.151017-3-johnny@johnnyrichard.com> (raw)
In-Reply-To: <20240923222229.151017-1-johnny@johnnyrichard.com>

Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
 src/lexer.c                            |  6 ++++
 src/lexer.h                            |  1 +
 tests/olc/0027_function_with_params.ol | 41 ++++++++++++++++++++++++++
 3 files changed, 48 insertions(+)
 create mode 100644 tests/olc/0027_function_with_params.ol

diff --git a/src/lexer.c b/src/lexer.c
index ebc21b7..6fe0151 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -227,6 +227,11 @@ lexer_next_token(lexer_t *lexer, token_t *token)
                 lexer_skip_char(lexer);
                 return;
             }
+            case ',': {
+                lexer_init_char_value_token(lexer, token, TOKEN_COMMA);
+                lexer_skip_char(lexer);
+                return;
+            }
             case '{': {
                 lexer_init_char_value_token(lexer, token, TOKEN_OCURLY);
                 lexer_skip_char(lexer);
@@ -289,6 +294,7 @@ static char *token_kind_str_table[] = {
     [TOKEN_OPAREN] = "(",
     [TOKEN_CPAREN] = ")",
     [TOKEN_COLON] = ":",
+    [TOKEN_COMMA] = ",",
     [TOKEN_OCURLY] = "{",
     [TOKEN_CCURLY] = "}",
     [TOKEN_PLUS] = "+",
diff --git a/src/lexer.h b/src/lexer.h
index 717d21d..2746e3e 100644
--- a/src/lexer.h
+++ b/src/lexer.h
@@ -73,6 +73,7 @@ typedef enum token_kind
     TOKEN_OPAREN,
     TOKEN_CPAREN,
     TOKEN_COLON,
+    TOKEN_COMMA,
     TOKEN_OCURLY,
     TOKEN_CCURLY,
     TOKEN_EOF
diff --git a/tests/olc/0027_function_with_params.ol b/tests/olc/0027_function_with_params.ol
new file mode 100644
index 0000000..f70fe7c
--- /dev/null
+++ b/tests/olc/0027_function_with_params.ol
@@ -0,0 +1,41 @@
+# 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(argc: u8, argv: u64): u8 {
+  return 0
+}
+
+# TEST test_contains_tokens WITH
+# ./0027_function_with_params.ol:16:1: <fn>
+# ./0027_function_with_params.ol:16:4: <identifier>
+# ./0027_function_with_params.ol:16:8: <(>
+# ./0027_function_with_params.ol:16:9: <identifier>
+# ./0027_function_with_params.ol:16:13: <:>
+# ./0027_function_with_params.ol:16:15: <identifier>
+# ./0027_function_with_params.ol:16:17: <,>
+# ./0027_function_with_params.ol:16:19: <identifier>
+# ./0027_function_with_params.ol:16:23: <:>
+# ./0027_function_with_params.ol:16:25: <identifier>
+# ./0027_function_with_params.ol:16:28: <)>
+# ./0027_function_with_params.ol:16:29: <:>
+# ./0027_function_with_params.ol:16:31: <identifier>
+# ./0027_function_with_params.ol:16:34: <{>
+# ./0027_function_with_params.ol:16:35: <line_feed>
+# ./0027_function_with_params.ol:17:3: <return>
+# ./0027_function_with_params.ol:17:10: <number>
+# ./0027_function_with_params.ol:17:11: <line_feed>
+# ./0027_function_with_params.ol:18:1: <}>
+# END
+
-- 
2.46.0


  parent reply	other threads:[~2024-09-23 22:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-23 22:19 [PATCH olang v1 0/3] parse function definition params Johnny Richard
2024-09-23 22:19 ` [PATCH olang v1 1/3] spec: add function params and function call Johnny Richard
2024-09-23 22:19 ` Johnny Richard [this message]
2024-09-23 22:23   ` [olang/patches/.build.yml] build success builds.sr.ht
2024-09-23 22:20 ` [PATCH olang v1 3/3] parser: parse function params Johnny Richard
2024-09-24  8:03 ` [PATCH olang v1 0/3] parse function definition params Carlos Maniero

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=20240923222229.151017-3-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