Source code of Windows XP (NT5)
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.

174 lines
4.8 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. //+---------------------------------------------------------------------------
  41. //
  42. // Class: CQueryParser
  43. //
  44. // Purpose: Changes a query string into a CRestriction for the
  45. // content index.
  46. //
  47. // History: 30-Apr-92 AmyA Created.
  48. // 31-May-94 t-jeffc Extended query grammar.
  49. //
  50. //----------------------------------------------------------------------------
  51. class CQueryParser
  52. {
  53. public:
  54. CQueryParser( CQueryScanner & scanner,
  55. ULONG rankMethod,
  56. LCID locale,
  57. WCHAR const * wcsProperty,
  58. PropertyType propType,
  59. IColumnMapper *pList )
  60. :_scan( scanner ),
  61. _rankMethod( rankMethod ),
  62. _locale( locale ),
  63. _xList( pList ),
  64. _wcsProperty( 0 ),
  65. _propType( propType )
  66. {
  67. _xList->AddRef();
  68. SetCurrentProperty( wcsProperty, propType );
  69. }
  70. ~CQueryParser() { delete [] _wcsProperty; }
  71. CDbRestriction * ParseQueryPhrase();
  72. WCHAR const * GetCurrentProperty() { return _wcsProperty; }
  73. PropertyType GetPropertyType() const { return _propType; }
  74. BOOL IsRegEx() { return ( REGEX == _propType ); }
  75. private:
  76. CDbRestriction * Query( CDbNodeRestriction * pExpr );
  77. CDbRestriction * QExpr( CDbBooleanNodeRestriction * pExpr );
  78. CDbRestriction * QTerm( CDbBooleanNodeRestriction * pExpr );
  79. CDbRestriction * QProp();
  80. CDbRestriction * QFactor();
  81. CDbRestriction * QGroup( CDbProximityNodeRestriction * pExpr );
  82. CDbRestriction * QPhrase();
  83. CDbRestriction * ParsePropertyRst();
  84. void SetCurrentProperty( WCHAR const * wcsProperty, PropertyType propType );
  85. CQueryScanner & _scan;
  86. ULONG _rankMethod;
  87. LCID _locale;
  88. WCHAR * _wcsProperty;
  89. PropertyType _propType;
  90. XInterface<IColumnMapper> _xList;
  91. };
  92. //+---------------------------------------------------------------------------
  93. //
  94. // Class: CPropertyValueParser
  95. //
  96. // Purpose: To intepret a sequence of tokens from a scanner
  97. // and place the results in a CStorageVariant
  98. //
  99. // Notes: This class throws CParserException when errors occur.
  100. //
  101. // History: 02-Mar-95 t-colinb Created.
  102. // 02-Sep-98 KLam Added locale
  103. //
  104. //----------------------------------------------------------------------------
  105. class CPropertyValueParser
  106. {
  107. public :
  108. CPropertyValueParser( CQueryScanner &scanner, DBTYPE PropertyType, LCID locale );
  109. CStorageVariant *AcquireStgVariant( void )
  110. {
  111. return _pStgVariant.Acquire();
  112. }
  113. static BOOL CheckForRelativeDate( WCHAR const * phrase, FILETIME & ft );
  114. private :
  115. void ParseDateTime( WCHAR const * phrase, FILETIME & ft );
  116. LCID _locale;
  117. XPtr<CStorageVariant> _pStgVariant;
  118. };
  119. //+---------------------------------------------------------------------------
  120. //
  121. // Class: CParserException
  122. //
  123. // Purpose: Exception class for parse errors
  124. //
  125. // History: 17-May-94 t-jeffc Created.
  126. //
  127. //----------------------------------------------------------------------------
  128. class CParserException : public CException
  129. {
  130. public:
  131. CParserException( SCODE pe )
  132. : CException( pe )
  133. {
  134. }
  135. SCODE GetParseError()
  136. {
  137. return GetErrorCode();
  138. }
  139. };