Skip to content

PKAlternation + PKAny Repetition = Random Results #22

Description

@agg23

Running the following parser results in some random results. The result occasionally contains "search" and/or "for", assumedly because of the PKAny Repetition immediately before and after the PKAlternation. Is there any way to resolve this or am I stuck with it?

    NSString *string = @"google search for ducky ducky super ducky duck";
    PKSequence *parser = [PKSequence sequence];

    PKRepetition *repetitionTest = [PKRepetition repetitionWithSubparser:[[PKAny any] discard]];

    [parser add:repetitionTest];

    PKAlternation *optionalSearch = [PKAlternation alternation];
    [optionalSearch add:[[PKEmpty empty] discard]];
    [optionalSearch add:[[PKLiteral literalWithString:@"search"] discard]];
    [parser add:optionalSearch];

    [parser add:[[PKLiteral literalWithString:@"google"] discard]];
    [parser add:optionalSearch];

    PKAlternation *optionalFor = [PKAlternation alternation];
    [optionalFor add:[[PKEmpty empty] discard]];
    [optionalFor add:[[PKLiteral literalWithString:@"for"] discard]];

    [parser add:optionalFor];

    PKRepetition *searchTerm = [PKRepetition repetitionWithSubparser:[PKAny any]];
    [parser add:searchTerm];
    PKAssembly *result = [parser bestMatchFor:[PKTokenAssembly assemblyWithString:string]]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions