Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
5.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1998.
  5. //
  6. // File: PARSER.HXX
  7. //
  8. // Contents: Query Parsers
  9. //
  10. // Classes: CQueryParser
  11. // CPropertyValueParser
  12. // CParserException
  13. //
  14. // History: 30-Apr-92 AmyA Created.
  15. // 15-Jun-94 t-jeffc Added exception classes.
  16. // 02-Mar-95 t-colinb Added CPropertyValueParser class and
  17. // some more exceptions to handle
  18. // the parsing of vector properties
  19. //
  20. //----------------------------------------------------------------------------
  21. #pragma once
  22. typedef XPtr<CDbRestriction> XDbRestriction;
  23. typedef XPtr<CDbNodeRestriction> XDbNodeRestriction;
  24. typedef XPtr<CDbNotRestriction> XDbNotRestriction;
  25. typedef XPtr<CDbVectorRestriction> XDbVectorRestriction;
  26. typedef XPtr<CDbPropertyRestriction> XDbPropertyRestriction;
  27. typedef XPtr<CDbContentRestriction> XDbContentRestriction;
  28. typedef XPtr<CDbNatLangRestriction> XDbNatLangRestriction;
  29. typedef XPtr<CDbBooleanNodeRestriction> XDbBooleanNodeRestriction;
  30. typedef XPtr<CDbProximityNodeRestriction> XDbProximityNodeRestriction;
  31. // forward decls
  32. class CQueryScanner;
  33. // types of properties - content, regular expression and natural language
  34. enum PropertyType
  35. {
  36. CONTENTS,
  37. REGEX,
  38. NATLANGUAGE
  39. };
  40. const ULONG CI_PARSER_MAX_RECURSION_DEPTH = 1000;
  41. //+---------------------------------------------------------------------------
  42. //
  43. // Class: CQueryParser
  44. //
  45. // Purpose: Changes a query string into a CRestriction for the
  46. // content index.
  47. //
  48. // History: 30-Apr-92 AmyA Created.
  49. // 31-May-94 t-jeffc Extended query grammar.
  50. //
  51. //----------------------------------------------------------------------------
  52. class CQueryParser
  53. {
  54. public:
  55. CQueryParser( CQueryScanner & scanner,
  56. ULONG rankMethod,
  57. LCID locale,
  58. WCHAR const * wcsProperty,
  59. PropertyType propType,
  60. IColumnMapper *pList )
  61. :_scan( scanner ),
  62. _rankMethod( rankMethod ),
  63. _locale( locale ),
  64. _xList( pList ),
  65. _wcsProperty( 0 ),
  66. _propType( propType ),
  67. _cRecursionDepth( 0 )
  68. {
  69. _xList->AddRef();
  70. SetCurrentProperty( wcsProperty, propType );
  71. }
  72. ~CQueryParser() { delete [] _wcsProperty; }
  73. CDbRestriction * ParseQueryPhrase();
  74. WCHAR const * GetCurrentProperty() { return _wcsProperty; }
  75. PropertyType GetPropertyType() const { return _propType; }
  76. BOOL IsRegEx() { return ( REGEX == _propType ); }
  77. void IncrementRecursionDepth()
  78. {
  79. _cRecursionDepth++;
  80. if ( _cRecursionDepth > CI_PARSER_MAX_RECURSION_DEPTH )
  81. THROW( CException( QUERY_E_TOOCOMPLEX ) );
  82. }
  83. void DecrementRecursionDepth()
  84. {
  85. Win4Assert( 0 != _cRecursionDepth );
  86. _cRecursionDepth--;
  87. }
  88. private:
  89. CDbRestriction * Query( CDbNodeRestriction * pExpr );
  90. CDbRestriction * QExpr( CDbBooleanNodeRestriction * pExpr );
  91. CDbRestriction * QTerm( CDbBooleanNodeRestriction * pExpr );
  92. CDbRestriction * QProp();
  93. CDbRestriction * QFactor();
  94. CDbRestriction * QGroup( CDbProximityNodeRestriction * pExpr );
  95. CDbRestriction * QPhrase();
  96. CDbRestriction * ParsePropertyRst();
  97. void SetCurrentProperty( WCHAR const * wcsProperty, PropertyType propType );
  98. CQueryScanner & _scan;
  99. ULONG _rankMethod;
  100. LCID _locale;
  101. ULONG _cRecursionDepth;
  102. WCHAR * _wcsProperty;
  103. PropertyType _propType;
  104. XInterface<IColumnMapper> _xList;
  105. };
  106. //+---------------------------------------------------------------------------
  107. //
  108. // Class: CPropertyValueParser
  109. //
  110. // Purpose: To intepret a sequence of tokens from a scanner
  111. // and place the results in a CStorageVariant
  112. //
  113. // Notes: This class throws CParserException when errors occur.
  114. //
  115. // History: 02-Mar-95 t-colinb Created.
  116. // 02-Sep-98 KLam Added locale
  117. //
  118. //----------------------------------------------------------------------------
  119. class CPropertyValueParser
  120. {
  121. public :
  122. CPropertyValueParser( CQueryScanner &scanner, DBTYPE PropertyType, LCID locale );
  123. CStorageVariant *AcquireStgVariant( void )
  124. {
  125. return _pStgVariant.Acquire();
  126. }
  127. static BOOL CheckForRelativeDate( WCHAR const * phrase, FILETIME & ft );
  128. private :
  129. void ParseDateTime( WCHAR const * phrase, FILETIME & ft );
  130. LCID _locale;
  131. XPtr<CStorageVariant> _pStgVariant;
  132. };
  133. //+---------------------------------------------------------------------------
  134. //
  135. // Class: CParserException
  136. //
  137. // Purpose: Exception class for parse errors
  138. //
  139. // History: 17-May-94 t-jeffc Created.
  140. //
  141. //----------------------------------------------------------------------------
  142. class CParserException : public CException
  143. {
  144. public:
  145. CParserException( SCODE pe )
  146. : CException( pe )
  147. {
  148. }
  149. SCODE GetParseError()
  150. {
  151. return GetErrorCode();
  152. }
  153. };