Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

RmMFCShaderSyntaxParser.h

00001 //=================================================================================================//
00002 // filename: RmMFCShaderSyntaxParser.h                                                             //
00003 //                                                                                                 //
00004 // author:      Toshiaki Tsuji                                                                     //
00005 //              ATI Research, Inc.                                                                 //
00006 //              3D Application Research Group                                                      //
00007 //                                                                                                 //
00008 // description: Shader Editor Tab 
00009 //                                                                                                 //
00010 //=================================================================================================//
00011 // $File: //depot/3darg/Tools/RenderMonkey/sdk/Include/MFCUtilities/RmMFCShaderSyntaxParser.h $                                   
00012 // $Author: tsuji $ $Revision: #2 $                                                                     
00013 //=================================================================================================//
00014 //   (C) 2004 ATI Research, Inc.  All rights reserved.                                             //
00015 //=================================================================================================//
00016 
00017 #ifndef RM_MFC_SHADER_SYNTAX_PARSER_H
00018 #define RM_MFC_SHADER_SYNTAX_PARSER_H
00019 
00020 //#include "RmShaderEditorTypes.h"
00021 //#include "RmShaderPage.h"
00022 
00023 #define MAX_NUM_CHAR 256 /*65536*/
00024 
00025 //..............................................................................................................//
00026 //..............................................................................................................//
00027 //..............................................................................................................//
00028 //..............................................................................................................//
00029 //  Shader Parser Class
00030 //..............................................................................................................//
00031 //..............................................................................................................//
00032 //..............................................................................................................//
00033 //..............................................................................................................//
00034 class RMMFCUTIL_API RmMFCShaderSyntaxParser
00035 {
00036 public:
00037    //--------------------------------------------------------------------
00038    // Simple Wrapper for Parsing Input/Result
00039    //--------------------------------------------------------------------
00040    struct ParseInput
00041    {
00042       const TCHAR *pBuffer;
00043       const RmShaderCharType *pRmShaderCharTypeTable; // Table to identify character type
00044 
00045       int bufferSize;
00046       int parseBeginPos;   // Starting poistion withtin buffer
00047       int parseEndPos;     // End limit poistion.  Parsing must stop before this
00048    }; // End of ParseInput
00049 
00050    //--------------------------------------------------------------------
00051    struct ParseResult
00052    {
00053       bool bProcessed;     // Returns true, if processing done. false if nothing was done
00054       bool bEndReached;
00055       int  parseNextPos;   // Position after parsing, next parsing should start from this pos
00056    }; // End of ParseResult
00057 
00058 public :
00059    //--------------------------------------------------------------------
00060    // Keyword
00061    //--------------------------------------------------------------------
00062    class Keyword
00063    {
00064    public :
00065       Keyword( const TCHAR* szKeyword );
00066       virtual ~Keyword();
00067 
00068       // Accessor
00069       const RmStringT& GetString() const { return m_keywordString; };
00070 
00071       // Returns true, if given string matches Keyword
00072       bool Match( const TCHAR* szStr, bool bCaseSensitive = true ) const;
00073 
00074    private:
00075       RmStringT m_keywordString; 
00076    }; // End of Keyword
00077 
00078    typedef RmLinkedList<Keyword*>         KeywordList;
00079    typedef KeywordList::iterator          KeywordIterator;
00080    typedef KeywordList::const_iterator    KeywordConstIterator;
00081 
00082    //--------------------------------------------------------------------
00083    // KeywordCategory
00084    //--------------------------------------------------------------------
00085    class KeywordCategory
00086    {
00087    public :
00088       // Keyword Table is a Table of list of Keyword
00089       // First character of keyword determines the index to array
00090       // Then each index of keywordtable is a list of keyword
00091       typedef KeywordList KeywordTable[MAX_NUM_CHAR];
00092 
00093    public :
00094       KeywordCategory( const TCHAR* szKeywordCategoryName, bool bOperatorType );
00095       virtual ~KeywordCategory();
00096 
00097       // Returns name of syntax canetgory
00098       const RmStringT& GetKeywordCategoryName() const { return m_keywordCategoryName; };
00099 
00100       // Is this operator category?
00101       bool IsOperatorType() const { return m_bOperatorType; };
00102 
00103       // Returns true, if given string matches Syntax CategoryName
00104       bool Match( const TCHAR* szStr, bool bCaseSensitive = false ) const;
00105 
00106       // Add/Remove Keyword
00107       void AddKeyword( const TCHAR *szKeyword );
00108       void RemoveKeyword( const TCHAR *szKeyword );
00109       void RemoveAllKeywords();
00110 
00111       // Search
00112       Keyword* FindKeyword( const TCHAR *szKeyword );
00113       const Keyword* FindKeyword( const TCHAR *szKeyword ) const;
00114 
00115       // Parsing
00116       // 
00117       // Parameter :
00118       //
00119       //  - parseInput     = Parameters necessary for parsing
00120       //  - parseInput     = [out] Result of Parsing
00121       //
00122       void Parse( const ParseInput& parseInput,
00123                   ParseResult& parseResult );
00124 
00125       // Set/Get Parent Parser
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       // Set/Get Color
00132       void     SetColor( COLORREF color ) { m_color = color; };
00133       COLORREF GetColor() const { return m_color; };
00134 
00135       // To directly access keyword table
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    }; // End of KeywordCategory
00149 
00150    typedef RmLinkedList<KeywordCategory*>      KeywordCategoryList;
00151    typedef KeywordCategoryList::iterator       KeywordCategoryIterator;
00152    typedef KeywordCategoryList::const_iterator KeywordCategoryConstIterator;
00153 
00154    //--------------------------------------------------------------------
00155    // WhiteSpaceParser
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          // Parsing
00172          // 
00173          // Parameter :
00174          //
00175          //  - parseInput     = Parameters necessary for parsing
00176          //  - parseInput     = [out] Result of Parsing
00177          //
00178          //--------------------------------------------------------------------
00179          void Parse( const ParseInput& parseInput,
00180                      ParseResult& parseResult );
00181 
00182       private :
00183          RmStringT       m_startOfComment;
00184          RmStringT       m_endOfComment;
00185       }; // End of CommentBlock
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       // Parsing
00197       // 
00198       // Parameter :
00199       //
00200       //  - parseInput     = Parameters necessary for parsing
00201       //  - parseInput     = [out] Result of Parsing
00202       //
00203       //--------------------------------------------------------------------
00204       void Parse( const ParseInput& parseInput,
00205                   ParseResult& parseResult );
00206 
00207       // Add/Remove Comments
00208       void AddCommentBlock( const TCHAR* szStartOfComment,
00209                             const TCHAR* szEndOfComment );
00210       void RemoveAllCommentBlocks();
00211 
00212       // Iterator
00213       CommentBlockItr BeginCommentBlock() { return m_commentBlockList.begin(); };
00214       CommentBlockItr EndCommentBlock() { return m_commentBlockList.end(); };
00215 
00216       // Set/Get Parent Parser
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    }; // End of WhiteSpaceParser
00226 
00227    //--------------------------------------------------------------------
00228    // TextParser
00229    //--------------------------------------------------------------------
00230    class TextParser
00231    {
00232    public : 
00233       TextParser();
00234       virtual ~TextParser();
00235 
00236       //--------------------------------------------------------------------
00237       // Parsing
00238       // 
00239       // Parameter :
00240       //
00241       //  - pBuffer        = Buffer to parse
00242       //  - parseInput     = Parameters necessary for parsing
00243       //  - parseInput     = [out] Result of Parsing
00244       //  - Keywords       = List of Keywords
00245       //
00246       //--------------------------------------------------------------------
00247       void Parse( const ParseInput& parseInput,
00248                   ParseResult& parseResult,
00249                   const KeywordCategoryList &keywords );
00250 
00251       // Set/Get Parent Parser
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    }; // End of TextParser
00260 
00261 public:
00262    // Default Constructor:
00263         RmMFCShaderSyntaxParser();      
00264    virtual ~RmMFCShaderSyntaxParser();
00265 
00266    // Add/Remove Category
00267    KeywordCategory* AddKeywordCategory( const TCHAR *szCategoryName, bool bOperator );
00268    void RemoveKeywordCategory( const TCHAR *szCategoryName );
00269    void RemoveAllKeywordCategory();
00270 
00271    // Search Category
00272    KeywordCategory* FindKeywordCategory( const TCHAR* szCategoryName );
00273    const KeywordCategory* FindKeywordCategory( const TCHAR* szCategoryName ) const;
00274 
00275    // Iterator for Syntax Category
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    // Keyword
00283    void AddKeyword( const TCHAR* szCategoryName, const TCHAR *szKeyword );
00284    void RemoveKeyword( const TCHAR* szCategoryName, const TCHAR *szKeyword );
00285 
00286    // WhiteSpace Processor 
00287    WhiteSpaceParser& GetWhiteSpaceParser() { return m_whiteSpaceParser; };
00288    const WhiteSpaceParser& GetWhiteSpaceParser() const { return m_whiteSpaceParser; };
00289 
00290    // Text Processor 
00291    TextParser& GetTextParser() { return m_textParser; };
00292    const TextParser& GetTextParser() const { return m_textParser; };
00293 
00294    //--------------------------------------------------------------------
00295    // Parsing
00296    // 
00297    // Parameter :
00298    //
00299    //  - pBuffer        = Buffer to parse
00300    //  - parseBeginPos  = Parse beginning position
00301    //  - parseEndPos    = Parse end limit position
00302    //
00303    //--------------------------------------------------------------------
00304    void Parse( const TCHAR *pBuffer,
00305                int bufferSize,
00306                int parseBeginPos,
00307                int parseEndPos );
00308 
00309    // Override this to catch when keyword is found
00310    virtual void OnKeywordFound( Keyword *pKeyword );
00311 
00312    // Colors
00313    COLORREF                    m_commentColor;
00314    COLORREF                    m_foregroundColor;
00315    COLORREF                    m_backgroundColor;
00316    COLORREF                    m_highlightColor;
00317 
00318 //----Class data members ----//
00319 private:
00320    KeywordCategoryList         m_keywordCategoryList;
00321    RmShaderCharType            m_charTypeTable[65536];
00322   
00323    WhiteSpaceParser            m_whiteSpaceParser;
00324    TextParser                  m_textParser;
00325 }; // End of RmMFCShaderSyntaxParser
00326 
00327 #endif
00328 

Generated on Fri Feb 25 16:08:39 2005 for RenderMonkey SDK by doxygen 1.3.6