public inbox for ~johnnyrichard/olang-devel@lists.sr.ht
 help / color / mirror / code / Atom feed
From: "Carlos Maniero" <carlos@maniero.me>
To: "Johnny Richard" <johnny@johnnyrichard.com>,
	<~johnnyrichard/olang-devel@lists.sr.ht>
Subject: Re: [PATCH olang v3 2/2] lexer: create --dump-tokens cli command
Date: Mon, 19 Feb 2024 00:30:36 -0300	[thread overview]
Message-ID: <CZ8QKMHJU0JB.2GEWC56YMGTMN@maniero.me> (raw)
In-Reply-To: <20240219013843.15707-4-johnny@johnnyrichard.com>

Nice work man! I just have a few comments:

> +    while (token.kind != TOKEN_EOF) {
> +        printf("%s:%lu:%lu: <%s>\n",
> +               opts.file_path,
> +               token.location.row + 1,
> +               (token.location.offset - token.location.bol) + 1,
> +               token_kind_to_cstr(token.kind));
> +        lexer_next_token(&lexer, &token);
> +    }
IMO, EOF token should be printed to, as it is a token returned by the
lexer.

> +    if (lexer_is_eof(lexer)) {
> +        *token = (token_t){ .kind = TOKEN_EOF };
> +        return;
> +    }

Missing token location. I know it seems silly to have the EOF position.
But it is useful for parser error messages such as "expected } found
EOF". Remember that this code appears twice, before and after the while.


> +lexer_next_char(lexer_t *lexer)

s/lexer_next_char/lexer_current_char
the current name of the function give me the impression that it changes
the offset.

> +    if (lexer->source.chars[lexer->offset] == '\n') {
call lexer_next_char/lexer_current_char instead.

> +static bool
> +_isspace(char c)
> +{
> +    return c == ' ' || c == '\f' || c == '\r' || c == '\t' || c == '\v';
> +}

What do you think about just add the *\n* guard before calling the
*isspace* that way it is clean for someone reading the code why you have
to reimplement the function.

  return c != '\n' && isspace(c);

> +static void
> +lexer_init_char_token(lexer_t *lexer, token_t *token, token_kind_t kind);
> +
> +static void
> +lexer_init_str_token(lexer_t *lexer, token_t *token, token_kind_t kind, size_t start_offset);
> +
> +static token_kind_t
> +lexer_str_to_token_kind(string_view_t text);

I don't have a suggestion to it, but IMO *lexer_init_char_token* and
*lexer_init_str_token* makes me feel we are initializing a "string" and
a 'char" token. But I haven't a better name, I thought calling it
*lexer_init_single_char_token* and *lexer_init_multi_char_token* but
IDK if it is really better.

  parent reply	other threads:[~2024-02-19  3:30 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19  1:38 [PATCH olang v3 0/2] Create --dump-tokens on compiler cli Johnny Richard
2024-02-19  1:38 ` [PATCH olang v3 1/2] utils: create string_view data structure Johnny Richard
2024-02-19  1:44 ` [PATCH olang v3 2/2] lexer: create --dump-tokens cli command Johnny Richard
2024-02-19  0:47   ` [olang/patches/.build.yml] build success builds.sr.ht
2024-02-19  3:30   ` Carlos Maniero [this message]
2024-02-19 19:51     ` [PATCH olang v3 2/2] lexer: create --dump-tokens cli command Johnny Richard
2024-02-19 19:17       ` Carlos Maniero
2024-02-19 10:01   ` Carlos Maniero
2024-02-19 21:07 ` [PATCH olang v3 0/2] Create --dump-tokens on compiler cli Johnny Richard

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=CZ8QKMHJU0JB.2GEWC56YMGTMN@maniero.me \
    --to=carlos@maniero.me \
    --cc=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