Location:
CBNFParser.h
Link against: bnf.lib
class CBNFParser : public CBase, public MDataProviderObserver;
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.
MDataProviderObserver
- MDataProviderObserver provides a virtual interface for any class to observe any MDataProvider, and provide data receiving
services
CBase
- Base class for all classes to be instantiated on the heap
CBNFParser
- Base class for parsers that use a BNF tree to parse an input stream
Defined in CBNFParser
:
AddComponentAttributeL()
, AddRuleCallbackL()
, AndL()
, AttributeLUT()
, CBNFParser()
, CRuleStack
, CommitL()
, CurrentRule()
, DeleteMark()
, EndConditional()
, ExactL()
, ExecutePostRuleCallbackL()
, ExecutePreRuleCallbackL()
, MDataProviderObserverReserved1()
, MDataProviderObserverReserved2()
, Mark()
, MarkCallback()
, MarkedL()
, MarkedWithInitialTextL()
, NMoreL()
, NewBNFL()
, NewComponentL()
, NewComponentL()
, NewComponentL()
, NewComponentL()
, NewComponentL()
, NewComponentL()
, NewL()
, NewRuleL()
, NewRuleL()
, OptionalL()
, OptionalMatched()
, OrL()
, ParseL()
, PerformRuleL()
, ProcessDataL()
, RangeL()
, ReferenceL()
, ResetL()
, RuleMatched()
, SelectL()
, SetBaseUriL()
, SetDataExpected()
, SetDocumentTypeL()
, SetDocumentTypeL()
, SetState()
, SetStatus()
, StartConditional()
, State()
, StringL()
, TRuleCallback
, TreeL()
, Valid()
, WithoutL()
, iCurrentRule
, iLUT
, iMatched
, iMoreCount
, iMoreMaximum
, iMoreMinimum
, iOptionalMatched
, iParsing
, iPostRuleCallback
, iPreRuleCallback
, iRangeEnd
, iRangeStart
, iReferenceString
, iRuleStack
, iString
, iStringComplete
, iSubRule
, iSubRuleMatched
, iTree
, ~CBNFParser()
Inherited from CBase
:
Delete()
,
Extension_()
,
operator new()
static IMPORT_C CBNFParser *NewL(CAttributeLookupTable &aLUT);
Allocates and constructs a new BNF parser.
|
|
protected: IMPORT_C CBNFParser(CAttributeLookupTable &aLUT);
Constructor.
|
virtual IMPORT_C void ResetL();
Reset the parser to a state where it can accept and parse new input.
If no BNF tree yet exists the virtual method TreeL()
is called to obtain the BNF tree for this parser. Any existing state of parsing and input data is destroyed.
inline TBool Valid() const;
Checks if the input stream was completely processed
|
inline HBufC *StringL() const;
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.
|
inline CBNFNode *CurrentRule();
Gets a pointer to the rule node currently being processed.
|
inline void Mark();
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.
inline HBufC *MarkedL();
Get string between the "cursor position" and the latest mark on the stream.
|
inline HBufC *MarkedWithInitialTextL(const TDesC &aInitialText);
Gets the marked string with a string added before the mached string.
|
|
inline void DeleteMark();
Removes the latest mark. All the marks are stored in a stack and this removes the topmost mark.
inline TBool RuleMatched() const;
Tests if the used rule matched.
This is typically used in post-rule callbacks.
|
inline TBool OptionalMatched() const;
Tests if an Optional node sub-rule matched.
|
IMPORT_C CBNFNode *NewBNFL();
Creates a new rule tree root node.
It creates a new single instance of CBNFNode
as the root node of the rule tree. All the top-level rules are attached as attributes to this node. The root node should
have single child node, which should be a reference to the logical root of the rule tree. This can be done be attaching the
logical root rule as a component to the root rule.
|
IMPORT_C CBNFNode &NewRuleL(CBNFNode *aRootRule, const TDesC &aRuleName, TParserNodeTypes aRuleType, HBufC *aData, TRuleCallback
*aPreRule, TRuleCallback *aPostRule);
Creates a new rule node and adds it to the root of the rule tree.
This overload takes ownership of the node data.
|
|
IMPORT_C CBNFNode &NewRuleL(CBNFNode *aRootRule, const TDesC &aRuleName, TParserNodeTypes aRuleType, const TDesC &aData, TRuleCallback
*aPreRule, TRuleCallback *aPostRule);
Creates a new rule node and adds it to the root of the rule tree.
This overload takes a reference to the node data instead of owning it.
|
|
IMPORT_C CBNFNode *NewComponentL(TParserNodeTypes aRuleType, const TDesC &aData);
Creates a new rule node, but does not add it to the tree.
This overload sets no rule callbacks.
|
|
IMPORT_C CBNFNode *NewComponentL(TParserNodeTypes aRuleType, HBufC *aData=0, TRuleCallback *aPreRule=0, TRuleCallback *aPostRule=0);
Creates a new rule node, but does not add it to the tree.
This overload allows rule callbacks to be set.
|
|
IMPORT_C CBNFNode *NewComponentL(CBNFNode *aRootRule, const TDesC &aRuleName);
Creates a new reference rule node.
|
|
IMPORT_C CBNFNode &NewComponentL(CBNFNode &aParentRule, TParserNodeTypes aRuleType, const TDesC &aData);
Creates a new sub-rule, and makes it a child of a specified parent rule.
This overload sets no rule callbacks.
|
|
IMPORT_C CBNFNode &NewComponentL(CBNFNode &aParentRule, TParserNodeTypes aRuleType, HBufC *aData=0, TRuleCallback *aPreRule=0,
TRuleCallback *aPostRule=0);
Creates a new sub-rule, and makes it a child of a specified parent rule.
This overload sets rule callbacks.
|
|
IMPORT_C CBNFNode &NewComponentL(CBNFNode *aRootRule, CBNFNode &aParentRule, const TDesC &aRuleName);
Creates a new reference rule node, and adds it as a child of the specified parent.
Note that the function succeeds even if the target rule aRuleName does not yet exist.
|
|
IMPORT_C void AddComponentAttributeL(CBNFNode &aRule, CBNFNodeAttributeType aAttribute, TInt aInt);
Adds an additional attribute to an existing rule node.
For example, this is used with range rules, which specify the range boundaries using start and end attributes.
|
virtual IMPORT_C void ProcessDataL(HBufC8 &aData);
Called by the data provider to add data for the parser to process.
This implements MDataProviderObserver::ProcessDataL()
.
|
virtual IMPORT_C void SetStatus(TInt aStatus=KErrNone);
Called by the data provider to report its status to its observer.
This implements MDataProviderObserver::SetStatus()
.
|
virtual IMPORT_C void SetDocumentTypeL(const TDesC &);
Intended Usage : The request to construct a CDataHandler to process data of aDataType, where aDataType is a string to match against some plugins declared data handling ability.
|
virtual IMPORT_C void SetDocumentTypeL(const TDesC &, const TDesC &);
Intended Usage : The request to construct a CDataHandler for aDataType with non default document encoding where aDataType is a string to match against some plugins declared data handling ability.
|
virtual IMPORT_C void SetDataExpected(TInt);
Intended Usage : The report of how many bytes of data is expected to be passed to ProcessDataL, enabling age reporting capabilities.
|
virtual IMPORT_C void SetBaseUriL(const TDesC *aBaseUri);
Intended Usage : Set the URI that the DataProvider considers the base URI for the current data.
|
virtual IMPORT_C void MDataProviderObserverReserved1();
Intended Usage : Reserved for future expansion.
virtual IMPORT_C void MDataProviderObserverReserved2();
Intended Usage : Reserved for future expansion.
IMPORT_C void CommitL();
Notifies the parser that all the data has been passed in.
It causes the parser to parse any of the input stream not already parsed.
inline TParseState State() const;
Get the current state of the parser.
|
protected: virtual IMPORT_C TBool ReferenceL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
Processes a reference rule node.
It is called by PerformRuleL()
.
|
|
protected: virtual IMPORT_C TBool ExactL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
Processes an EExact rule node.
It is called by PerformRuleL()
.
|
|
protected: virtual IMPORT_C TBool RangeL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
Processes an ERange rule node.
It is called by PerformRuleL()
.
|
|
protected: virtual IMPORT_C TBool SelectL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
Processes an ESelect rule node.
It is called by PerformRuleL()
.
if (aMatched == CFragmentedString::EMatch
)
|
|
protected: virtual IMPORT_C TBool WithoutL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
Processes an EWithout rule node.
It is called by PerformRuleL()
.
|
|
protected: virtual IMPORT_C TBool AndL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
Processes an EAnd rule node.
It is called by PerformRuleL()
.
performedMatch = ETrue;
|
|
protected: virtual IMPORT_C TBool OrL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
Processes an EOr rule node.
It is called by PerformRuleL()
.
|
|
protected: virtual IMPORT_C TBool OptionalL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
|
|
protected: virtual IMPORT_C TBool NMoreL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
Processes an ENMore rule node.
It is called by PerformRuleL()
.
|
|
protected: virtual IMPORT_C void AddRuleCallbackL(CBNFNode &aRule, const TDesC *aCallbackID, TRuleCallback *aCallback);
Adds a callback to a rule.
|
protected: virtual IMPORT_C void ExecutePreRuleCallbackL(CBNFNode &aRule);
Executes a pre-rule callback function.
|
protected: virtual IMPORT_C void ExecutePostRuleCallbackL(CBNFNode &aRule);
Executes a post-rule callback function.
|
protected: virtual IMPORT_C void StartConditional(TParserNodeTypes aRuleType);
|
protected: virtual IMPORT_C void EndConditional(TParserNodeTypes aRuleType, TBool aSuccess);
|
protected: static IMPORT_C void MarkCallback(CBNFParser &aParser);
Inserts a mark to the current position of the stream being processed.
Adding a mark is a very common callback operation before starting to process a rule, so the method is provided by the parser.
|
protected: IMPORT_C CAttributeLookupTable &AttributeLUT() const;
Gets the attribute look-up table used by this parser.
|
protected: virtual IMPORT_C TBool PerformRuleL(CBNFNode &aRule, CFragmentedString::TStringMatch &aMatched);
Handles a node in the rule tree.
It calls the appropriate handler method for the rule type.
|
|
protected: inline void SetState(TParseState aState);
Sets the parser state.
|
protected: typedef CStack<CBNFNode, EFalse> CBNFParser::CRuleStack;
Defines a type to handle a stack of rules.
protected: typedef void( CBNFParser::TRuleCallback)(CBNFParser&);
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.
protected: CAttributeLookupTable & iLUT;
Storage object for all the attributes and identifiers in a tree
protected: CFragmentedString iString;
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.
protected: TBool iStringComplete;
Flag indicating if the input stream has been completely processed.
protected: CBNFNode * iTree;
The BNF tree the parser is using to parse the input stream.
protected: CRuleStack iRuleStack;
A stack of rules from iTree which are waiting to be completed. The stack basically holds the path along the rule tree.
protected: TBool iSubRuleMatched;
Flag that indicates when returning to a rule in the rulestack if the child rule matched correctly.
protected: TBool iOptionalMatched;
Flag that indicates when returning to a rule in the rulestack if an optional rule matched correctly.
protected: CBNFNode * iSubRule;
The child rule we are returning from (if any). If this is NULL we are new to this BNF rule.
protected: const TDesC * iReferenceString;
Stores attribute identifier for reference string attributes.
protected: const TDesC * iRangeStart;
Stores attribute identifier for range start attributes.
protected: const TDesC * iRangeEnd;
Stores attribute identifier for range end attributes.
protected: const TDesC * iMoreMinimum;
Stores attribute identifier for nmore minimum attributes.
protected: const TDesC * iMoreCount;
Stores attribute identifier for nmore count attributes.
protected: const TDesC * iMoreMaximum;
Stores attribute identifier for nmore maximum attributes.
protected: const TDesC * iPreRuleCallback;
Stores attribute identifier for pre-rule callback attributes.
protected: const TDesC * iPostRuleCallback;
Stores attribute identifier for post-rule callback attributes.