У меня есть следующий очень простой (тестовый) файл грамматики
@start = expression+;
expression = keyword | otherWord;
otherWord = Word;
keyword = a | the;
a = 'a';
the = 'the';
Затем я запускаю следующий код:
// Grammer contains the contents of the above grammer file.
PKParser *parser = [[PKParserFactory factory] parserFromGrammar:grammer assembler:self];
NSString *s = @"The parrot";
[parser parse:s];
PKReleaseSubparserTree(parser);
И следующие методы:
- (void)didMatchA:(PKAssembly *)a{
[self log:a type:@"didMatchA "];
}
- (void)didMatchThe:(PKAssembly *)a{
[self log:a type:@"didMatchThe "];
}
- (void)didMatchKeyword:(PKAssembly *)a{
[self log:a type:@"didMatchKeyword "];
}
- (void)didMatchExpression:(PKAssembly *)a{
[self log:a type:@"didMatchExpression "];
}
- (void)didMatchOtherWord:(PKAssembly *)a{
[self log:a type:@"didMatchOtherWord "];
}
-(void) log:(PKAssembly *) assembly type:(NSString *) type{
PKToken * token = [assembly top];
NSLog(@"Method: [%@], token: %@, assembly: %@", type, token, assembly);
}
И, наконец, я получаю следующие сообщения в журнале:
[1] Method: [didMatchThe ], token: The, assembly: [The]The^parrot
[2] Method: [didMatchKeyword ], token: The, assembly: [The]The^parrot
[3] Method: [didMatchOtherWord ], token: The, assembly: [The]The^parrot
[4] Method: [didMatchExpression ], token: The, assembly: [The]The^parrot
[5] Method: [didMatchExpression ], token: The, assembly: [The]The^parrot
[6] Method: [didMatchOtherWord ], token: parrot, assembly: [The, parrot]The/parrot^
[7] Method: [didMatchExpression ], token: parrot, assembly: [The, parrot]The/parrot^
Это имеет смысл, но я не могу понять, почему происходит% 5.Я действительно хотел бы иметь возможность удалить двойное соответствие, чтобы ключевые слова, такие как триггер "The", делали didMatchThe и not didMatchKeyword.
К сожалению, doco для parsekit, кажется, не существует в синтаксисе грамматики икак он решает вызвать методы.Да, я также проверял исходный код: -)
Кто-нибудь имел опыт работы с parsekit и может пролить свет на это?