CPParserDelegate Protocol Reference
Conforms to | NSObject |
Declared in | CPParser.h |
Overview
The delegate of a CPParser must adopt the CPParserDelegate protocol. This allows you to replace the produced syntax trees with data structures of your choice.
Significant processing can be performed in a parser delegate. For example, a parser for numeric expressions could replace each syntax tree with an NSNumber representing the resultant value of evaluating the expression. This would allow you to parse, and compute the result of the expression in one pass.
Tasks
-
– parser:didProduceSyntaxTree:
Should return an object to replace a produced syntax tree with.
-
– parser:didEncounterErrorOnInput:
Called when the parser encounters a token for which it can not shift, reduce or accept.
-
– parser:didEncounterErrorOnInput:expecting:
Called when the parser encounters a token for which it can not shift, reduce or accept.
Instance Methods
parser:didEncounterErrorOnInput:
Called when the parser encounters a token for which it can not shift, reduce or accept.
- (CPRecoveryAction *)parser:(CPParser *)parser didEncounterErrorOnInput:(CPTokenStream *)inputStream
Parameters
- parser
The parser which produced the syntax tree.
- inputStream
The input stream containing the token the parser could not cope with.
Return Value
An action to take to recover from the parse error or nil. If the action is nil, and the problematic token is a CPErrorToken the parse stack is unwound a step for the parent rule to deal with the error.
Discussion
Called when the parser encounters a token for which it can not shift, reduce or accept.
Bug: Warning this method is deprecated, use parser:didEncounterErrorOnInput:expecting: instead.
Declared In
CPParser.h
parser:didEncounterErrorOnInput:expecting:
Called when the parser encounters a token for which it can not shift, reduce or accept.
- (CPRecoveryAction *)parser:(CPParser *)parser didEncounterErrorOnInput:(CPTokenStream *)inputStream expecting:(NSSet *)acceptableTokens
Parameters
- parser
The parser which produced the syntax tree.
- inputStream
The input stream containing the token the parser could not cope with.
- acceptableTokens
A set of token names that would have allowed the parser to continue in its current state.
Return Value
An action to take to recover from the parse error or nil. If the action is nil, and the problematic token is a CPErrorToken the parse stack is unwound a step for the parent rule to deal with the error.
Discussion
Called when the parser encounters a token for which it can not shift, reduce or accept.
Declared In
CPParser.h
parser:didProduceSyntaxTree:
Should return an object to replace a produced syntax tree with.
- (id)parser:(CPParser *)parser didProduceSyntaxTree:(CPSyntaxTree *)syntaxTree
Parameters
- parser
The parser which produced the syntax tree.
- syntaxTree
The syntax tree the parser has produced.
Return Value
An object value to replace the syntax tree with.
Discussion
Should return an object to replace a produced syntax tree with.
You should not return nil
from this method. If you do not wish to change the syntax tree, simply return the same value as you are passed.
Warning: Note that it is not guarenteed that this method will be called in the same order as the structures appear in your input stream.
Declared In
CPParser.h