williamr@2: // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@2: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // This class provides a mechanism to use a BNF tree to parse an input stream. williamr@2: // The notation of the EBNF is based upon that described in the XML1.0 specification. williamr@2: // The BNF tree form used is a variation on Extended BNF and has the following rule types, williamr@2: // where the input stream must: williamr@2: // , Exact - match exactly with the provided string. williamr@2: // , Range - next character must be in the specified range. williamr@2: // , Select - next character must exist in the selected string. williamr@2: // If the select string starts with ^ it is a NOT Select. williamr@2: // , And - match all of the given sub rules williamr@2: // , Or - match one of the given sub rules williamr@2: // , NMore - match N or more times the the SINGLE subrule. williamr@2: // , Optional - match 0/1 times to the SINGLE subrule. williamr@2: // , Without - match the first subrule but NOT the second. williamr@2: // , Reference - match the referred to rule. williamr@2: // The iterative parser not only validates an input stream against the williamr@2: // BNF grammer but allows pre/post actions to be performed during the parsing. williamr@2: // Partial parsing is also allowed in that the input stream does not have to williamr@2: // completed before parsing can begin. As soon as data is added the parser williamr@2: // attempts to parse it. williamr@2: // Numerous methods are provided to assist in the building of the BNF Tree this parser uses. williamr@2: // To use this class: williamr@2: // Create a derivation and implement the virtual method TreeL() to creat a BNF rule tree williamr@2: // (the assistance methods NewBNF/NewRule etc should be used) - see DTDModel williamr@2: // To use your new parser invoke Reset and pass input data using the ProcessData method. williamr@2: // williamr@2: // williamr@2: williamr@2: #ifndef __CBNFPARSER_H__ williamr@2: #define __CBNFPARSER_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: // williamr@2: // forward class declarations williamr@2: // williamr@2: class CAttributeLookupTable; williamr@2: williamr@2: williamr@2: // Rule Tree node type definitions williamr@2: /** Defines types of node in a BNF tree (CBNFParser). williamr@2: williamr@2: Except for ERoot, EIncomplete, EReference, and ELastParserNodeType, the williamr@2: types define different types of rule that the input stream must meet to williamr@2: satisfy the grammar. */ williamr@2: enum TParserNodeTypes williamr@2: { williamr@2: /** Root node. */ williamr@2: ERoot, williamr@2: /** Incomplete node. */ williamr@2: EIncomplete, williamr@2: /** Exact rule: match exactly with the provided string. */ williamr@2: EExact, williamr@2: /** Range rule: next character must be in the specified range. williamr@2: williamr@2: The start of the range is specified by a CBNFNode::KRangeStart() williamr@2: attribute; the end by a CBNFNode::KRangeEnd() attribute. */ williamr@2: ERange, williamr@2: /** Select rule: next character must exist in the selected string. williamr@2: williamr@2: If the select string starts with ^, it is a NOT Select. */ williamr@2: ESelect, williamr@2: /** And rule: match all of the given sub-rules. williamr@2: williamr@2: Sub-rules are defined by the child nodes of the AND rule node. */ williamr@2: EAnd, williamr@2: /** Or rule: match one of the given sub-rules. williamr@2: williamr@2: Sub-rules are defined by the child nodes of the OR rule node. */ williamr@2: EOr, williamr@2: /** NMore rule: match a single subrule N or more times. williamr@2: williamr@2: A minimum is specified by a CBNFNode::KNMoreMinimum() attribute; a maximum by williamr@2: a CBNFNode::KNMoreMaximum() attribute; an exact figure by a CBNFNode::KNMoreCount() attribute. */ williamr@2: ENMore, williamr@2: /** Optional rule: match a single sub-rule 0/1 times. williamr@2: williamr@2: A sub-rule is defined by the child node of the Optional rule node. */ williamr@2: EOptional, williamr@2: /** Without rule: match the first sub-rule but not the second. williamr@2: williamr@2: Sub-rules are defined by the child nodes of the Without rule node. */ williamr@2: EWithout, williamr@2: /** Reference rule: match the referred to rule. williamr@2: williamr@2: The target rule name is identified by a CBNFNode::KReference() attribute. */ williamr@2: EReference, williamr@2: /** Indicates final node type. */ williamr@2: ELastParserNodeType williamr@2: }; williamr@2: williamr@2: // Parser states williamr@2: // williamr@2: // When a the state is EActive. williamr@2: // Setting the parser state to something else in a pre-/post-rule callback function williamr@2: // causes the parser to exit on next loop in ParseL. If the state is set to EStopped williamr@2: // we have finished the parser operation (e.g. in event of an error), in state EPaused williamr@2: // we are likely to resume the parser operation after some external operations. williamr@2: /** CBNFParser parser states. */ williamr@2: enum TParseState williamr@2: { williamr@2: /** Parser has stopped. */ williamr@2: EStopped, williamr@2: /** Rarser is running. */ williamr@2: EActive, williamr@2: /** Parser has paused: e.g. waiting for further input to continue. */ williamr@2: EPaused williamr@2: }; williamr@2: williamr@2: williamr@2: williamr@2: class CBNFParser : public CBase, public MDataProviderObserver williamr@2: /** Base class for parsers that use a BNF tree to parse an input stream. williamr@2: williamr@2: The BNF tree form used is a variation on Extended BNF described in the XML1.0 williamr@2: specification. The general form of the tree is as follows: williamr@2: williamr@2: Each node in the tree defines a rule that the input stream must meet to satisfy the grammar. williamr@2: williamr@2: 1. a node type is set to the rule type, as defined in TParserNodeTypes williamr@2: williamr@2: 2. node data stores any string required by the rule: e.g. for a comparison rule, the string williamr@2: to match against williamr@2: williamr@2: 3. the parser allows callback functions to be called either before or after the rule is processed. williamr@2: If these are present, they are stored as attributes of the node. williamr@2: williamr@2: 4. some rules allow sub-rules: for example, the AND rule expects a number of sub-rules, all williamr@2: of which must be successful if the AND rule itself is to succeed. Each sub-rule is williamr@2: represented as a child node of the parent rule. Sub-rules in turn can have sub-rules. williamr@2: williamr@2: 5. reference rule nodes are also allowed: these do not define themselves rules, but direct the williamr@2: parser to another rule. They can link rules to each other and so build rule sequences more williamr@2: complex than a simple tree. williamr@2: williamr@2: All the top-level rules are stored as attributes of the root node. The attribute type is a string williamr@2: that names the rule; the attribute value is a pointer to the node that implements the rule. williamr@2: williamr@2: The class supplies functions that encapsulate adding rules appropriately to the tree. The parser williamr@2: provider creates a derived class that implements the virtual method TreeL() that uses these williamr@2: functions to create a BNF rule tree. williamr@2: williamr@2: The user of the parser initialises the parser with ResetL(), and then passes input data to the williamr@2: parser using ProcessData(). The parser supports partial parsing: the input stream does not have williamr@2: to completed before parsing can begin. As soon as data is added, the parser attempts to parse it. williamr@2: williamr@2: @publishedAll williamr@4: @deprecated williamr@2: williamr@2: */ williamr@2: { williamr@2: protected: williamr@2: /** Defines a type to handle a stack of rules. */ williamr@2: typedef CStack CRuleStack; williamr@2: williamr@2: /** Type definition for a callback function pointer williamr@2: Callback functions need to get a reference to the parser as parameter williamr@2: and they need to be static. */ williamr@2: typedef void (TRuleCallback)(CBNFParser&); williamr@2: williamr@2: public: williamr@2: // Constructor for a new parser instance williamr@2: // williamr@2: // Input: williamr@2: // aLUT - reference to attribute lookuptable; used to store all the stuff in the parser rule tree williamr@2: // williamr@2: //##ModelId=3B6669EA00F8 williamr@2: IMPORT_C static CBNFParser* NewL(CAttributeLookupTable& aLUT); williamr@2: williamr@2: //##ModelId=3B6669EA00F7 williamr@2: IMPORT_C virtual ~CBNFParser(); williamr@2: williamr@2: // Prepare the parser to take in fresh stream of data. williamr@2: // THIS METHOD MUST BE CALLED BEFORE DATA CAN BE PROCESSED BY THE PARSER!! williamr@2: // Calls TreeL in order to create the parsing rule tree if no tree already williamr@2: // exists. williamr@2: //##ModelId=3B6669EA00EF williamr@2: IMPORT_C virtual void ResetL(); williamr@2: williamr@2: /** Checks if the input stream was completely processed williamr@2: @return ETrue if all of the data was processed, EFalse if the data didn't match to the parsing rules williamr@2: */ williamr@2: //##ModelId=3B6669EA00EE williamr@2: TBool Valid() const { return iStringComplete && (iString.Length() == 0); } williamr@2: williamr@2: /** Concatenates the rest of the input stream (which hasn't yet been processed) williamr@2: into a single string. The ownership of the string is given to the caller. williamr@2: @return String containing the remaining data to be parsed. OWNERSHIP PASSED TO CALLED. */ williamr@2: //##ModelId=3B6669EA00ED williamr@2: HBufC* StringL() const { return iString.StringL(); } williamr@2: williamr@2: /** Gets a pointer to the rule node currently being processed. williamr@2: @return Rule node */ williamr@2: //##ModelId=3B6669EA00E3 williamr@2: CBNFNode* CurrentRule() { return iCurrentRule; } williamr@2: williamr@2: // Set reference to an attribute lookup table williamr@2: //##ModelId=3B6669EA00C5 williamr@2: void SetAttributeLookupTable(CAttributeLookupTable& aAttributeLookupTable); williamr@2: williamr@2: // methods to allow the input stream to be marked so that the callbacks williamr@2: // can determine those parts which successfully matched williamr@2: williamr@2: /** Set a mark to the current position of the input stream. williamr@2: williamr@2: The mark acts as a tag in the stream currently being processed. williamr@2: As we process further along the stream after adding the mark, we can perform williamr@2: a rollback to the most previously set mark and start processing again (e.g. OR rule williamr@2: works this way). The string fragments won't be consumed (deleted) until williamr@2: all the marks on a fragment (and fragments before that) are deleted. */ williamr@2: //##ModelId=3B6669EA00BC williamr@2: void Mark() { iString.Mark(); }; // **Mark can leave** williamr@2: williamr@2: /** Get string between the "cursor position" and the latest mark on the stream. williamr@2: williamr@2: @return Pointer to the string from the previous mark on to the current position williamr@2: of processed string. OWNERSHIP OF THE STRING GIVEN TO THE CALLER. */ williamr@2: //##ModelId=3B6669EA00BB williamr@2: HBufC* MarkedL() { return iString.MarkedL(); }; williamr@2: williamr@2: /** Gets the marked string with a string added before the mached string. williamr@2: @see MarkedL() williamr@2: @return A string cosisting of aInitialText appended with the marked string. williamr@2: OWNERSHIP OF THE CONSTRUCTED STRING IS GIVEN TO THE CALLER. */ williamr@2: //##ModelId=3B6669EA009E williamr@2: HBufC* MarkedWithInitialTextL(const TDesC& aInitialText) { return iString.MarkedWithInitialTextL(aInitialText); }; williamr@2: williamr@2: /** Removes the latest mark. All the marks are stored in a stack and this removes williamr@2: the topmost mark.*/ williamr@2: //##ModelId=3B6669EA009D williamr@2: void DeleteMark() { iString.DeleteMark(); }; williamr@2: williamr@2: // methods to determine it the used rule actually matched (typically used in post callbacks) williamr@2: /** Tests if the used rule matched. williamr@2: williamr@2: This is typically used in post-rule callbacks. williamr@2: williamr@2: @return True if the used rule matched; otherwise false williamr@2: */ williamr@2: //##ModelId=3B6669EA0094 williamr@2: TBool RuleMatched() const { return iSubRuleMatched; }; williamr@2: /** Tests if an Optional node sub-rule matched. williamr@2: williamr@2: @return True if the sub- rule matched; otherwise false williamr@2: */ williamr@2: //##ModelId=3B6669EA0093 williamr@2: TBool OptionalMatched() const { return iOptionalMatched; }; williamr@2: williamr@2: // Create new rule tree root node. williamr@2: // This method creates a new single instance of CBNFNode, which shall act as the root williamr@2: // node of the rule tree, which implements the BNF rules for parsing the input stream. williamr@2: // All the other rules are attached as attributes to this node. williamr@2: // The root node should have single child node, which should be a reference to the williamr@2: // "logical root" of the rule tree. This can be done be attaching the logical root williamr@2: // rule as a component to the root rule. williamr@2: //##ModelId=3B6669EA0089 williamr@2: IMPORT_C CBNFNode* NewBNFL(); williamr@2: williamr@2: // Add a new rule to a rule tree. williamr@2: // williamr@2: // Input: williamr@2: // aRootRule - Pointer to the root bnf node (created with NewBNFL() ). williamr@2: // aRuleName - Reference to a string identifying this rule. The string is used williamr@2: // to make references to this rule from other rule's subtrees. williamr@2: // aData - Pointer to a data string; used with EExact and ESelect type rules williamr@2: // to match actual text strings. williamr@2: // aPreRule - Function pointer to a prerule function that gets called _BEFORE_ williamr@2: // we start processing this rule and its children (i.e. the rule subtree) williamr@2: // aPostRule - Function pointer to a postrule function which is called _AFTER_ williamr@2: // we have processed this rule (i.e. when we return up from the subtree williamr@2: // and this rule is finished). williamr@2: // williamr@2: // Return: williamr@2: // CBNFNode& - Reference to the newly created rule node in the rule tree williamr@2: // williamr@2: //##ModelId=3B6669E90326 williamr@2: IMPORT_C CBNFNode& NewRuleL(CBNFNode* aRootRule, williamr@2: const TDesC& aRuleName, williamr@2: TParserNodeTypes aRuleType, williamr@2: HBufC* aData, williamr@2: TRuleCallback* aPreRule, williamr@2: TRuleCallback* aPostRule); williamr@2: williamr@2: // Overridden version of the NewRuleL. Takes reference to the data instead of owning it. williamr@2: //##ModelId=3B6669E903D1 williamr@2: IMPORT_C CBNFNode& NewRuleL(CBNFNode* aRootRule, williamr@2: const TDesC& aRuleName, williamr@2: TParserNodeTypes aRuleType, williamr@2: const TDesC& aData, williamr@2: TRuleCallback* aPreRule, williamr@2: TRuleCallback* aPostRule); williamr@2: williamr@2: // construct a new rule component not attached to a rule. williamr@2: //##ModelId=3B6669E9018C williamr@2: IMPORT_C CBNFNode* NewComponentL(TParserNodeTypes aRuleType, const TDesC& aData); williamr@2: //##ModelId=3B6669E901B4 williamr@2: IMPORT_C CBNFNode* NewComponentL(TParserNodeTypes aRuleType, HBufC* aData = NULL, TRuleCallback* aPreRule = NULL, TRuleCallback* aPostRule = NULL); williamr@2: williamr@2: // create a reference component to the rule of the given name williamr@2: // which is not attached to any rule. williamr@2: //##ModelId=3B6669E90204 williamr@2: IMPORT_C CBNFNode* NewComponentL(CBNFNode* aRootRule, const TDesC& aRuleName); williamr@2: williamr@2: // Methods to create a new subrule to the given parent rule. williamr@2: // These methods can be used to build the subtrees to the "main rules" attached to the root node. williamr@2: // williamr@2: // Input: williamr@2: // aParentRule - The rule for which the new rule shall be added as a child williamr@2: // aRuleType - Type of the new rule williamr@2: // aData - Data for the rule; the string to match for an EExact rule, the selection character set for ESelect williamr@2: // williamr@2: // aPreRule - Pre rule callback function pointer williamr@2: // aPostRule - Post rule callback function pointer williamr@2: // Return: williamr@2: // CBNFNode& - reference to the new rule williamr@2: // williamr@2: //##ModelId=3B6669E9022C williamr@2: IMPORT_C CBNFNode& NewComponentL(CBNFNode &aParentRule, TParserNodeTypes aRuleType, const TDesC& aData); williamr@2: //##ModelId=3B6669E90268 williamr@2: IMPORT_C CBNFNode& NewComponentL(CBNFNode &aParentRule, TParserNodeTypes aRuleType, HBufC* aData = NULL, TRuleCallback* aPreRule = NULL, TRuleCallback* aPostRule = NULL); williamr@2: williamr@2: // Create a reference to another rule and attach this reference as a child of the given parent. williamr@2: // Creates a child node of type EReference for the parent. This reference node williamr@2: // hold the pointer to the rule we are refering to. williamr@2: // Using references we can link rules to each other and build complex rule trees williamr@2: // even though they don't physically form a complete tree. williamr@2: // Notice, that the rule we are refering to does not necessarily need to exist, yet! williamr@2: // williamr@2: // Input: williamr@2: // aRootRule - The Root node to the rule tree (created with NewBNFL). This is needed to williamr@2: // find the rule we are refering to with the string. williamr@2: // aParentRule - The parent rule of the newly created reference williamr@2: // aRuleName - The "id string" of the rule we are refering to. williamr@2: //##ModelId=3B6669E902CC williamr@2: IMPORT_C CBNFNode& NewComponentL(CBNFNode* aRootRule, CBNFNode &aParentRule, const TDesC& aRuleName); williamr@2: williamr@2: // add additional attributes to components of rules (i.e. range values) williamr@2: //##ModelId=3B6669E900F6 williamr@2: IMPORT_C void AddComponentAttributeL(CBNFNode& aRule, CBNFNodeAttributeType aAttribute, TInt aInt); williamr@2: williamr@2: // re-implementations of MDataProviderObserver methods williamr@2: //##ModelId=3B6669E900D8 williamr@2: IMPORT_C virtual void ProcessDataL(HBufC8& aData); williamr@2: //##ModelId=3B6669E900AF williamr@2: IMPORT_C virtual void SetStatus(TInt aStatus = KErrNone); williamr@2: //##ModelId=3B6669E90069 williamr@2: IMPORT_C virtual void SetDocumentTypeL(const TDesC&); williamr@2: //##ModelId=3B6669E90087 williamr@2: IMPORT_C virtual void SetDocumentTypeL(const TDesC&, const TDesC&); williamr@2: //##ModelId=3B6669E90055 williamr@2: IMPORT_C virtual void SetDataExpected(TInt); williamr@2: //##ModelId=3B6669E90041 williamr@2: IMPORT_C virtual void SetBaseUriL(const TDesC* aBaseUri); williamr@2: //##ModelId=3B6669E90038 williamr@2: IMPORT_C virtual void MDataProviderObserverReserved1(); williamr@2: //##ModelId=3B6669E90037 williamr@2: IMPORT_C virtual void MDataProviderObserverReserved2(); williamr@2: williamr@2: // Tell the parser, that we all the data has been passed in. williamr@2: // This method attempts to parse what ever is left of the input stream if it wasn't williamr@2: // already finished. williamr@2: //##ModelId=3B6669E9002E williamr@2: IMPORT_C void CommitL(); williamr@2: williamr@2: /** Get the current state of the parser. williamr@2: @return Parser state */ williamr@2: //##ModelId=3B6669E9002D williamr@2: TParseState State() const {return(iParsing);}; williamr@2: williamr@2: protected: williamr@2: IMPORT_C CBNFParser(CAttributeLookupTable& aLUT); williamr@2: williamr@2: // Each of the following functions is a handler method for a specific type of a rule williamr@2: // node. For example, ReferenceL handles reference nodes etc. williamr@2: // These methods are called by PerformRuleL. williamr@2: // williamr@2: // Input: williamr@2: // aRule - reference to the rule being processed williamr@2: // aMatched - reference to a CFragmentedString::TStringMatch variable, which holds williamr@2: // the information if the string or character we previously were trying to williamr@2: // match actually matched. williamr@2: // Return: williamr@2: // TBool - We return ETrue if we have completed processing this node. If the processing williamr@2: // still continues we return EFalse. For example, an EAnd rule would return williamr@2: // ETrue if all of its chidren had matched or if a rule didn't match. In the first williamr@2: // case the EAnd rule would have turned out to be true (aMatched = EMatched) since williamr@2: // all of its children were true, but in the latter case we can stop processing the williamr@2: // EAnd rule, since a subrule to the And didn't match and this means that the And williamr@2: // expression can not be true. Either way, the processing of the And ends and we williamr@2: // may return ETrue; williamr@2: // williamr@2: //##ModelId=3B6669E90005 williamr@2: IMPORT_C virtual TBool ReferenceL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: //##ModelId=3B6669E803BB williamr@2: IMPORT_C virtual TBool ExactL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: //##ModelId=3B6669E80389 williamr@2: IMPORT_C virtual TBool RangeL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: //##ModelId=3B6669E80343 williamr@2: IMPORT_C virtual TBool SelectL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: //##ModelId=3B6669E80311 williamr@2: IMPORT_C virtual TBool WithoutL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: //##ModelId=3B6669E802D5 williamr@2: IMPORT_C virtual TBool AndL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: //##ModelId=3B6669E80299 williamr@2: IMPORT_C virtual TBool OrL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: //##ModelId=3B6669E80271 williamr@2: IMPORT_C virtual TBool OptionalL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: //##ModelId=3B6669E8023F williamr@2: IMPORT_C virtual TBool NMoreL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: williamr@2: // A method to add a callback to a rule williamr@2: // williamr@2: // Input: williamr@2: // aRule - The rule to which the callback is to be added williamr@2: // aCallbackID - Either CBNFNode::KPreRuleCallback() or CBNFNode::KPostRuleCallback() williamr@2: // Defines the type of the callback function (i.e. is it to be called before williamr@2: // or after the rule has been processed). williamr@2: // aCallback - The callback function pointer williamr@2: // williamr@2: //##ModelId=3B6669E80203 williamr@2: IMPORT_C virtual void AddRuleCallbackL(CBNFNode& aRule, const TDesC* aCallbackID, TRuleCallback* aCallback); williamr@2: //##ModelId=3B6669E801EF williamr@2: IMPORT_C virtual void ExecutePreRuleCallbackL(CBNFNode& aRule); williamr@2: //##ModelId=3B6669E801D1 williamr@2: IMPORT_C virtual void ExecutePostRuleCallbackL(CBNFNode& aRule); williamr@2: williamr@2: // the method TreeL() should be reimplemented to generate a BNF rule tree and return williamr@2: // ownership of it. This is the rule tree which will be to parse the input stream. williamr@2: // See XmlPars.cpp or DTDMDL.cpp for example. williamr@2: //##ModelId=3B6669E801D0 williamr@2: IMPORT_C virtual CBNFNode* TreeL(); williamr@2: williamr@2: // methods which are invoked when the parser encounters a conditional williamr@2: // point in the BNF grammar (i.e. And/Or) williamr@2: //##ModelId=3B6669E801B2 williamr@2: IMPORT_C virtual void StartConditional(TParserNodeTypes aRuleType); williamr@2: //##ModelId=3B6669E80180 williamr@2: IMPORT_C virtual void EndConditional(TParserNodeTypes aRuleType, TBool aSuccess); williamr@2: williamr@2: // A callback function to insert a mark to the current position of the stream williamr@2: // being processed. Adding mark is a very common callback operation befor starting williamr@2: // to process a rule, hence the method is provided by the parser. williamr@2: //##ModelId=3B6669E8016C williamr@2: IMPORT_C static void MarkCallback(CBNFParser& aParser); williamr@2: williamr@2: // returns the LUT used by this parser. williamr@2: //##ModelId=3B6669E80163 williamr@2: IMPORT_C CAttributeLookupTable& AttributeLUT() const; williamr@2: williamr@2: // method which does the actual iterative parsing williamr@2: //##ModelId=3B6669E80162 williamr@2: IMPORT_C TBool ParseL(); williamr@2: williamr@2: // A rule to handle a node in the rule tree. This method just calls the appropriate williamr@2: // handler method according to the rule type. williamr@2: //##ModelId=3B6669E8013A williamr@2: IMPORT_C virtual TBool PerformRuleL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched); williamr@2: williamr@2: //##ModelId=3B6669E8011C williamr@2: /** Sets the parser state. williamr@2: williamr@2: @param aState Parser state williamr@2: */ williamr@2: void SetState(TParseState aState) {iParsing=aState;}; williamr@2: williamr@2: protected: williamr@2: /** Storage object for all the attributes and identifiers in a tree */ williamr@2: //##ModelId=3B6669E80108 williamr@2: CAttributeLookupTable& iLUT; williamr@2: williamr@2: /** An utility object which stores all the buffers passed into the parser williamr@2: and represents them as if they would form a single, continuous string. williamr@2: This class also performs the actual physical matching/selection of the strings williamr@2: and holds the marks set onto the string.*/ williamr@2: //##ModelId=3B6669E800EA williamr@2: CFragmentedString iString; williamr@2: /** Flag indicating if the input stream has been completely processed. */ williamr@2: //##ModelId=3B6669E800D6 williamr@2: TBool iStringComplete; // more input stream has completed williamr@2: williamr@2: /** The BNF tree the parser is using to parse the input stream.*/ williamr@2: //##ModelId=3B6669E800C2 williamr@2: CBNFNode* iTree; // the BNF tree we are using to parse the input stream williamr@2: williamr@2: /** A stack of rules from iTree which are waiting to be completed. williamr@2: The stack basically holds the path along the rule tree. */ williamr@2: //##ModelId=3B6669E800AE williamr@2: CRuleStack iRuleStack; williamr@2: /** The BNF rule that is currently being processed. */ williamr@2: //##ModelId=3B6669E80090 williamr@2: CBNFNode* iCurrentRule; // the BNF rule we are currently using williamr@2: williamr@2: // when returning to a rule in the rulestack this indicates williamr@2: // if the child rule matched correctly williamr@2: /** Flag that indicates when returning to a rule in the rulestack if the child rule matched correctly. */ williamr@2: //##ModelId=3B6669E8007C williamr@2: TBool iSubRuleMatched; williamr@2: /** Flag that indicates when returning to a rule in the rulestack if an optional rule matched correctly. */ williamr@2: //##ModelId=3B6669E8006A williamr@2: TBool iOptionalMatched; williamr@2: williamr@2: /** The child rule we are returning from (if any). williamr@2: If this is NULL we are new to this BNF rule.*/ williamr@2: //##ModelId=3B6669E80054 williamr@2: CBNFNode* iSubRule; williamr@2: williamr@2: /** Parser state. */ williamr@2: //##ModelId=3B6669E8004A williamr@2: TParseState iParsing; williamr@2: /** Input stream matched rule flag. */ williamr@2: //##ModelId=3B6669E80038 williamr@2: CFragmentedString::TStringMatch iMatched; williamr@2: williamr@2: // Storage pointers for strings identifying certain attributes on the rule nodes williamr@2: /** Stores attribute identifier for reference string attributes. */ williamr@2: //##ModelId=3B6669E8002C williamr@2: const TDesC* iReferenceString; williamr@2: /** Stores attribute identifier for range start attributes. */ williamr@2: //##ModelId=3B6669E8001A williamr@2: const TDesC* iRangeStart; williamr@2: /** Stores attribute identifier for range end attributes. */ williamr@2: //##ModelId=3B6669E80010 williamr@2: const TDesC* iRangeEnd; williamr@2: /** Stores attribute identifier for nmore minimum attributes. */ williamr@2: //##ModelId=3B6669E80006 williamr@2: const TDesC* iMoreMinimum; williamr@2: /** Stores attribute identifier for nmore count attributes. */ williamr@2: //##ModelId=3B6669E703DA williamr@2: const TDesC* iMoreCount; williamr@2: /** Stores attribute identifier for nmore maximum attributes. */ williamr@2: //##ModelId=3B6669E703D0 williamr@2: const TDesC* iMoreMaximum; williamr@2: /** Stores attribute identifier for pre-rule callback attributes. */ williamr@2: //##ModelId=3B6669E703C6 williamr@2: const TDesC* iPreRuleCallback; williamr@2: /** Stores attribute identifier for post-rule callback attributes. */ williamr@2: //##ModelId=3B6669E703BC williamr@2: const TDesC* iPostRuleCallback; williamr@2: }; williamr@2: williamr@2: #endif