* [olang/patches/.build.yml] build success
2024-10-08 15:53 [PATCH olang v1] lexer: add 'while' keyword token Johnny Richard
@ 2024-10-08 13:54 ` builds.sr.ht
2024-10-08 15:35 ` [PATCH olang] fixup! lexer: add 'while' keyword token Carlos Maniero
2024-10-08 15:40 ` [PATCH olang v1] " Carlos Maniero
2 siblings, 0 replies; 4+ messages in thread
From: builds.sr.ht @ 2024-10-08 13:54 UTC (permalink / raw)
To: Johnny Richard; +Cc: ~johnnyrichard/olang-devel
olang/patches/.build.yml: SUCCESS in 21s
[lexer: add 'while' keyword token][0] from [Johnny Richard][1]
[0]: https://lists.sr.ht/~johnnyrichard/olang-devel/patches/55382
[1]: mailto:johnny@johnnyrichard.com
✓ #1346415 SUCCESS olang/patches/.build.yml https://builds.sr.ht/~johnnyrichard/job/1346415
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH olang] fixup! lexer: add 'while' keyword token
2024-10-08 15:53 [PATCH olang v1] lexer: add 'while' keyword token Johnny Richard
2024-10-08 13:54 ` [olang/patches/.build.yml] build success builds.sr.ht
@ 2024-10-08 15:35 ` Carlos Maniero
2024-10-08 15:40 ` [PATCH olang v1] " Carlos Maniero
2 siblings, 0 replies; 4+ messages in thread
From: Carlos Maniero @ 2024-10-08 15:35 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Carlos Maniero
---
tests/olc/0030_while_statement.ol | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/olc/0030_while_statement.ol b/tests/olc/0030_while_statement.ol
index eb47ae5..1ebdc5a 100644
--- a/tests/olc/0030_while_statement.ol
+++ b/tests/olc/0030_while_statement.ol
@@ -20,7 +20,7 @@ fn main(): u32 {
i = i + 1
}
- return i
+ return i
}
# XTEST test_compile(exit_code=0)
--
2.46.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH olang v1] lexer: add 'while' keyword token
2024-10-08 15:53 [PATCH olang v1] lexer: add 'while' keyword token Johnny Richard
2024-10-08 13:54 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-08 15:35 ` [PATCH olang] fixup! lexer: add 'while' keyword token Carlos Maniero
@ 2024-10-08 15:40 ` Carlos Maniero
2 siblings, 0 replies; 4+ messages in thread
From: Carlos Maniero @ 2024-10-08 15:40 UTC (permalink / raw)
To: Johnny Richard, ~johnnyrichard/olang-devel
Applied with a minor fixup.
To git.sr.ht:~johnnyrichard/olang
3780214..5a3c6d8 main -> main
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH olang v1] lexer: add 'while' keyword token
@ 2024-10-08 15:53 Johnny Richard
2024-10-08 13:54 ` [olang/patches/.build.yml] build success builds.sr.ht
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Johnny Richard @ 2024-10-08 15:53 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Johnny Richard
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
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.
<block> ::= '{' <ows> <statement> <ows> (<end-of-statement> <ows> <statement> <ows>)* <end-of-statement>? <ows> '}'
<function-args> ::= <expression> (<ows> ',' <function-args>)*
<function-call> ::= <function-name> <ows> '(' ( <ows> | <ows> <function-args> <ows> ) ')'
-<statement> ::= <common-statement> | <if-statement> | <return-statement> | <function-call>
+<statement> ::= <common-statement> | <if-statement> | <while-statement> | <return-statement> | <function-call>
<if-statement> ::= 'if' <ws> <expression> <ows> <block>
+<while-statement> ::= 'while' <ws> <expression> <ows> <block>
<return-statement> ::= 'return' <ws> <expression>
(* 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 <https://www.gnu.org/licenses/>.
+
+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 <name:main> <return:u32>
+# `-Block
+# `-Return_Statement
+# `-Literal <kind:u32> <value:0>
+# END
+#
+# TEST test_contains_tokens WITH
+# ./0030_while_statement.ol:19:3: <while>
+# END
base-commit: dbbfdf2acab2b022cc9f0157d4341478d82b8838
--
2.46.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-08 15:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-08 15:53 [PATCH olang v1] lexer: add 'while' keyword token Johnny Richard
2024-10-08 13:54 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-08 15:35 ` [PATCH olang] fixup! lexer: add 'while' keyword token Carlos Maniero
2024-10-08 15:40 ` [PATCH olang v1] " Carlos Maniero
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