Skip to content

fix: Handle upper-scope generics in __AnonymousParselet__ - #171

Merged
phorward merged 5 commits into
tokay-lang:mainfrom
phorward:fix-130-again2
Nov 18, 2025
Merged

fix: Handle upper-scope generics in __AnonymousParselet__#171
phorward merged 5 commits into
tokay-lang:mainfrom
phorward:fix-130-again2

Conversation

@phorward

Copy link
Copy Markdown
Member

The fix #166 was not complete to resolve #130, when it came to resolving generics inside of anonymous parselets inside parselets defining the generics.

The current compiler implementation is a little bit error-prone. This PR introduces a fix that handled the case reproducible by

Until : @<P, Escape: Void, empty: true> {
    # stop conddition, when P is matched
    Peek<P>  if empty accept $0 else if $0 accept $0 else reject

    # repeat parselet on escaped P or any Char
    (Escape P | Char)  repeat

    # Anything else is rejected
    reject
}

String : @<
    Start,            # start sequence
    End: Void,        # end sequence, fallback is Start
    Escape: '\\',     # escape sequence for escaping End
    empty: true,      # allow empty strings
> {
    Start Until<(End | Start), Escape, empty> (End | Start)  $2
}

print(String<'"'>)

which is a development step case of #133 and the input

println!("Hello Rust");
console.log('Hello JS');
println!("Hello\n\"Rust1\"");
println!("Hello\n'Rust2'");
console.log('Hello\n\'JS\'');
empty "" or
multiline "Hello
World"
unfinished "Hello
xdoofx

... and detect problem, which is that inline parselets don't have generics setting, so both the fast-lane and the final check fails.
Removing these checks will build the correct program, which is the case with this commit.
@phorward phorward added this to the v0.7 milestone Nov 18, 2025
@phorward phorward self-assigned this Nov 18, 2025
@phorward
phorward merged commit bb4774d into tokay-lang:main Nov 18, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Use of generic within implicit parselet fails to compile

1 participant