epoc32/include/mw/cbnfparser.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@2
     1
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@4
     4
// under the terms of "Eclipse Public License v1.0"
williamr@2
     5
// which accompanies this distribution, and is available
williamr@4
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
// This class provides a mechanism to use a BNF tree to parse an input stream.
williamr@2
    15
// The notation of the EBNF is based upon that described in the XML1.0 specification.
williamr@2
    16
// The BNF tree form used is a variation on Extended BNF and has the following rule types,
williamr@2
    17
// where the input stream must:
williamr@2
    18
// , Exact - match exactly with the provided string.
williamr@2
    19
// , Range - next character must be in the specified range.
williamr@2
    20
// , Select - next character must exist in the selected string.
williamr@2
    21
// If the select string starts with ^ it is a NOT Select.
williamr@2
    22
// , And - match all of the given sub rules
williamr@2
    23
// , Or - match one of the given sub rules
williamr@2
    24
// , NMore - match N or more times the the SINGLE subrule.
williamr@2
    25
// , Optional - match 0/1 times to the SINGLE subrule.
williamr@2
    26
// , Without - match the first subrule but NOT the second.
williamr@2
    27
// , Reference - match the referred to rule.
williamr@2
    28
// The iterative parser not only validates an input stream against the 
williamr@2
    29
// BNF grammer but allows pre/post actions to be performed during the parsing.
williamr@2
    30
// Partial parsing is also allowed in that the input stream does not have to
williamr@2
    31
// completed before parsing can begin. As soon as data is added the parser
williamr@2
    32
// attempts to parse it.
williamr@2
    33
// Numerous methods are provided to assist in the building of the BNF Tree this parser uses.
williamr@2
    34
// To use this class:
williamr@2
    35
// Create a derivation and implement the virtual method TreeL() to creat a BNF rule tree
williamr@2
    36
// (the assistance methods NewBNF/NewRule etc should be used) - see DTDModel 
williamr@2
    37
// To use your new parser invoke Reset and pass input data using the ProcessData method.
williamr@2
    38
// 
williamr@2
    39
//
williamr@2
    40
williamr@2
    41
#ifndef __CBNFPARSER_H__
williamr@2
    42
#define __CBNFPARSER_H__
williamr@2
    43
williamr@2
    44
#include <e32std.h>
williamr@2
    45
#include <mdataproviderobserver.h>
williamr@2
    46
#include <cstack.h>
williamr@2
    47
#include <cfragmentedstring.h>
williamr@2
    48
#include <cbnfnode.h>
williamr@2
    49
williamr@2
    50
//
williamr@2
    51
// forward class declarations
williamr@2
    52
//
williamr@2
    53
class CAttributeLookupTable;
williamr@2
    54
williamr@2
    55
williamr@2
    56
// Rule Tree node type definitions
williamr@2
    57
/** Defines types of node in a BNF tree (CBNFParser).
williamr@2
    58
williamr@2
    59
Except for ERoot, EIncomplete, EReference, and ELastParserNodeType, the 
williamr@2
    60
types define different types of rule that the input stream must meet to 
williamr@2
    61
satisfy the grammar. */
williamr@2
    62
enum TParserNodeTypes
williamr@2
    63
	{
williamr@2
    64
	/** Root node. */
williamr@2
    65
	ERoot, 
williamr@2
    66
	/** Incomplete node. */
williamr@2
    67
	EIncomplete, 
williamr@2
    68
	/** Exact rule: match exactly with the provided string. */
williamr@2
    69
	EExact, 
williamr@2
    70
	/** Range rule: next character must be in the specified range.
williamr@2
    71
williamr@2
    72
	The start of the range is specified by a CBNFNode::KRangeStart() 
williamr@2
    73
	attribute; the end by a CBNFNode::KRangeEnd() attribute. */
williamr@2
    74
	ERange, 
williamr@2
    75
	/** Select rule: next character must exist in the selected string.
williamr@2
    76
williamr@2
    77
	If the select string starts with ^, it is a NOT Select. */
williamr@2
    78
	ESelect, 
williamr@2
    79
	/** And rule: match all of the given sub-rules.
williamr@2
    80
williamr@2
    81
	Sub-rules are defined by the child nodes of the AND rule node. */
williamr@2
    82
	EAnd, 
williamr@2
    83
	/** Or rule: match one of the given sub-rules.
williamr@2
    84
williamr@2
    85
	Sub-rules are defined by the child nodes of the OR rule node. */
williamr@2
    86
	EOr, 
williamr@2
    87
	/** NMore rule: match a single subrule N or more times.
williamr@2
    88
williamr@2
    89
	A minimum is specified by a CBNFNode::KNMoreMinimum() attribute; a maximum by 
williamr@2
    90
	a CBNFNode::KNMoreMaximum() attribute; an exact figure by a CBNFNode::KNMoreCount() attribute. */
williamr@2
    91
	ENMore, 
williamr@2
    92
	/** Optional rule: match a single sub-rule 0/1 times.
williamr@2
    93
williamr@2
    94
	A sub-rule is defined by the child node of the Optional rule node. */
williamr@2
    95
	EOptional, 
williamr@2
    96
	/** Without rule: match the first sub-rule but not the second.
williamr@2
    97
williamr@2
    98
	Sub-rules are defined by the child nodes of the Without rule node. */
williamr@2
    99
	EWithout, 
williamr@2
   100
	/** Reference rule: match the referred to rule.
williamr@2
   101
williamr@2
   102
	The target rule name is identified by a CBNFNode::KReference() attribute. */
williamr@2
   103
	EReference, 
williamr@2
   104
	/** Indicates final node type. */
williamr@2
   105
	ELastParserNodeType	
williamr@2
   106
	};
williamr@2
   107
williamr@2
   108
// Parser states
williamr@2
   109
// 
williamr@2
   110
// When a  the state is EActive. 
williamr@2
   111
// Setting the parser state to something else in a pre-/post-rule callback function
williamr@2
   112
// causes the parser to exit on next loop in ParseL. If the state is set to EStopped
williamr@2
   113
// we have finished the parser operation (e.g. in event of an error), in state EPaused
williamr@2
   114
// we are likely to resume the parser operation after some external operations.
williamr@2
   115
/** CBNFParser parser states. */
williamr@2
   116
enum TParseState
williamr@2
   117
	{
williamr@2
   118
	/** Parser has stopped. */
williamr@2
   119
	EStopped, 
williamr@2
   120
	/** Rarser is running. */
williamr@2
   121
	EActive, 
williamr@2
   122
	/** Parser has paused: e.g. waiting for further input to continue. */
williamr@2
   123
	EPaused
williamr@2
   124
	};
williamr@2
   125
williamr@2
   126
williamr@2
   127
williamr@2
   128
class CBNFParser : public CBase, public MDataProviderObserver
williamr@2
   129
/** Base class for parsers that use a BNF tree to parse an input stream.
williamr@2
   130
williamr@2
   131
The BNF tree form used is a variation on Extended BNF described in the XML1.0 
williamr@2
   132
specification. The general form of the tree is as follows:
williamr@2
   133
williamr@2
   134
Each node in the tree defines a rule that the input stream must meet to satisfy the grammar.
williamr@2
   135
williamr@2
   136
1. a node type is set to the rule type, as defined in TParserNodeTypes
williamr@2
   137
williamr@2
   138
2. node data stores any string required by the rule: e.g. for a comparison rule, the string 
williamr@2
   139
	to match against
williamr@2
   140
williamr@2
   141
3. the parser allows callback functions to be called either before or after the rule is processed.
williamr@2
   142
	 If these are present, they are stored as attributes of the node.
williamr@2
   143
williamr@2
   144
4. some rules allow sub-rules: for example, the AND rule expects a number of sub-rules, all 
williamr@2
   145
	of which must be successful if the AND rule itself is to succeed. Each sub-rule is 
williamr@2
   146
	represented as a child node of the parent rule. Sub-rules in turn can have sub-rules.
williamr@2
   147
williamr@2
   148
5. reference rule nodes are also allowed: these do not define themselves rules, but direct the 
williamr@2
   149
	parser to another rule. They can link rules to each other and so build rule sequences more 
williamr@2
   150
	complex than a simple tree.
williamr@2
   151
williamr@2
   152
All the top-level rules are stored as attributes of the root node. The attribute type is a string
williamr@2
   153
 that names the rule; the attribute value is a pointer to the node that implements the rule.
williamr@2
   154
williamr@2
   155
The class supplies functions that encapsulate adding rules appropriately to the tree. The parser 
williamr@2
   156
provider creates a derived class that implements the virtual method TreeL() that uses these 
williamr@2
   157
functions to create a BNF rule tree.
williamr@2
   158
williamr@2
   159
The user of the parser initialises the parser with ResetL(), and then passes input data to the 
williamr@2
   160
parser using ProcessData(). The parser supports partial parsing: the input stream does not have 
williamr@2
   161
to completed before parsing can begin. As soon as data is added, the parser attempts to parse it.
williamr@2
   162
williamr@2
   163
	@publishedAll
williamr@4
   164
	@deprecated
williamr@2
   165
williamr@2
   166
*/
williamr@2
   167
	{
williamr@2
   168
protected:
williamr@2
   169
	/** Defines a type to handle a stack of rules. */
williamr@2
   170
	typedef CStack<CBNFNode, EFalse> CRuleStack;
williamr@2
   171
williamr@2
   172
	/** Type definition for a callback function pointer
williamr@2
   173
		Callback functions need to get a reference to the parser as parameter
williamr@2
   174
		and they need to be static. */
williamr@2
   175
	typedef void (TRuleCallback)(CBNFParser&);
williamr@2
   176
williamr@2
   177
public:
williamr@2
   178
	// Constructor for a new parser instance
williamr@2
   179
	//
williamr@2
   180
	// Input:
williamr@2
   181
	// aLUT - reference to attribute lookuptable; used to store all the stuff in the parser rule tree
williamr@2
   182
	//
williamr@2
   183
	//##ModelId=3B6669EA00F8
williamr@2
   184
	IMPORT_C static CBNFParser* NewL(CAttributeLookupTable& aLUT);
williamr@2
   185
williamr@2
   186
	//##ModelId=3B6669EA00F7
williamr@2
   187
	IMPORT_C virtual ~CBNFParser();
williamr@2
   188
williamr@2
   189
	// Prepare the parser to take in fresh stream of data.
williamr@2
   190
	// THIS METHOD MUST BE CALLED BEFORE DATA CAN BE PROCESSED BY THE PARSER!!
williamr@2
   191
	// Calls TreeL in order to create the parsing rule tree if no tree already
williamr@2
   192
	// exists.
williamr@2
   193
	//##ModelId=3B6669EA00EF
williamr@2
   194
	IMPORT_C virtual void ResetL();
williamr@2
   195
williamr@2
   196
	/** Checks if the input stream was completely processed
williamr@2
   197
	@return ETrue if all of the data was processed, EFalse if the data didn't match to the parsing rules
williamr@2
   198
	*/
williamr@2
   199
	//##ModelId=3B6669EA00EE
williamr@2
   200
	TBool Valid() const { return iStringComplete && (iString.Length() == 0); }
williamr@2
   201
williamr@2
   202
	/** Concatenates the rest of the input stream (which hasn't yet been processed)
williamr@2
   203
	into a single string. The ownership of the string is given to the caller.
williamr@2
   204
	@return String containing the remaining data to be parsed. OWNERSHIP PASSED TO CALLED. */
williamr@2
   205
	//##ModelId=3B6669EA00ED
williamr@2
   206
	HBufC* StringL() const { return iString.StringL(); }
williamr@2
   207
williamr@2
   208
	/** Gets a pointer to the rule node currently being processed.
williamr@2
   209
	@return Rule node */
williamr@2
   210
	//##ModelId=3B6669EA00E3
williamr@2
   211
	CBNFNode* CurrentRule() { return iCurrentRule; }
williamr@2
   212
williamr@2
   213
	// Set reference to an attribute lookup table
williamr@2
   214
	//##ModelId=3B6669EA00C5
williamr@2
   215
	void SetAttributeLookupTable(CAttributeLookupTable& aAttributeLookupTable);
williamr@2
   216
williamr@2
   217
	// methods to allow the input stream to be marked so that the callbacks
williamr@2
   218
	// can determine those parts which successfully matched
williamr@2
   219
williamr@2
   220
	/** Set a mark to the current position of the input stream. 
williamr@2
   221
williamr@2
   222
	The mark acts as a tag in the stream currently being processed.
williamr@2
   223
	As we process further along the stream after adding the mark, we can perform
williamr@2
   224
	a rollback to the most previously set mark and start processing again (e.g. OR rule
williamr@2
   225
	works this way). The string fragments won't be consumed (deleted) until
williamr@2
   226
	all the marks on a fragment (and fragments before that) are deleted. */
williamr@2
   227
	//##ModelId=3B6669EA00BC
williamr@2
   228
	void Mark() { iString.Mark(); }; // **Mark can leave**
williamr@2
   229
williamr@2
   230
	/** Get string between the "cursor position" and the latest mark on the stream.
williamr@2
   231
	
williamr@2
   232
	@return Pointer to the string from the previous mark on to the current position
williamr@2
   233
			of processed string. OWNERSHIP OF THE STRING GIVEN TO THE CALLER. */
williamr@2
   234
	//##ModelId=3B6669EA00BB
williamr@2
   235
	HBufC* MarkedL() { return iString.MarkedL(); };
williamr@2
   236
williamr@2
   237
	/** Gets the marked string with a string added before the mached string.
williamr@2
   238
	@see MarkedL()
williamr@2
   239
	@return A string cosisting of aInitialText appended with the marked string.
williamr@2
   240
	          OWNERSHIP OF THE CONSTRUCTED STRING IS GIVEN TO THE CALLER. */
williamr@2
   241
	//##ModelId=3B6669EA009E
williamr@2
   242
	HBufC* MarkedWithInitialTextL(const TDesC& aInitialText) { return iString.MarkedWithInitialTextL(aInitialText); };
williamr@2
   243
williamr@2
   244
	/** Removes the latest mark. All the marks are stored in a stack and this removes
williamr@2
   245
	the topmost mark.*/
williamr@2
   246
	//##ModelId=3B6669EA009D
williamr@2
   247
	void DeleteMark() { iString.DeleteMark(); };
williamr@2
   248
williamr@2
   249
	// methods to determine it the used rule actually matched (typically used in post callbacks)
williamr@2
   250
	/** Tests if the used rule matched.
williamr@2
   251
williamr@2
   252
	This is typically used in post-rule callbacks.
williamr@2
   253
williamr@2
   254
	@return True if the used rule matched; otherwise false
williamr@2
   255
	*/
williamr@2
   256
	//##ModelId=3B6669EA0094
williamr@2
   257
	TBool RuleMatched() const { return iSubRuleMatched; };
williamr@2
   258
	/** Tests if an Optional node sub-rule matched.
williamr@2
   259
williamr@2
   260
	@return True if the sub- rule matched; otherwise false
williamr@2
   261
	*/
williamr@2
   262
	//##ModelId=3B6669EA0093
williamr@2
   263
	TBool OptionalMatched() const { return iOptionalMatched; };
williamr@2
   264
williamr@2
   265
	// Create new rule tree root node.
williamr@2
   266
	// This method creates a new single instance of CBNFNode, which shall act as the root
williamr@2
   267
	// node of the rule tree, which implements the BNF rules for parsing the input stream.
williamr@2
   268
	// All the other rules are attached as attributes to this node.
williamr@2
   269
	// The root node should have single child node, which should be a reference to the
williamr@2
   270
	// "logical root" of the rule tree. This can be done be attaching the logical root
williamr@2
   271
	// rule as a component to the root rule.
williamr@2
   272
	//##ModelId=3B6669EA0089
williamr@2
   273
	IMPORT_C CBNFNode* NewBNFL();
williamr@2
   274
williamr@2
   275
	// Add a new rule to a rule tree.
williamr@2
   276
	//
williamr@2
   277
	// Input:
williamr@2
   278
	//	aRootRule - Pointer to the root bnf node (created with NewBNFL() ).
williamr@2
   279
	//	aRuleName - Reference to a string identifying this rule. The string is used
williamr@2
   280
	//				to make references to this rule from other rule's subtrees.
williamr@2
   281
	//	aData	  - Pointer to a data string; used with EExact and ESelect type rules
williamr@2
   282
	//              to match actual text strings.
williamr@2
   283
	//	aPreRule  - Function pointer to a prerule function that gets called _BEFORE_
williamr@2
   284
	//				we start processing this rule and its children (i.e. the rule subtree)
williamr@2
   285
	//	aPostRule - Function pointer to a postrule function which is called _AFTER_
williamr@2
   286
	//              we have processed this rule (i.e. when we return up from the subtree
williamr@2
   287
	//              and this rule is finished).
williamr@2
   288
	//
williamr@2
   289
	// Return:
williamr@2
   290
	//	CBNFNode& - Reference to the newly created rule node in the rule tree
williamr@2
   291
	//
williamr@2
   292
	//##ModelId=3B6669E90326
williamr@2
   293
	IMPORT_C CBNFNode& NewRuleL(CBNFNode* aRootRule, 
williamr@2
   294
					const TDesC& aRuleName, 
williamr@2
   295
					TParserNodeTypes aRuleType, 
williamr@2
   296
					HBufC* aData, 
williamr@2
   297
					TRuleCallback* aPreRule, 
williamr@2
   298
					TRuleCallback* aPostRule);
williamr@2
   299
williamr@2
   300
	// Overridden version of the NewRuleL. Takes reference to the data instead of owning it.
williamr@2
   301
	//##ModelId=3B6669E903D1
williamr@2
   302
	IMPORT_C CBNFNode& NewRuleL(CBNFNode* aRootRule, 
williamr@2
   303
					const TDesC& aRuleName, 
williamr@2
   304
					TParserNodeTypes aRuleType, 
williamr@2
   305
					const TDesC& aData, 
williamr@2
   306
					TRuleCallback* aPreRule, 
williamr@2
   307
					TRuleCallback* aPostRule);
williamr@2
   308
williamr@2
   309
	// construct a new rule component not attached to a rule.
williamr@2
   310
	//##ModelId=3B6669E9018C
williamr@2
   311
	IMPORT_C CBNFNode* NewComponentL(TParserNodeTypes aRuleType, const TDesC& aData);
williamr@2
   312
	//##ModelId=3B6669E901B4
williamr@2
   313
	IMPORT_C CBNFNode* NewComponentL(TParserNodeTypes aRuleType, HBufC* aData = NULL, TRuleCallback* aPreRule = NULL, TRuleCallback* aPostRule = NULL);
williamr@2
   314
williamr@2
   315
	// create a reference component to the rule of the given name
williamr@2
   316
	// which is not attached to any rule.
williamr@2
   317
	//##ModelId=3B6669E90204
williamr@2
   318
	IMPORT_C CBNFNode* NewComponentL(CBNFNode* aRootRule, const TDesC& aRuleName);
williamr@2
   319
williamr@2
   320
	// Methods to create a new subrule to the given parent rule.
williamr@2
   321
	// These methods can be used to build the subtrees to the "main rules" attached to the root node.
williamr@2
   322
	//
williamr@2
   323
	// Input:
williamr@2
   324
	//	aParentRule - The rule for which the new rule shall be added as a child
williamr@2
   325
	//  aRuleType - Type of the new rule
williamr@2
   326
	//  aData - Data for the rule; the string to match for an EExact rule, the selection character set for ESelect
williamr@2
   327
	//
williamr@2
   328
	//	aPreRule - Pre rule callback function pointer
williamr@2
   329
	//  aPostRule - Post rule callback function pointer
williamr@2
   330
	// Return:
williamr@2
   331
	//	CBNFNode& - reference to the new rule
williamr@2
   332
	//
williamr@2
   333
	//##ModelId=3B6669E9022C
williamr@2
   334
	IMPORT_C CBNFNode& NewComponentL(CBNFNode &aParentRule, TParserNodeTypes aRuleType, const TDesC& aData);
williamr@2
   335
	//##ModelId=3B6669E90268
williamr@2
   336
	IMPORT_C CBNFNode& NewComponentL(CBNFNode &aParentRule, TParserNodeTypes aRuleType, HBufC* aData = NULL, TRuleCallback* aPreRule = NULL, TRuleCallback* aPostRule = NULL);
williamr@2
   337
	
williamr@2
   338
	// Create a reference to another rule and attach this reference as a child of the given parent.
williamr@2
   339
	// Creates a child node of type EReference for the parent. This reference node
williamr@2
   340
	// hold the pointer to the rule we are refering to.
williamr@2
   341
	// Using references we can link rules to each other and build complex rule trees
williamr@2
   342
	// even though they don't physically form a complete tree.
williamr@2
   343
	// Notice, that the rule we are refering to does not necessarily need to exist, yet!
williamr@2
   344
	//
williamr@2
   345
	// Input:
williamr@2
   346
	//	aRootRule - The Root node to the rule tree (created with NewBNFL). This is needed to
williamr@2
   347
	//				find the rule we are refering to with the string.
williamr@2
   348
	//	aParentRule - The parent rule of the newly created reference 
williamr@2
   349
	//	aRuleName - The "id string" of the rule we are refering to.
williamr@2
   350
	//##ModelId=3B6669E902CC
williamr@2
   351
	IMPORT_C CBNFNode& NewComponentL(CBNFNode* aRootRule, CBNFNode &aParentRule, const TDesC& aRuleName);
williamr@2
   352
	
williamr@2
   353
	// add additional attributes to components of rules (i.e. range values)
williamr@2
   354
	//##ModelId=3B6669E900F6
williamr@2
   355
	IMPORT_C void AddComponentAttributeL(CBNFNode& aRule, CBNFNodeAttributeType aAttribute, TInt aInt);
williamr@2
   356
	
williamr@2
   357
	// re-implementations of MDataProviderObserver methods
williamr@2
   358
	//##ModelId=3B6669E900D8
williamr@2
   359
	IMPORT_C virtual void ProcessDataL(HBufC8& aData);
williamr@2
   360
	//##ModelId=3B6669E900AF
williamr@2
   361
	IMPORT_C virtual void SetStatus(TInt aStatus = KErrNone);
williamr@2
   362
	//##ModelId=3B6669E90069
williamr@2
   363
	IMPORT_C virtual void SetDocumentTypeL(const TDesC&);
williamr@2
   364
	//##ModelId=3B6669E90087
williamr@2
   365
	IMPORT_C virtual void SetDocumentTypeL(const TDesC&, const TDesC&);
williamr@2
   366
	//##ModelId=3B6669E90055
williamr@2
   367
	IMPORT_C virtual void SetDataExpected(TInt);
williamr@2
   368
	//##ModelId=3B6669E90041
williamr@2
   369
	IMPORT_C virtual void SetBaseUriL(const TDesC* aBaseUri);
williamr@2
   370
	//##ModelId=3B6669E90038
williamr@2
   371
	IMPORT_C virtual void MDataProviderObserverReserved1();
williamr@2
   372
	//##ModelId=3B6669E90037
williamr@2
   373
	IMPORT_C virtual void MDataProviderObserverReserved2();
williamr@2
   374
williamr@2
   375
	// Tell the parser, that we all the data has been passed in.
williamr@2
   376
	// This method attempts to parse what ever is left of the input stream if it wasn't
williamr@2
   377
	// already finished.
williamr@2
   378
	//##ModelId=3B6669E9002E
williamr@2
   379
	IMPORT_C void CommitL();
williamr@2
   380
williamr@2
   381
	/** Get the current state of the parser. 
williamr@2
   382
	@return Parser state */
williamr@2
   383
	//##ModelId=3B6669E9002D
williamr@2
   384
	TParseState State() const {return(iParsing);};
williamr@2
   385
williamr@2
   386
protected:
williamr@2
   387
	IMPORT_C CBNFParser(CAttributeLookupTable& aLUT);
williamr@2
   388
williamr@2
   389
	// Each of the following functions is a handler method for a specific type of a rule
williamr@2
   390
	// node. For example, ReferenceL handles reference nodes etc.
williamr@2
   391
	// These methods are called by PerformRuleL.
williamr@2
   392
	//
williamr@2
   393
	// Input:
williamr@2
   394
	//	aRule - reference to the rule being processed
williamr@2
   395
	//	aMatched - reference to a CFragmentedString::TStringMatch variable, which holds
williamr@2
   396
	//             the information if the string or character we previously were trying to
williamr@2
   397
	//             match actually matched.
williamr@2
   398
	// Return:
williamr@2
   399
	//	TBool - We return ETrue if we have completed processing this node. If the processing
williamr@2
   400
	//          still continues we return EFalse. For example, an EAnd rule would return
williamr@2
   401
	//          ETrue if all of its chidren had matched or if a rule didn't match. In the first
williamr@2
   402
	//          case the EAnd rule would have turned out to be true (aMatched = EMatched) since
williamr@2
   403
	//          all of its children were true, but in the latter case we can stop processing the
williamr@2
   404
	//          EAnd rule, since a subrule to the And didn't match and this means that the And
williamr@2
   405
	//          expression can not be true. Either way, the processing of the And ends and we
williamr@2
   406
	//          may return ETrue;
williamr@2
   407
	//
williamr@2
   408
	//##ModelId=3B6669E90005
williamr@2
   409
    IMPORT_C virtual TBool ReferenceL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   410
	//##ModelId=3B6669E803BB
williamr@2
   411
    IMPORT_C virtual TBool ExactL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   412
	//##ModelId=3B6669E80389
williamr@2
   413
    IMPORT_C virtual TBool RangeL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   414
	//##ModelId=3B6669E80343
williamr@2
   415
    IMPORT_C virtual TBool SelectL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   416
	//##ModelId=3B6669E80311
williamr@2
   417
    IMPORT_C virtual TBool WithoutL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   418
	//##ModelId=3B6669E802D5
williamr@2
   419
    IMPORT_C virtual TBool AndL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   420
	//##ModelId=3B6669E80299
williamr@2
   421
    IMPORT_C virtual TBool OrL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   422
	//##ModelId=3B6669E80271
williamr@2
   423
    IMPORT_C virtual TBool OptionalL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   424
	//##ModelId=3B6669E8023F
williamr@2
   425
    IMPORT_C virtual TBool NMoreL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   426
williamr@2
   427
	// A method to add a callback to a rule
williamr@2
   428
	//
williamr@2
   429
	// Input:
williamr@2
   430
	//	aRule - The rule to which the callback is to be added
williamr@2
   431
	//	aCallbackID - Either CBNFNode::KPreRuleCallback() or CBNFNode::KPostRuleCallback()
williamr@2
   432
	//                Defines the type of the callback function (i.e. is it to be called before
williamr@2
   433
	//                or after the rule has been processed).
williamr@2
   434
	//	aCallback - The callback function pointer
williamr@2
   435
	//
williamr@2
   436
	//##ModelId=3B6669E80203
williamr@2
   437
    IMPORT_C virtual void AddRuleCallbackL(CBNFNode& aRule, const TDesC* aCallbackID, TRuleCallback* aCallback);
williamr@2
   438
	//##ModelId=3B6669E801EF
williamr@2
   439
    IMPORT_C virtual void ExecutePreRuleCallbackL(CBNFNode& aRule);
williamr@2
   440
	//##ModelId=3B6669E801D1
williamr@2
   441
    IMPORT_C virtual void ExecutePostRuleCallbackL(CBNFNode& aRule);
williamr@2
   442
williamr@2
   443
	// the method TreeL() should be reimplemented to generate a BNF rule tree and return
williamr@2
   444
	// ownership of it. This is the rule tree which will be to parse the input stream.
williamr@2
   445
	// See XmlPars.cpp or DTDMDL.cpp for example.
williamr@2
   446
	//##ModelId=3B6669E801D0
williamr@2
   447
	IMPORT_C virtual CBNFNode* TreeL();
williamr@2
   448
williamr@2
   449
	// methods which are invoked when the parser encounters a conditional
williamr@2
   450
	// point in the BNF grammar (i.e. And/Or)
williamr@2
   451
	//##ModelId=3B6669E801B2
williamr@2
   452
    IMPORT_C virtual void StartConditional(TParserNodeTypes aRuleType);
williamr@2
   453
	//##ModelId=3B6669E80180
williamr@2
   454
	IMPORT_C virtual void EndConditional(TParserNodeTypes aRuleType, TBool aSuccess);
williamr@2
   455
williamr@2
   456
	// A callback function to insert a mark to the current position of the stream
williamr@2
   457
	// being processed. Adding mark is a very common callback operation befor starting
williamr@2
   458
	// to process a rule, hence the method is provided by the parser.
williamr@2
   459
	//##ModelId=3B6669E8016C
williamr@2
   460
	IMPORT_C static void MarkCallback(CBNFParser& aParser);
williamr@2
   461
williamr@2
   462
	// returns the LUT used by this parser.
williamr@2
   463
	//##ModelId=3B6669E80163
williamr@2
   464
	IMPORT_C CAttributeLookupTable& AttributeLUT() const;
williamr@2
   465
williamr@2
   466
	// method which does the actual iterative parsing
williamr@2
   467
	//##ModelId=3B6669E80162
williamr@2
   468
	IMPORT_C TBool ParseL();
williamr@2
   469
williamr@2
   470
	// A rule to handle a node in the rule tree. This method just calls the appropriate
williamr@2
   471
	// handler method according to the rule type.
williamr@2
   472
	//##ModelId=3B6669E8013A
williamr@2
   473
    IMPORT_C virtual TBool PerformRuleL(CBNFNode& aRule, CFragmentedString::TStringMatch& aMatched);
williamr@2
   474
williamr@2
   475
	//##ModelId=3B6669E8011C
williamr@2
   476
	/** Sets the parser state.
williamr@2
   477
williamr@2
   478
	@param aState Parser state
williamr@2
   479
	*/
williamr@2
   480
	void SetState(TParseState aState) {iParsing=aState;};
williamr@2
   481
williamr@2
   482
protected:
williamr@2
   483
	/** Storage object for all the attributes and identifiers in a tree */
williamr@2
   484
	//##ModelId=3B6669E80108
williamr@2
   485
	CAttributeLookupTable& iLUT;	
williamr@2
   486
williamr@2
   487
	/** An utility object which stores all the buffers passed into the parser
williamr@2
   488
	and represents them as if they would form a single, continuous string.
williamr@2
   489
	This class also performs the actual physical matching/selection of the strings
williamr@2
   490
	and holds the marks set onto the string.*/
williamr@2
   491
	//##ModelId=3B6669E800EA
williamr@2
   492
	CFragmentedString iString;
williamr@2
   493
	/** Flag indicating if the input stream has been completely processed. */ 
williamr@2
   494
	//##ModelId=3B6669E800D6
williamr@2
   495
	TBool iStringComplete; // more input stream has completed
williamr@2
   496
williamr@2
   497
	/** The BNF tree the parser is using to parse the input stream.*/
williamr@2
   498
	//##ModelId=3B6669E800C2
williamr@2
   499
	CBNFNode* iTree;        // the BNF tree we are using to parse the input stream
williamr@2
   500
williamr@2
   501
	/** A stack of rules from iTree which are waiting to be completed.
williamr@2
   502
	The stack basically holds the path along the rule tree. */
williamr@2
   503
	//##ModelId=3B6669E800AE
williamr@2
   504
	CRuleStack iRuleStack;  
williamr@2
   505
	/** The BNF rule that is currently being processed. */
williamr@2
   506
	//##ModelId=3B6669E80090
williamr@2
   507
	CBNFNode* iCurrentRule; // the BNF rule we are currently using
williamr@2
   508
williamr@2
   509
	// when returning to a rule in the rulestack this indicates 
williamr@2
   510
	// if the child rule matched correctly
williamr@2
   511
	/** Flag that indicates when returning to a rule in the rulestack if the child rule matched correctly. */
williamr@2
   512
	//##ModelId=3B6669E8007C
williamr@2
   513
	TBool iSubRuleMatched;
williamr@2
   514
	/** Flag that indicates when returning to a rule in the rulestack if an optional rule matched correctly. */
williamr@2
   515
	//##ModelId=3B6669E8006A
williamr@2
   516
	TBool iOptionalMatched;
williamr@2
   517
williamr@2
   518
	/** The child rule we are returning from (if any). 
williamr@2
   519
	If this is NULL we are new to this BNF rule.*/
williamr@2
   520
	//##ModelId=3B6669E80054
williamr@2
   521
	CBNFNode* iSubRule;     
williamr@2
   522
williamr@2
   523
	/** Parser state. */
williamr@2
   524
	//##ModelId=3B6669E8004A
williamr@2
   525
	TParseState iParsing;
williamr@2
   526
	/** Input stream matched rule flag. */
williamr@2
   527
	//##ModelId=3B6669E80038
williamr@2
   528
    CFragmentedString::TStringMatch iMatched;
williamr@2
   529
williamr@2
   530
	// Storage pointers for strings identifying certain attributes on the rule nodes
williamr@2
   531
	/** Stores attribute identifier for reference string attributes. */
williamr@2
   532
	//##ModelId=3B6669E8002C
williamr@2
   533
	const TDesC* iReferenceString;
williamr@2
   534
	/** Stores attribute identifier for range start attributes. */
williamr@2
   535
	//##ModelId=3B6669E8001A
williamr@2
   536
	const TDesC* iRangeStart;
williamr@2
   537
	/** Stores attribute identifier for range end attributes. */
williamr@2
   538
	//##ModelId=3B6669E80010
williamr@2
   539
	const TDesC* iRangeEnd;
williamr@2
   540
	/** Stores attribute identifier for nmore minimum attributes. */
williamr@2
   541
	//##ModelId=3B6669E80006
williamr@2
   542
	const TDesC* iMoreMinimum;
williamr@2
   543
	/** Stores attribute identifier for nmore count attributes. */
williamr@2
   544
	//##ModelId=3B6669E703DA
williamr@2
   545
	const TDesC* iMoreCount;
williamr@2
   546
	/** Stores attribute identifier for nmore maximum attributes. */
williamr@2
   547
	//##ModelId=3B6669E703D0
williamr@2
   548
	const TDesC* iMoreMaximum;
williamr@2
   549
	/** Stores attribute identifier for pre-rule callback attributes. */
williamr@2
   550
	//##ModelId=3B6669E703C6
williamr@2
   551
	const TDesC* iPreRuleCallback;
williamr@2
   552
	/** Stores attribute identifier for post-rule callback attributes. */
williamr@2
   553
	//##ModelId=3B6669E703BC
williamr@2
   554
	const TDesC* iPostRuleCallback;
williamr@2
   555
	};
williamr@2
   556
williamr@2
   557
#endif