00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef RM_MFC_SHADER_SYNTAX_PARSER_H
00018 #define RM_MFC_SHADER_SYNTAX_PARSER_H
00019
00020
00021
00022
00023 #define MAX_NUM_CHAR 256
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class RMMFCUTIL_API RmMFCShaderSyntaxParser
00035 {
00036 public:
00037
00038
00039
00040 struct ParseInput
00041 {
00042 const TCHAR *pBuffer;
00043 const RmShaderCharType *pRmShaderCharTypeTable;
00044
00045 int bufferSize;
00046 int parseBeginPos;
00047 int parseEndPos;
00048 };
00049
00050
00051 struct ParseResult
00052 {
00053 bool bProcessed;
00054 bool bEndReached;
00055 int parseNextPos;
00056 };
00057
00058 public :
00059
00060
00061
00062 class Keyword
00063 {
00064 public :
00065 Keyword( const TCHAR* szKeyword );
00066 virtual ~Keyword();
00067
00068
00069 const RmStringT& GetString() const { return m_keywordString; };
00070
00071
00072 bool Match( const TCHAR* szStr, bool bCaseSensitive = true ) const;
00073
00074 private:
00075 RmStringT m_keywordString;
00076 };
00077
00078 typedef RmLinkedList<Keyword*> KeywordList;
00079 typedef KeywordList::iterator KeywordIterator;
00080 typedef KeywordList::const_iterator KeywordConstIterator;
00081
00082
00083
00084
00085 class KeywordCategory
00086 {
00087 public :
00088
00089
00090
00091 typedef KeywordList KeywordTable[MAX_NUM_CHAR];
00092
00093 public :
00094 KeywordCategory( const TCHAR* szKeywordCategoryName, bool bOperatorType );
00095 virtual ~KeywordCategory();
00096
00097
00098 const RmStringT& GetKeywordCategoryName() const { return m_keywordCategoryName; };
00099
00100
00101 bool IsOperatorType() const { return m_bOperatorType; };
00102
00103
00104 bool Match( const TCHAR* szStr, bool bCaseSensitive = false ) const;
00105
00106
00107 void AddKeyword( const TCHAR *szKeyword );
00108 void RemoveKeyword( const TCHAR *szKeyword );
00109 void RemoveAllKeywords();
00110
00111
00112 Keyword* FindKeyword( const TCHAR *szKeyword );
00113 const Keyword* FindKeyword( const TCHAR *szKeyword ) const;
00114
00115
00116
00117
00118
00119
00120
00121
00122 void Parse( const ParseInput& parseInput,
00123 ParseResult& parseResult );
00124
00125
00126 void SetParser( RmMFCShaderSyntaxParser *pParser ) { m_pParser = pParser; };
00127
00128 RmMFCShaderSyntaxParser* GetParser() { return m_pParser; };
00129 const RmMFCShaderSyntaxParser* GetParser() const { return m_pParser; };
00130
00131
00132 void SetColor( COLORREF color ) { m_color = color; };
00133 COLORREF GetColor() const { return m_color; };
00134
00135
00136 KeywordTable& GetKeywordTable() { return m_keywordTable; };
00137 const KeywordTable& GetKeywordTable() const { return m_keywordTable; };
00138
00139 protected :
00140 RmMFCShaderSyntaxParser *m_pParser;
00141
00142 RmStringT m_keywordCategoryName;
00143 bool m_bOperatorType;
00144
00145 KeywordTable m_keywordTable;
00146
00147 COLORREF m_color;
00148 };
00149
00150 typedef RmLinkedList<KeywordCategory*> KeywordCategoryList;
00151 typedef KeywordCategoryList::iterator KeywordCategoryIterator;
00152 typedef KeywordCategoryList::const_iterator KeywordCategoryConstIterator;
00153
00154
00155
00156
00157 class WhiteSpaceParser
00158 {
00159 public:
00160 class CommentBlock
00161 {
00162 public :
00163 CommentBlock( const TCHAR* szStartOfComment,
00164 const TCHAR* szEndOfComment );
00165 virtual ~CommentBlock();
00166
00167 const RmStringT& GetStartOfComment() const { return m_startOfComment; };
00168 const RmStringT& GetEndOfComment() const { return m_endOfComment; };
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 void Parse( const ParseInput& parseInput,
00180 ParseResult& parseResult );
00181
00182 private :
00183 RmStringT m_startOfComment;
00184 RmStringT m_endOfComment;
00185 };
00186
00187 typedef RmLinkedList<CommentBlock*> CommentBlockList;
00188 typedef CommentBlockList::iterator CommentBlockItr;
00189 typedef CommentBlockList::const_iterator CommentBlockConstItr;
00190
00191 public :
00192 WhiteSpaceParser();
00193 virtual ~WhiteSpaceParser();
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 void Parse( const ParseInput& parseInput,
00205 ParseResult& parseResult );
00206
00207
00208 void AddCommentBlock( const TCHAR* szStartOfComment,
00209 const TCHAR* szEndOfComment );
00210 void RemoveAllCommentBlocks();
00211
00212
00213 CommentBlockItr BeginCommentBlock() { return m_commentBlockList.begin(); };
00214 CommentBlockItr EndCommentBlock() { return m_commentBlockList.end(); };
00215
00216
00217 void SetParser( RmMFCShaderSyntaxParser *pParser ) { m_pParser = pParser; };
00218
00219 RmMFCShaderSyntaxParser* GetParser() { return m_pParser; };
00220 const RmMFCShaderSyntaxParser* GetParser() const { return m_pParser; };
00221
00222 private :
00223 RmMFCShaderSyntaxParser *m_pParser;
00224 CommentBlockList m_commentBlockList;
00225 };
00226
00227
00228
00229
00230 class TextParser
00231 {
00232 public :
00233 TextParser();
00234 virtual ~TextParser();
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 void Parse( const ParseInput& parseInput,
00248 ParseResult& parseResult,
00249 const KeywordCategoryList &keywords );
00250
00251
00252 void SetParser( RmMFCShaderSyntaxParser *pParser ) { m_pParser = pParser; };
00253
00254 RmMFCShaderSyntaxParser* GetParser() { return m_pParser; };
00255 const RmMFCShaderSyntaxParser* GetParser() const { return m_pParser; };
00256
00257 private :
00258 RmMFCShaderSyntaxParser *m_pParser;
00259 };
00260
00261 public:
00262
00263 RmMFCShaderSyntaxParser();
00264 virtual ~RmMFCShaderSyntaxParser();
00265
00266
00267 KeywordCategory* AddKeywordCategory( const TCHAR *szCategoryName, bool bOperator );
00268 void RemoveKeywordCategory( const TCHAR *szCategoryName );
00269 void RemoveAllKeywordCategory();
00270
00271
00272 KeywordCategory* FindKeywordCategory( const TCHAR* szCategoryName );
00273 const KeywordCategory* FindKeywordCategory( const TCHAR* szCategoryName ) const;
00274
00275
00276 KeywordCategoryIterator BeginKeywordCategory() { return m_keywordCategoryList.begin(); };
00277 KeywordCategoryConstIterator BeginKeywordCategory() const { return m_keywordCategoryList.begin(); };
00278
00279 KeywordCategoryIterator EndKeywordCategory() { return m_keywordCategoryList.end(); };
00280 KeywordCategoryConstIterator EndKeywordCategory() const { return m_keywordCategoryList.end(); };
00281
00282
00283 void AddKeyword( const TCHAR* szCategoryName, const TCHAR *szKeyword );
00284 void RemoveKeyword( const TCHAR* szCategoryName, const TCHAR *szKeyword );
00285
00286
00287 WhiteSpaceParser& GetWhiteSpaceParser() { return m_whiteSpaceParser; };
00288 const WhiteSpaceParser& GetWhiteSpaceParser() const { return m_whiteSpaceParser; };
00289
00290
00291 TextParser& GetTextParser() { return m_textParser; };
00292 const TextParser& GetTextParser() const { return m_textParser; };
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 void Parse( const TCHAR *pBuffer,
00305 int bufferSize,
00306 int parseBeginPos,
00307 int parseEndPos );
00308
00309
00310 virtual void OnKeywordFound( Keyword *pKeyword );
00311
00312
00313 COLORREF m_commentColor;
00314 COLORREF m_foregroundColor;
00315 COLORREF m_backgroundColor;
00316 COLORREF m_highlightColor;
00317
00318
00319 private:
00320 KeywordCategoryList m_keywordCategoryList;
00321 RmShaderCharType m_charTypeTable[65536];
00322
00323 WhiteSpaceParser m_whiteSpaceParser;
00324 TextParser m_textParser;
00325 };
00326
00327 #endif
00328