CPTokeniserDelegate Protocol Reference
Conforms to | NSObject |
Declared in | CPTokeniser.h |
Overview
The delegate of a CPTokeniser must adopt the CPTokeniserDelegate protocol. This allows for customising if/when a tokeniser should produce a token.
Tasks
-
– tokeniser:shouldConsumeToken:
Determines whether a CPTokeniser should produce a token and consume the associated input string.
required method -
– tokeniser:willProduceToken:
Allows you to replace a taken in the tokeniser’s output stream.
-
– tokeniser:requestsToken:pushedOntoStream:
Requests that you push a token onto a tokeniser’s output stream. This allows you to replace the token with any others you choose, or not output the token at all.
-
– tokeniser:didNotFindTokenOnInput:position:error:
This method is called when no recogniser matches a token at the current position in the input stream. You must provide a new location in the input stream to start tokenising from again, or NSNotFound to stop the tokeniser. You may optionally provide an error message to attach to a CPErrorToken.
Instance Methods
tokeniser:didNotFindTokenOnInput:position:error:
This method is called when no recogniser matches a token at the current position in the input stream. You must provide a new location in the input stream to start tokenising from again, or NSNotFound to stop the tokeniser. You may optionally provide an error message to attach to a CPErrorToken.
- (NSUInteger)tokeniser:(CPTokeniser *)tokeniser didNotFindTokenOnInput:(NSString *)input position:(NSUInteger)position error:(NSString **)errorMessage
Parameters
- tokeniser
The CPTokeniser that could not match any token in the input stream.
- input
The input given to the tokeniser.
- position
The position in the input stream at which the tokeniser failed.
- errorMessage
A pointer to which you can write to provide an error message to output in an error token.
Return Value
Return a new position in the input to begin tokenising from. Return NSNotFound to request that the tokeniser stops.
Discussion
This method is called when no recogniser matches a token at the current position in the input stream. You must provide a new location in the input stream to start tokenising from again, or NSNotFound to stop the tokeniser. You may optionally provide an error message to attach to a CPErrorToken.
Declared In
CPTokeniser.h
tokeniser:requestsToken:pushedOntoStream:
Requests that you push a token onto a tokeniser’s output stream. This allows you to replace the token with any others you choose, or not output the token at all.
- (void)tokeniser:(CPTokeniser *)tokeniser requestsToken:(CPToken *)token pushedOntoStream:(CPTokenStream *)stream
Parameters
- tokeniser
The CPTokeniser that produced the token.
- token
The CPToken that the tokeniser has recognised.
- stream
The CPTokenStream the token should be pushed onto (if required).
Discussion
Requests that you push a token onto a tokeniser’s output stream. This allows you to replace the token with any others you choose, or not output the token at all.
Only one of this and tokeniser:willProduceToken: will be called. The tokeniser will attempt to call this method first.
Declared In
CPTokeniser.h
tokeniser:shouldConsumeToken:
Determines whether a CPTokeniser should produce a token and consume the associated input string.
- (BOOL)tokeniser:(CPTokeniser *)tokeniser shouldConsumeToken:(CPToken *)token
Parameters
- tokeniser
The CPTokeniser attempting to produce the token.
- token
The CPToken that the tokeniser has recognised.
Return Value
Return YES if the tokeniser should consume the token, NO otherwise.
Discussion
Determines whether a CPTokeniser should produce a token and consume the associated input string.
If this method returns NO, the CPTokeniser continues to attempt to recognise tokens at the same point in the input string with other token recognisers.
Declared In
CPTokeniser.h
tokeniser:willProduceToken:
Allows you to replace a taken in the tokeniser’s output stream.
- (NSArray *)tokeniser:(CPTokeniser *)tokeniser willProduceToken:(CPToken *)token
Parameters
- tokeniser
The CPTokeniser that will produce the token.
- token
The CPToken that the tokeniser has recognised.
Return Value
Return an array of CPToken objects to place in the output token stream.
Discussion
Allows you to replace a taken in the tokeniser’s output stream.
Only one of this and tokeniser:willProduceToken: will be called. The tokeniser will attempt to call this method second.
Bug: Warning this method is deprecated, use tokeniser:requestsToken:pushedOntoStream: instead.
Declared In
CPTokeniser.h