* [PATCH olang v1] fe: lexer: add single line comments support
@ 2024-03-28 15:58 Johnny Richard
2024-03-28 14:59 ` [olang/patches/.build.yml] build failed builds.sr.ht
2024-03-28 23:53 ` [PATCH olang v1] fe: lexer: add single line comments support Carlos Maniero
0 siblings, 2 replies; 4+ messages in thread
From: Johnny Richard @ 2024-03-28 15:58 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Johnny Richard
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
examples/main_exit.ol | 3 +++
src/lexer.c | 7 +++++++
src/parser.c | 1 +
tests/integration/cli_test.c | 31 +++++++++++++++++--------------
4 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/examples/main_exit.ol b/examples/main_exit.ol
index c86fc68..8952017 100644
--- a/examples/main_exit.ol
+++ b/examples/main_exit.ol
@@ -1,3 +1,6 @@
+# Expected:
+# - output: ""
+
fn main(): u32 {
return 0
}
diff --git a/src/lexer.c b/src/lexer.c
index 801e4d0..684cad1 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -76,6 +76,13 @@ lexer_next_token(lexer_t *lexer, token_t *token)
}
while (lexer_is_not_eof(lexer)) {
+ if (current_char == '#') {
+ while (current_char != '\n' && lexer_is_not_eof(lexer)) {
+ lexer_skip_char(lexer);
+ current_char = lexer_current_char(lexer);
+ }
+ }
+
if (isalpha(current_char)) {
size_t start_offset = lexer->offset;
while (isalnum(current_char) && lexer_is_not_eof(lexer)) {
diff --git a/src/parser.c b/src/parser.c
index 76ef91a..b800870 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -62,6 +62,7 @@ parser_init(parser_t *parser, lexer_t *lexer, arena_t *arena, char *file_path)
ast_node_t *
parser_parse_program(parser_t *parser)
{
+ skip_line_feeds(parser->lexer);
ast_node_t *fn = parser_parse_fn_definition(parser);
if (fn == NULL) {
return NULL;
diff --git a/tests/integration/cli_test.c b/tests/integration/cli_test.c
index d46471b..e7ae059 100644
--- a/tests/integration/cli_test.c
+++ b/tests/integration/cli_test.c
@@ -25,20 +25,23 @@ test_cli_dump_tokens_example_main_exit(const MunitParameter params[], void *user
cli_result_t compilation_result = cli_runner_compiler_dump_tokens("../../examples/main_exit.ol");
munit_assert_int(compilation_result.exec.exit_code, ==, 0);
munit_assert_string_equal(compilation_result.exec.stdout_buf,
- "../../examples/main_exit.ol:1:1: <fn>\n"
- "../../examples/main_exit.ol:1:4: <identifier>\n"
- "../../examples/main_exit.ol:1:8: <(>\n"
- "../../examples/main_exit.ol:1:9: <)>\n"
- "../../examples/main_exit.ol:1:10: <:>\n"
- "../../examples/main_exit.ol:1:12: <identifier>\n"
- "../../examples/main_exit.ol:1:16: <{>\n"
- "../../examples/main_exit.ol:1:17: <line_feed>\n"
- "../../examples/main_exit.ol:2:3: <return>\n"
- "../../examples/main_exit.ol:2:10: <number>\n"
- "../../examples/main_exit.ol:2:11: <line_feed>\n"
- "../../examples/main_exit.ol:3:1: <}>\n"
- "../../examples/main_exit.ol:3:2: <line_feed>\n"
- "../../examples/main_exit.ol:4:1: <EOF>\n");
+ "../../examples/main_exit.ol:1:12: <line_feed>\n"
+ "../../examples/main_exit.ol:2:16: <line_feed>\n"
+ "../../examples/main_exit.ol:3:1: <line_feed>\n"
+ "../../examples/main_exit.ol:4:1: <fn>\n"
+ "../../examples/main_exit.ol:4:4: <identifier>\n"
+ "../../examples/main_exit.ol:4:8: <(>\n"
+ "../../examples/main_exit.ol:4:9: <)>\n"
+ "../../examples/main_exit.ol:4:10: <:>\n"
+ "../../examples/main_exit.ol:4:12: <identifier>\n"
+ "../../examples/main_exit.ol:4:16: <{>\n"
+ "../../examples/main_exit.ol:4:17: <line_feed>\n"
+ "../../examples/main_exit.ol:5:3: <return>\n"
+ "../../examples/main_exit.ol:5:10: <number>\n"
+ "../../examples/main_exit.ol:5:11: <line_feed>\n"
+ "../../examples/main_exit.ol:6:1: <}>\n"
+ "../../examples/main_exit.ol:6:2: <line_feed>\n"
+ "../../examples/main_exit.ol:7:1: <EOF>\n");
return MUNIT_OK;
}
base-commit: 117a06874c48c64e8ad4befbab244670f4f9ca9c
--
2.44.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [olang/patches/.build.yml] build failed
2024-03-28 15:58 [PATCH olang v1] fe: lexer: add single line comments support Johnny Richard
@ 2024-03-28 14:59 ` builds.sr.ht
2024-03-28 16:46 ` Johnny Richard
2024-03-28 23:53 ` [PATCH olang v1] fe: lexer: add single line comments support Carlos Maniero
1 sibling, 1 reply; 4+ messages in thread
From: builds.sr.ht @ 2024-03-28 14:59 UTC (permalink / raw)
To: Johnny Richard; +Cc: ~johnnyrichard/olang-devel
olang/patches/.build.yml: FAILED in 36s
[fe: lexer: add single line comments support][0] from [Johnny Richard][1]
[0]: https://lists.sr.ht/~johnnyrichard/olang-devel/patches/50503
[1]: mailto:johnny@johnnyrichard.com
✗ #1181030 FAILED olang/patches/.build.yml https://builds.sr.ht/~johnnyrichard/job/1181030
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [olang/patches/.build.yml] build failed
2024-03-28 14:59 ` [olang/patches/.build.yml] build failed builds.sr.ht
@ 2024-03-28 16:46 ` Johnny Richard
0 siblings, 0 replies; 4+ messages in thread
From: Johnny Richard @ 2024-03-28 16:46 UTC (permalink / raw)
To: builds.sr.ht; +Cc: ~johnnyrichard/olang-devel
On Thu, Mar 28, 2024 at 02:59:02PM +0000, builds.sr.ht wrote:
> olang/patches/.build.yml: FAILED in 36s
>
> [fe: lexer: add single line comments support][0] from [Johnny Richard][1]
>
> [0]: https://lists.sr.ht/~johnnyrichard/olang-devel/patches/50503
> [1]: mailto:johnny@johnnyrichard.com
>
> ✗ #1181030 FAILED olang/patches/.build.yml https://builds.sr.ht/~johnnyrichard/job/1181030
This build is failing due to a clang bumped version on Arch Linux
repositories. It was a major bump from 16 to 17 (it has breaking
changes).
We can solve this problem by fixing the version or by bumping our clang
locally. I will upgrade my clang meanwhile.
Please, consider the patch to fix it.
---->8----
Subject: [PATCH olang] fixup! fe: lexer: add single line comments support
diff --git a/src/pretty_print_ast.c b/src/pretty_print_ast.c
index e950796..129f090 100644
--- a/src/pretty_print_ast.c
+++ b/src/pretty_print_ast.c
@@ -26,7 +26,7 @@
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_RESET "\x1b[0m"
-#define PP_IS_BIT_SET(data, index) ((data)&1 << index)
+#define PP_IS_BIT_SET(data, index) ((data) & 1 << index)
typedef struct pretty_print_node
{
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH olang v1] fe: lexer: add single line comments support
2024-03-28 15:58 [PATCH olang v1] fe: lexer: add single line comments support Johnny Richard
2024-03-28 14:59 ` [olang/patches/.build.yml] build failed builds.sr.ht
@ 2024-03-28 23:53 ` Carlos Maniero
1 sibling, 0 replies; 4+ messages in thread
From: Carlos Maniero @ 2024-03-28 23:53 UTC (permalink / raw)
To: Johnny Richard, ~johnnyrichard/olang-devel
Nice work! Thanks.
To git.sr.ht:~johnnyrichard/olang
804cea4..ab7a546 main -> main
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-28 23:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 15:58 [PATCH olang v1] fe: lexer: add single line comments support Johnny Richard
2024-03-28 14:59 ` [olang/patches/.build.yml] build failed builds.sr.ht
2024-03-28 16:46 ` Johnny Richard
2024-03-28 23:53 ` [PATCH olang v1] fe: lexer: add single line comments support 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