ParseKit developer is here.
Unfortunately, in ParseKit there is no βfreeβ mechanism that will return this data itself.
However, this is exactly the task with which ParseKit is developed / is well suited. But you must write the code yourself. Something like this will work:
First, slightly modify the grammar to include the named production for 'beer' . This will simplify the callback:
@start = sentence+; sentence = beer container; beer = 'beer'; container = 'bottle' | 'cup';
Then do the assembler callback for beer production.
- (void)parser:(PKParser *)p didMatchBeer:(PKAssembly *)a {
Your client or driver code should look like this:
PKParser *p = [PKParserFactory parserFromGrammar:g assembler:a]; PKAssembly *input = [PKAssembly assemblyWithString:@"beer"]; // get this string from the user in reality PKAssembly *result = [p bestMatchFor:input]; NSArray *completions = result.target;
This should give you an idea of ββhow these types of things can be implemented with ParseKit. For such a small example, this solution may look like an overkill (and probably this). But for a great example in the real world, this would be a very powerful and elegant autocomplete solution.
source share