public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
* [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

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