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] parser: abort when parser identifies a syntax error
Date: Fri,  8 Mar 2024 21:52:22 +0100	[thread overview]
Message-ID: <20240308205358.1046108-1-johnny@johnnyrichard.com> (raw)

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


             reply	other threads:[~2024-03-08 19:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08 20:52 Johnny Richard [this message]
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

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=20240308205358.1046108-1-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