Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with Repeat<P>: Match in Pos<P> sequence fails without severity #123

Closed
phorward opened this issue Oct 22, 2023 · 0 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@phorward
Copy link
Member

This is somehow complicated to describe, and only happens with #105 which becomes merged soon.

# cargo run -- fufu.tok -- "#"      # doesn't work
# cargo run -- fufu.tok -- "#lala"  # works!

Test : @{ '#' Char<^\n>* }
# Test : @{ '#' }  # works, because it's not a sequence

Test+ print("Never :-(")

Test+ (becoming Pos<Test>, which becomes Repeat<Test, min:1, max:void, blur:true> only is matched when additional chars are provided. This is, because the '#'-match will become void as simple matches have severity 0. Therefore, Repeat<P> fails at the position marked:

Repeat : @<
    P,          # Parselet
    min: 1,     # minimum occurence
    max: void,  # maximum occurence, void for unlimited
    blur: true  # result blurrying; empty list becomes void, one-item list becomes item
> {
    res = ()

    loop {
        P {
            res.push($1)  # <<<--- pushes void, which doesn't push
            if max && res.len == max break
        }

        if res.len < min reject   # <<<--- success, because res.len is 0, as no void is pushed
        break
    }

    if blur {
        if res.len == 0 {
            accept void
        }
        else if res.len == 1 {
            accept res[0]
        }
    }

    res
}

The problem at this point is: Input is consumed, but Repeat relies on the res-list. An additional variable could solve the problem, but is this the solution? Repeat must be implemented as optimal as possible.

@phorward phorward added the bug Something isn't working label Oct 22, 2023
@phorward phorward self-assigned this Oct 22, 2023
phorward added a commit to phorward/tokay that referenced this issue Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant