Inherits from NSObject
Conforms to CPTokenRecogniser
Declared in CPKeywordRecogniser.h
CPKeywordRecogniser.m

Overview

The CPKeywordRecogniser class attempts to recognise a specific keyword in a token stream.

A keyword recogniser attempts to recognise a specific word or set of symbols. Keyword recognisers can also check that the keyword is not followed by specific characters in order to stop it recognising the beginnings of words.

This recogniser produces CPKeywordTokens.

Tasks

Creating and Initialising a Keyword Recogniser

Configuring a Keyword Recogniser

Other Methods

Properties

invalidFollowingCharacters

A set of characters that may not follow the keyword.

@property (readwrite, retain, nonatomic) NSCharacterSet *invalidFollowingCharacters

Discussion

A set of characters that may not follow the keyword.

Declared In

CPKeywordRecogniser.h

keyword

The keyword that the recogniser should attempt to recognise.

@property (readwrite, retain, nonatomic) NSString *keyword

Discussion

The keyword that the recogniser should attempt to recognise.

Declared In

CPKeywordRecogniser.h

Class Methods

recogniserForKeyword:

Creates a Keyword Recogniser for a specific keyword.

+ (id)recogniserForKeyword:(NSString *)keyword

Parameters

keyword

The keyword to recognise.

Return Value

Returns a keyword recogniser for the passed keyword.

Discussion

Creates a Keyword Recogniser for a specific keyword.

Declared In

CPKeywordRecogniser.h

recogniserForKeyword:invalidFollowingCharacters:

Creates a Keyword Recogniser for a specific keyword.

+ (id)recogniserForKeyword:(NSString *)keyword invalidFollowingCharacters:(NSCharacterSet *)invalidFollowingCharacters

Parameters

keyword

The keyword to recognise.

invalidFollowingCharacters

A set of characters that may not follow the keyword in the string being tokenised.

Return Value

Returns a keyword recogniser for the passed keyword.

Discussion

Creates a Keyword Recogniser for a specific keyword.

Declared In

CPKeywordRecogniser.h

Instance Methods

initWithKeyword:

Initialises a Keyword Recogniser to recognise a specific keyword.

- (id)initWithKeyword:(NSString *)keyword

Parameters

keyword

The keyword to recognise.

Return Value

Returns the keyword recogniser initialised to recognise the passed keyword.

Discussion

Initialises a Keyword Recogniser to recognise a specific keyword.

Declared In

CPKeywordRecogniser.h

initWithKeyword:invalidFollowingCharacters:

Initialises a Keyword Recogniser to recognise a specific keyword.

- (id)initWithKeyword:(NSString *)keyword invalidFollowingCharacters:(NSCharacterSet *)invalidFollowingCharacters

Parameters

keyword

The keyword to recognise.

invalidFollowingCharacters

A set of characters that may not follow the keyword in the string being tokenised.

Return Value

Returns the keyword recogniser initialised to recognise the passed keyword.

Discussion

Initialises a Keyword Recogniser to recognise a specific keyword.

Declared In

CPKeywordRecogniser.h

recogniseTokenInString:currentTokenPosition:

Attempts to recognise a token at tokenPosition in tokenString.

- (CPToken *)recogniseTokenInString:(NSString *)tokenString currentTokenPosition:(NSUInteger *)tokenPosition

Parameters

tokenString

The string in which to recognise tokens.

tokenPosition

The position at which to try to find the token. On output, the position after the recognised token.

Return Value

Returns the token recognised.

Discussion

Attempts to recognise a token at tokenPosition in tokenString.

If a token is successfully recognised, it should be returned, and tokenPosition advanced to after the consumed characters. If no valid token is found nil must be returned instead, and tokenPosition left unchanged.

Declared In

CPTokenRecogniser.h