class CBNFParser : public CBase |
Base class for parsers that use a BNF tree to parse an input stream.
The BNF tree form used is a variation on Extended BNF described in the XML1.0 specification. The general form of the tree is as follows:
Each node in the tree defines a rule that the input stream must meet to satisfy the grammar.
1. a node type is set to the rule type, as defined in TParserNodeTypes
2. node data stores any string required by the rule: e.g. for a comparison rule, the string to match against
3. the parser allows callback functions to be called either before or after the rule is processed. If these are present, they are stored as attributes of the node.
4. some rules allow sub-rules: for example, the AND rule expects a number of sub-rules, all of which must be successful if the AND rule itself is to succeed. Each sub-rule is represented as a child node of the parent rule. Sub-rules in turn can have sub-rules.
5. reference rule nodes are also allowed: these do not define themselves rules, but direct the parser to another rule. They can link rules to each other and so build rule sequences more complex than a simple tree.
All the top-level rules are stored as attributes of the root node. The attribute type is a string that names the rule; the attribute value is a pointer to the node that implements the rule.
The class supplies functions that encapsulate adding rules appropriately to the tree. The parser provider creates a derived class that implements the virtual method TreeL() that uses these functions to create a BNF rule tree.
The user of the parser initialises the parser with ResetL(), and then passes input data to the parser using ProcessData(). The parser supports partial parsing: the input stream does not have to completed before parsing can begin. As soon as data is added, the parser attempts to parse it.
Protected Member Type Definitions | |
---|---|
typedef | CStack< CBNFNode, EFalse > CRuleStack |
typedef | void( TRuleCallback |
Protected Attributes | |
---|---|
CBNFNode * | iCurrentRule |
CAttributeLookupTable & | iLUT |
CFragmentedString::TStringMatch | iMatched |
const TDesC * | iMoreCount |
const TDesC * | iMoreMaximum |
const TDesC * | iMoreMinimum |
TBool | iOptionalMatched |
TParseState | iParsing |
const TDesC * | iPostRuleCallback |
const TDesC * | iPreRuleCallback |
const TDesC * | iRangeEnd |
const TDesC * | iRangeStart |
const TDesC * | iReferenceString |
CRuleStack | iRuleStack |
CFragmentedString | iString |
TBool | iStringComplete |
CBNFNode * | iSubRule |
TBool | iSubRuleMatched |
CBNFNode * | iTree |
IMPORT_C | CBNFParser | ( | CAttributeLookupTable & | aLUT | ) | [protected] |
CAttributeLookupTable & aLUT |
IMPORT_C void | AddComponentAttributeL | ( | CBNFNode & | aRule, |
CBNFNodeAttributeType | aAttribute, | |||
TInt | aInt | |||
) |
CBNFNode & aRule | |
CBNFNodeAttributeType aAttribute | |
TInt aInt |
IMPORT_C void | AddRuleCallbackL | ( | CBNFNode & | aRule, |
const TDesC * | aCallbackID, | |||
TRuleCallback * | aCallback | |||
) | [protected, virtual] |
CBNFNode & aRule | |
const TDesC * aCallbackID | |
TRuleCallback * aCallback |
IMPORT_C TBool | AndL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
CBNFNode * | CurrentRule | ( | ) | [inline] |
Gets a pointer to the rule node currently being processed. Rule node
void | DeleteMark | ( | ) | [inline] |
Removes the latest mark. All the marks are stored in a stack and this removes the topmost mark.
IMPORT_C void | EndConditional | ( | TParserNodeTypes | aRuleType, |
TBool | aSuccess | |||
) | [protected, virtual] |
TParserNodeTypes aRuleType | |
TBool aSuccess |
IMPORT_C TBool | ExactL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
IMPORT_C void | ExecutePostRuleCallbackL | ( | CBNFNode & | aRule | ) | [protected, virtual] |
CBNFNode & aRule |
IMPORT_C void | ExecutePreRuleCallbackL | ( | CBNFNode & | aRule | ) | [protected, virtual] |
CBNFNode & aRule |
void | Mark | ( | ) | [inline] |
Set a mark to the current position of the input stream.
The mark acts as a tag in the stream currently being processed. As we process further along the stream after adding the mark, we can perform a rollback to the most previously set mark and start processing again (e.g. OR rule works this way). The string fragments won't be consumed (deleted) until all the marks on a fragment (and fragments before that) are deleted.
IMPORT_C void | MarkCallback | ( | CBNFParser & | aParser | ) | [protected, static] |
CBNFParser & aParser |
HBufC * | MarkedL | ( | ) | [inline] |
Get string between the "cursor position" and the latest mark on the stream.
Pointer to the string from the previous mark on to the current position of processed string. OWNERSHIP OF THE STRING GIVEN TO THE CALLER.
HBufC * | MarkedWithInitialTextL | ( | const TDesC & | aInitialText | ) | [inline] |
Gets the marked string with a string added before the mached string. MarkedL()
A string cosisting of aInitialText appended with the marked string. OWNERSHIP OF THE CONSTRUCTED STRING IS GIVEN TO THE CALLER.
const TDesC & aInitialText |
IMPORT_C TBool | NMoreL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
IMPORT_C CBNFNode * | NewComponentL | ( | TParserNodeTypes | aRuleType, |
const TDesC & | aData | |||
) |
TParserNodeTypes aRuleType | |
const TDesC & aData |
IMPORT_C CBNFNode * | NewComponentL | ( | TParserNodeTypes | aRuleType, |
HBufC * | aData = NULL, | |||
TRuleCallback * | aPreRule = NULL, | |||
TRuleCallback * | aPostRule = NULL | |||
) |
TParserNodeTypes aRuleType | |
HBufC * aData = NULL | |
TRuleCallback * aPreRule = NULL | |
TRuleCallback * aPostRule = NULL |
IMPORT_C CBNFNode * | NewComponentL | ( | CBNFNode * | aRootRule, |
const TDesC & | aRuleName | |||
) |
IMPORT_C CBNFNode & | NewComponentL | ( | CBNFNode & | aParentRule, |
TParserNodeTypes | aRuleType, | |||
const TDesC & | aData | |||
) |
CBNFNode & aParentRule | |
TParserNodeTypes aRuleType | |
const TDesC & aData |
IMPORT_C CBNFNode & | NewComponentL | ( | CBNFNode & | aParentRule, |
TParserNodeTypes | aRuleType, | |||
HBufC * | aData = NULL, | |||
TRuleCallback * | aPreRule = NULL, | |||
TRuleCallback * | aPostRule = NULL | |||
) |
CBNFNode & aParentRule | |
TParserNodeTypes aRuleType | |
HBufC * aData = NULL | |
TRuleCallback * aPreRule = NULL | |
TRuleCallback * aPostRule = NULL |
IMPORT_C CBNFNode & | NewComponentL | ( | CBNFNode * | aRootRule, |
CBNFNode & | aParentRule, | |||
const TDesC & | aRuleName | |||
) |
IMPORT_C CBNFParser * | NewL | ( | CAttributeLookupTable & | aLUT | ) | [static] |
CAttributeLookupTable & aLUT |
IMPORT_C CBNFNode & | NewRuleL | ( | CBNFNode * | aRootRule, |
const TDesC & | aRuleName, | |||
TParserNodeTypes | aRuleType, | |||
HBufC * | aData, | |||
TRuleCallback * | aPreRule, | |||
TRuleCallback * | aPostRule | |||
) |
CBNFNode * aRootRule | |
const TDesC & aRuleName | |
TParserNodeTypes aRuleType | |
HBufC * aData | |
TRuleCallback * aPreRule | |
TRuleCallback * aPostRule |
IMPORT_C CBNFNode & | NewRuleL | ( | CBNFNode * | aRootRule, |
const TDesC & | aRuleName, | |||
TParserNodeTypes | aRuleType, | |||
const TDesC & | aData, | |||
TRuleCallback * | aPreRule, | |||
TRuleCallback * | aPostRule | |||
) |
CBNFNode * aRootRule | |
const TDesC & aRuleName | |
TParserNodeTypes aRuleType | |
const TDesC & aData | |
TRuleCallback * aPreRule | |
TRuleCallback * aPostRule |
IMPORT_C TBool | OptionalL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
TBool | OptionalMatched | ( | ) | const [inline] |
Tests if an Optional node sub-rule matched.
True if the sub- rule matched; otherwise false
IMPORT_C TBool | OrL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
IMPORT_C TBool | PerformRuleL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
IMPORT_C TBool | RangeL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
IMPORT_C TBool | ReferenceL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
TBool | RuleMatched | ( | ) | const [inline] |
Tests if the used rule matched.
This is typically used in post-rule callbacks.
True if the used rule matched; otherwise false
IMPORT_C TBool | SelectL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
void | SetAttributeLookupTable | ( | CAttributeLookupTable & | aAttributeLookupTable | ) |
CAttributeLookupTable & aAttributeLookupTable |
IMPORT_C void | SetBaseUriL | ( | const TDesC * | aBaseUri | ) | [virtual] |
const TDesC * aBaseUri |
IMPORT_C void | SetDocumentTypeL | ( | const TDesC & | ) | [virtual] |
const TDesC & |
IMPORT_C void | SetDocumentTypeL | ( | const TDesC & | , |
const TDesC & | ||||
) | [virtual] |
void | SetState | ( | TParseState | aState | ) | [protected, inline] |
Sets the parser state.
TParseState aState | Parser state |
IMPORT_C void | StartConditional | ( | TParserNodeTypes | aRuleType | ) | [protected, virtual] |
TParserNodeTypes aRuleType |
HBufC * | StringL | ( | ) | const [inline] |
Concatenates the rest of the input stream (which hasn't yet been processed) into a single string. The ownership of the string is given to the caller. String containing the remaining data to be parsed. OWNERSHIP PASSED TO CALLED.
TBool | Valid | ( | ) | const [inline] |
Checks if the input stream was completely processed ETrue if all of the data was processed, EFalse if the data didn't match to the parsing rules
IMPORT_C TBool | WithoutL | ( | CBNFNode & | aRule, |
CFragmentedString::TStringMatch & | aMatched | |||
) | [protected, virtual] |
CBNFNode & aRule | |
CFragmentedString::TStringMatch & aMatched |
typedef CStack< CBNFNode, EFalse > | CRuleStack | [protected] |
Defines a type to handle a stack of rules.
typedef void( | TRuleCallback | [protected] |
Type definition for a callback function pointer Callback functions need to get a reference to the parser as parameter and they need to be static.
CBNFNode * | iCurrentRule | [protected] |
The BNF rule that is currently being processed.
CAttributeLookupTable & | iLUT | [protected] |
Storage object for all the attributes and identifiers in a tree
CFragmentedString::TStringMatch | iMatched | [protected] |
Input stream matched rule flag.
const TDesC * | iMoreCount | [protected] |
Stores attribute identifier for nmore count attributes.
const TDesC * | iMoreMaximum | [protected] |
Stores attribute identifier for nmore maximum attributes.
const TDesC * | iMoreMinimum | [protected] |
Stores attribute identifier for nmore minimum attributes.
TBool | iOptionalMatched | [protected] |
Flag that indicates when returning to a rule in the rulestack if an optional rule matched correctly.
const TDesC * | iPostRuleCallback | [protected] |
Stores attribute identifier for post-rule callback attributes.
const TDesC * | iPreRuleCallback | [protected] |
Stores attribute identifier for pre-rule callback attributes.
const TDesC * | iRangeEnd | [protected] |
Stores attribute identifier for range end attributes.
const TDesC * | iRangeStart | [protected] |
Stores attribute identifier for range start attributes.
const TDesC * | iReferenceString | [protected] |
Stores attribute identifier for reference string attributes.
CRuleStack | iRuleStack | [protected] |
A stack of rules from iTree which are waiting to be completed. The stack basically holds the path along the rule tree.
CFragmentedString | iString | [protected] |
An utility object which stores all the buffers passed into the parser and represents them as if they would form a single, continuous string. This class also performs the actual physical matching/selection of the strings and holds the marks set onto the string.
TBool | iStringComplete | [protected] |
Flag indicating if the input stream has been completely processed.
CBNFNode * | iSubRule | [protected] |
The child rule we are returning from (if any). If this is NULL we are new to this BNF rule.
TBool | iSubRuleMatched | [protected] |
Flag that indicates when returning to a rule in the rulestack if the child rule matched correctly.
CBNFNode * | iTree | [protected] |
The BNF tree the parser is using to parse the input stream.