From: Johnny Richard <johnny@johnnyrichard.com>
To: Carlos Maniero <carlos@maniero.me>
Cc: ~johnnyrichard/olang-devel@lists.sr.ht
Subject: Re: [PATCH olang v2 1/3] lexer: add tokenize support to binary op tokens
Date: Mon, 18 Mar 2024 09:49:07 +0100 [thread overview]
Message-ID: <7cluu7ds2dietj2akdocfng6xd67wbc3eb2w2m3n46lu3ukcge@ophga22ly6wa> (raw)
In-Reply-To: <CZWGA19PG4DZ.1KWSAW2TV1XKJ@maniero.me>
On Sun, Mar 17, 2024 at 09:30:34PM -0300, Carlos Maniero wrote:
> > + case '=': {
> > + size_t start_offset = lexer->offset;
> > +
> > + if (lexer_peek_next_char(lexer) == '=') {
> > + lexer_skip_char(lexer);
> > + lexer_skip_char(lexer);
> > + lexer_init_str_value_token(lexer, token, TOKEN_CMP_EQ, start_offset);
> > + return;
> > + }
> > +
> > + lexer_init_char_value_token(lexer, token, TOKEN_EQ);
> > + lexer_skip_char(lexer);
> > + return;
> > + }
>
> We could apply the *maximal munch* [1] here avoiding looking to the
> future by skipping the char right after founding it:
Thanks, I kind agree on removing the necessity of lookahead here.
>
> + case '=': {
> + size_t start_offset = lexer->offset;
> + lexer_skip_char(lexer);
> +
> + if (lexer_current_char(lexer) == '=') {
> + lexer_skip_char(lexer);
> + lexer_init_str_value_token(lexer, token, TOKEN_CMP_EQ, start_offset);
> + return;
> + }
> +
> + lexer_init_char_value_token(lexer, token, TOKEN_EQ);
This function expect the offset being point to the char in question. In
your solution we already moved the offset.
I solution for this problem would replace the /lexer_init_char_value_token/ with
/lexer_init_str_value_token/. I have sent a new revision for this patch
with the correction.
> + lexer_skip_char(lexer);
This solution is moving twice to consume a single char.
> + return;
> + }
>
> I know it is a silly change, but this help us to keep the parsing
> process as deterministic as possible.
I don't think it's a silly change, that's a nice improvement, thanks for
suggesting this change.
next prev parent reply other threads:[~2024-03-18 7:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-17 21:29 [PATCH olang v2 0/3] frontend: add binary operation expr support Johnny Richard
2024-03-17 21:29 ` [PATCH olang v2 1/3] lexer: add tokenize support to binary op tokens Johnny Richard
2024-03-18 0:30 ` Carlos Maniero
2024-03-18 8:49 ` Johnny Richard [this message]
2024-03-17 21:29 ` [PATCH olang v2 2/3] ast: create binary operation ast node Johnny Richard
2024-03-17 21:29 ` [PATCH olang v2 3/3] parser: add all binary operation expressions Johnny Richard
2024-03-17 20:37 ` [olang/patches/.build.yml] build success builds.sr.ht
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=7cluu7ds2dietj2akdocfng6xd67wbc3eb2w2m3n46lu3ukcge@ophga22ly6wa \
--to=johnny@johnnyrichard.com \
--cc=carlos@maniero.me \
--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