Skip to content

Add more tests of lexer's skipToLeadingKeyword behavior#1971

Merged
Rangi42 merged 1 commit into
gbdev:masterfrom
Rangi42:more-tests
May 9, 2026
Merged

Add more tests of lexer's skipToLeadingKeyword behavior#1971
Rangi42 merged 1 commit into
gbdev:masterfrom
Rangi42:more-tests

Conversation

@Rangi42
Copy link
Copy Markdown
Contributor

@Rangi42 Rangi42 commented May 9, 2026

These three tests are related to how "skipping" and "capturing" work. ("Skipping" occurs when an untaken if/elif/else needs to skip to the next elif/else/endc, or when a break inside a rept/for skips to its endr. "Capturing" occurs when a rept/for or a macro body stores its contents up to its endr/endm.)

Skipping and capturing both use the skipToLeadingKeyword function to skip lines until finding one that starts with an appropriate "ending" keyword (endc/endr/endm/etc). Expansions are disabled during this process, so you can't do e.g. def s equs "endr" and then {s} to end a loop.

"Blue-painting", however, does occur while skipping and capturing (naturally -- it's a low-level behavior of peek() and skipChar(), which are used by skipToLeadingKeyword just like everywhere else in the lexer that advances through the assembly code). So to detect the ending keyword, the character after the ending keyword has already been peeked and thus painted blue -- and this happens while expansions are disabled, so even if that character is a { brace it won't start an interpolation, nor will \ start a macro argument.

Currently the Rust rewrite does not blue-paint during its equivalent of skipping/capturing, so it handles these tests differently (see https://codeberg.org/ISSOtm/rsgbds/issues/53). This is considered a bug, but we may want to further change/refine its behavior in ways inconsistent with how C++ RGBASM currently behaves.

These tests are also intended to allow more confidently optimizing skipToLeadingKeyword, since it's a fairly significant part of the overall runtime on real-world projects (see #1968).

@Rangi42 Rangi42 added this to the 1.0.2 milestone May 9, 2026
@Rangi42 Rangi42 requested a review from ISSOtm May 9, 2026 19:35
@Rangi42 Rangi42 added tests This affects the test suite rgbasm This affects RGBASM labels May 9, 2026
Copy link
Copy Markdown
Member

@ISSOtm ISSOtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behaviour looks fine, thanks :)

@Rangi42 Rangi42 merged commit 358e8fe into gbdev:master May 9, 2026
27 checks passed
@Rangi42 Rangi42 deleted the more-tests branch May 9, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rgbasm This affects RGBASM tests This affects the test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants