public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
* [olang/patches/.build.yml] build failed
  2024-03-08 20:52 [PATCH olang] parser: abort when parser identifies a syntax error Johnny Richard
@ 2024-03-08 19:54 ` builds.sr.ht
  2024-03-08 21:03 ` [PATCH olang] parser: abort when parser identifies a syntax error Johnny Richard
  2024-03-08 22:52 ` Carlos Maniero
  2 siblings, 0 replies; 4+ messages in thread
From: builds.sr.ht @ 2024-03-08 19:54 UTC (permalink / raw)
  To: Johnny Richard; +Cc: ~johnnyrichard/olang-devel

olang/patches/.build.yml: FAILED in 30s

[parser: abort when parser identifies a syntax error][0] from [Johnny Richard][1]

[0]: https://lists.sr.ht/~johnnyrichard/olang-devel/patches/50088
[1]: mailto:johnny@johnnyrichard.com

✗ #1164684 FAILED olang/patches/.build.yml https://builds.sr.ht/~johnnyrichard/job/1164684

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH olang] parser: abort when parser identifies a syntax error
@ 2024-03-08 20:52 Johnny Richard
  2024-03-08 19:54 ` [olang/patches/.build.yml] build failed builds.sr.ht
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Johnny Richard @ 2024-03-08 20:52 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel; +Cc: Johnny Richard

The current implementation fails with segfault when the parser finds a
syntax error.  We are not prepared to recover from errors at this
moment.

This patch aborts when found an expected token and it also improves the
error output by showing the wrong token string value.

Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
Let's postpone syntax error recovery.  I want to keep things simple
right now.

 src/parser.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/parser.c b/src/parser.c
index a9699be..cfea9ef 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -173,18 +173,18 @@ expected_token(parser_t *parser, token_t *token, token_kind_t expected_kind)
 
     if (token->kind != expected_kind) {
         fprintf(stderr,
-                "%s:%lu:%lu: error: got <%s> token but expect <%s>\n",
+                "%s:%lu:%lu: error: got '"SV_FMT"' token but expect <%s>\n",
                 parser->file_path,
                 token->location.row + 1,
                 (token->location.offset - token->location.bol) + 1,
-                token_kind_to_cstr(token->kind),
+                SV_ARG(token->value),
                 token_kind_to_cstr(expected_kind));
 
         string_view_t line = lexer_get_token_line(parser->lexer, token);
         fprintf(stderr, "" SV_FMT "\n", SV_ARG(line));
         fprintf(stderr, "%*s\n", (int)(token->location.offset - token->location.bol + 1), "^");
 
-        return false;
+        exit(EXIT_FAILURE);
     }
     return true;
 }

base-commit: 35f594370443a2b9f73d2d2ebe573b4cab472be6
-- 
2.44.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH olang] parser: abort when parser identifies a syntax error
  2024-03-08 20:52 [PATCH olang] parser: abort when parser identifies a syntax error Johnny Richard
  2024-03-08 19:54 ` [olang/patches/.build.yml] build failed builds.sr.ht
@ 2024-03-08 21:03 ` Johnny Richard
  2024-03-08 22:52 ` Carlos Maniero
  2 siblings, 0 replies; 4+ messages in thread
From: Johnny Richard @ 2024-03-08 21:03 UTC (permalink / raw)
  To: ~johnnyrichard/olang-devel

Ops... the lint failing again...

Please consider the following fixup:

-------->8--------
Subject: [PATCH olang] fixup! parser: abort when parser identifies a syntax
 error


diff --git a/src/parser.c b/src/parser.c
index cfea9ef..3316e07 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -173,7 +173,7 @@ expected_token(parser_t *parser, token_t *token, token_kind_t expected_kind)
 
     if (token->kind != expected_kind) {
         fprintf(stderr,
-                "%s:%lu:%lu: error: got '"SV_FMT"' token but expect <%s>\n",
+                "%s:%lu:%lu: error: got '" SV_FMT "' token but expect <%s>\n",
                 parser->file_path,
                 token->location.row + 1,
                 (token->location.offset - token->location.bol) + 1,



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH olang] parser: abort when parser identifies a syntax error
  2024-03-08 20:52 [PATCH olang] parser: abort when parser identifies a syntax error Johnny Richard
  2024-03-08 19:54 ` [olang/patches/.build.yml] build failed builds.sr.ht
  2024-03-08 21:03 ` [PATCH olang] parser: abort when parser identifies a syntax error Johnny Richard
@ 2024-03-08 22:52 ` Carlos Maniero
  2 siblings, 0 replies; 4+ messages in thread
From: Carlos Maniero @ 2024-03-08 22:52 UTC (permalink / raw)
  To: Johnny Richard, ~johnnyrichard/olang-devel

The patch was applied. Thanks.

To git.sr.ht:~johnnyrichard/olang
   35f5943..4684a78  main -> main

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-08 22:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08 20:52 [PATCH olang] parser: abort when parser identifies a syntax error Johnny Richard
2024-03-08 19:54 ` [olang/patches/.build.yml] build failed builds.sr.ht
2024-03-08 21:03 ` [PATCH olang] parser: abort when parser identifies a syntax error Johnny Richard
2024-03-08 22:52 ` 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