/** * @file XTPSyntaxEditLexParser.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPSYNTAXEDITLEXPARSER_H__) # define __XTPSYNTAXEDITLEXPARSER_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPSyntaxEditColorTheme; class CXTPNotifySink; class CXTPNotifyConnection; class CXTPSyntaxEditBufferManager; class CXTPNotifyConnectionMT; //////////////////////////////////////////////////////////////////////////// /** @cond */ typedef CList CXTPSyntaxEditTextBlockList; typedef CArray CXTPSyntaxEditTextBlockArray; /** @endcond */ /** @cond */ namespace XTPSyntaxEditLexAnalyser /** @endcond */ { class CXTPSyntaxEditLexObj_ActiveTags; class CXTPSyntaxEditLexClass; class CXTPSyntaxEditLexClassInfoArray; class CXTPSyntaxEditLexOnScreenParseCnt; /** * @brief * Enumerates flags which indicate the results of parse function calls. * @see * CXTPSyntaxEditLexClass, CXTPSyntaxEditLexTextSchema */ enum XTPSyntaxEditLexParseResult { xtpEditLPR_Unknown = 0, /**< Undefined value. */ xtpEditLPR_StartFound = 0x001, /**< Start text block was found. */ xtpEditLPR_EndFound = 0x002, /**< End text block was found. */ xtpEditLPR_Iterated = 0x010, /**< Indicates that the current text position has already moved to the next char inside a function call. */ xtpEditLPR_TBpop1 = 0x020, /**< Indicates that the new found text block should be inserted before the previous one and as a parent of it. */ xtpEditLPR_Error = 0x100, /**< Iterated parse process breaked due to some error. See trace for details. */ xtpEditLPR_RunFinished = 0x200, /**< Run iterated parse process (or some big part of it) has finished. */ xtpEditLPR_RunBreaked = 0x400, /**< Run iterated parse process (or some big part of it) has breaked. */ xtpEditLPR_RunRestart = 0x800, /**< Restart run children from the beginning. */ // xtpEditLPR_NeedFullReparse = 0x1000, // Cannot reparse only specified piece of text. Full // reparse is necessary. }; /** * @brief * This class is designed to store the coordinates of a text region. * @see * XTP_EDIT_LINECOL */ class _XTP_EXT_CLASS CXTPSyntaxEditTextRegion { public: XTP_EDIT_LINECOL m_posStart; /**< Start position in document coordinates. */ XTP_EDIT_LINECOL m_posEnd; /**< End position in document coordinates. */ /** * @brief * Clears coordinates. */ void Clear(); /** * @brief * Sets coordinates. * @param pLCStart [in] Start position in document coordinates. * @param pLCEnd [in] End position in document coordinates. */ void Set(const XTP_EDIT_LINECOL* pLCStart, const XTP_EDIT_LINECOL* pLCEnd); }; /** @cond */ typedef CArray CXTPSyntaxEditInvalidZoneArray; /** @endcond */ /** * @brief * This class stores tokens definition: a list of tokens and * corresponding lists of start and end tokens separators. */ class _XTP_EXT_CLASS CXTPSyntaxEditLexTokensDef { public: /** * @brief * Default object constructor. */ CXTPSyntaxEditLexTokensDef(){}; /** * @brief * Copy object constructor. * @param rSrc [in] Reference to source CXTPSyntaxEditLexTokensDef object. */ CXTPSyntaxEditLexTokensDef(const CXTPSyntaxEditLexTokensDef& rSrc); /** * @brief * Object destructor. Handles clean up and deallocations. */ virtual ~CXTPSyntaxEditLexTokensDef(); /** * @brief * Assignment operator for class. * @param rSrc [in] Reference to source CXTPSyntaxEditLexTokensDef object. * @return * A reference to a CXTPSyntaxEditLexTokensDef object. */ const CXTPSyntaxEditLexTokensDef& operator=(const CXTPSyntaxEditLexTokensDef& rSrc); CStringArray m_arTokens; /**< List of tokens. */ CStringArray m_arStartSeps; /**< List of start separators. */ CStringArray m_arEndSeps; /**< List of end separators. */ }; /** @cond */ typedef CArray CXTPSyntaxEditLexTokensDefArray; /** @endcond */ /** * @brief * This class is designed to easily manipulate parser options. */ class _XTP_EXT_CLASS CXTPSyntaxEditLexParserSchemaOptions : public CXTPCmdTarget { public: /** * @brief * Default object constructor. */ CXTPSyntaxEditLexParserSchemaOptions(); /** * @brief * Object constructor. * @param rSrc [in] Reference to source CXTPSyntaxEditLexParserSchemaOptions object. */ CXTPSyntaxEditLexParserSchemaOptions(const CXTPSyntaxEditLexParserSchemaOptions& rSrc); /** * @brief * Overloaded equals operator. * @param rSrc [in] Reference to source CXTPSyntaxEditLexParserSchemaOptions object. */ const CXTPSyntaxEditLexParserSchemaOptions& operator=(const CXTPSyntaxEditLexParserSchemaOptions& rSrc); // global: BOOL m_bFirstParseInSeparateThread; /**< {0,1} default=1 */ BOOL m_bEditReparceInSeparateThread; /**< {0,1} default=1 */ BOOL m_bConfigChangedReparceInSeparateThread; /**< {0,1} default=1 */ DWORD m_dwMaxBackParseOffset; /**< default=100; maximum back buffer size. Some times parser look back for the text from current position. */ DWORD m_dwEditReparceTimeout_ms; /**< default=500 ms; time out for start reparse after last key was pressed. */ DWORD m_dwOnScreenSchCacheLifeTime_sec; /**< default=180 sec; time out for on screen parsed pices of text. for memory using optimization. */ DWORD m_dwParserThreadIdleLifeTime_ms; /**< default=60 sec; time out for existing of parser thread when parser idle (no parse requests). */ }; /** @cond */ class _XTP_EXT_CLASS CXTPSyntaxEditLexClassSchema : public CXTPCmdTarget { friend class CXTPSyntaxEditLexTextSchema; public: CXTPSyntaxEditLexClassSchema(); virtual ~CXTPSyntaxEditLexClassSchema(); virtual void AddPreBuildClass(CXTPSyntaxEditLexClass* pClass); virtual BOOL Build(); virtual BOOL Copy(CXTPSyntaxEditLexClassSchema* pDest); virtual void Close(); virtual void RemoveAll(); virtual CXTPSyntaxEditLexClassPtrArray* GetClasses(BOOL bShortSch); virtual CXTPSyntaxEditLexClassPtrArray* GetPreBuildClasses(); virtual CXTPSyntaxEditLexClass* GetPreBuildClass(const CString& strName); virtual CXTPSyntaxEditLexClass* GetNewClass(BOOL bForFile); virtual CXTPSyntaxEditLexObj_ActiveTags* GetActiveTagsFor(CXTPSyntaxEditLexClass* pTopClass); protected: virtual BOOL Build_ChildrenFor(BOOL bDynamic, CXTPSyntaxEditLexClass* pCBase, CStringArray& rarAdded, int& rnNextClassID, int nLevel = 0); virtual CXTPSyntaxEditLexClassPtrArray* GetChildrenFor(CXTPSyntaxEditLexClass* pClass, BOOL& rbSelfChild); virtual CXTPSyntaxEditLexClassPtrArray* GetDynChildrenFor(CXTPSyntaxEditLexClass* pClass, BOOL& rbSelfChild); virtual void GetDynParentsList(CXTPSyntaxEditLexClass* pClass, CStringArray& rarDynParents, CStringArray& rarProcessedClasses); virtual int CanBeParentDynForChild(CString strParentName, CXTPSyntaxEditLexClass* pCChild); virtual BOOL Build_ShortTree(); virtual BOOL PostBuild_Step(CXTPSyntaxEditLexClassPtrArray* pArClasses); virtual BOOL CopyChildrenFor(BOOL bShort, CXTPSyntaxEditLexClass* pCDest, CXTPSyntaxEditLexClass* pCSrc, int nLevel); CXTPSyntaxEditLexClassPtrArray m_arPreBuildClassesList; CXTPSyntaxEditLexClassPtrArray m_arClassesTreeShort; CXTPSyntaxEditLexClassPtrArray m_arClassesTreeFull; }; /** @endcond */ /** * @brief * The CXTPSyntaxEditLexTextBlock class represents a block of text which * corresponds to a lex class in a text schema. * It stores the start position, end position, and pointer to the lex class * object in a class schema along with some other information. * Text blocks are organized as a bidirectional list and as a tree structure. */ class _XTP_EXT_CLASS CXTPSyntaxEditLexTextBlock : public CXTPCmdTarget { /** @cond */ friend class CXTPSyntaxEditLexTextSchema; friend class CXTPSyntaxEditLexClass; friend class CXTPSyntaxEditLexClass_file; /** @endcond */ public: /** * @brief * Default object constructor. */ CXTPSyntaxEditLexTextBlock(); /** * @brief * Object destructor. Handles clean up and deallocations. */ virtual ~CXTPSyntaxEditLexTextBlock(); CXTPSyntaxEditLexClassPtr m_ptrLexClass; /**< Pointer to the LexClass object. */ CXTPSyntaxEditLexTextBlockPtr m_ptrParent; /**< Pointer to the parent block object. */ CXTPSyntaxEditLexTextBlockPtr m_ptrPrev; /**< Pointer to the previous block. */ CXTPSyntaxEditLexTextBlockPtr m_ptrNext; /**< Pointer to the next block. */ XTP_EDIT_LINECOL m_PosStartLC; /**< Text block start position. */ XTP_EDIT_LINECOL m_PosEndLC; /**< Text block start position. */ BOOL m_bEndByParent; /**< Text block ended when the parent block ended. */ /** * @brief * Gets the text block end position. * @param bMaxIfInvalid [in] TRUE to get the maximum value if * the text block end position is invalid, * FALSE to get the minimum value if * the text block end position is invalid. * @return * The text block end position if it is valid. Otherwise the * maximum or minimum value depending on bMaxIfInvalid. * @see * XTP_EDIT_LINECOL, m_PosEndLC, m_PosStartLC. */ XTP_EDIT_LINECOL GetPosEndLC(BOOL bMaxIfInvalid = TRUE); /** * @brief * Gets the text block start tag end position in the text. * @return * The text block start tag end position in XLC form. * @see * XTP_EDIT_LINECOL::GetXLC(), XTP_EDIT_XLC() macros. */ DWORD GetStartTagEndXLC(); /** * @brief * Gets the text block end tag begin position in the text. * @return * The text block end tag begin position in XLC form. * @see * XTP_EDIT_LINECOL::GetXLC(), XTP_EDIT_XLC() macros. */ DWORD GetEndTagBeginXLC(); /** * @brief * Gets the text block end tag end position in the text. * @return * The text block end tag end position in XLC form. * @see * XTP_EDIT_LINECOL::GetXLC(), XTP_EDIT_XLC() macros. */ DWORD GetEndTagEndXLC(); /** * @brief * Releases references to other objects. * @details * This method is used in text schema destruction process. * @see * CXTPSyntaxEditLexTextSchema::Close(). */ virtual void Close(); // virtual void Close(BOOL bWithPrev = FALSE, BOOL bWithNext = FALSE); /** * @brief * Determines if the lex class name of a specified text block * is equal to the lex class name of the current text block. * @param pTB2 [in] Pointer to a CXTPSyntaxEditLexTextBlock object. * @return * TRUE if the lex class name of the specified text block * is equal to the lex class name of the current text block, * otherwise FALSE. */ virtual BOOL IsEqualLexClasses(CXTPSyntaxEditLexTextBlock* pTB2) const; /** * @brief * Determines if a specified text block is included within * the current text block. * @param pTB2 [in] Pointer to a CXTPSyntaxEditLexTextBlock object. * @return * TRUE if the specified text block is included within * the current textblock, otherwise FALSE. */ virtual BOOL IsInclude(CXTPSyntaxEditLexTextBlock* pTB2) const; /** * @brief * Determines if the current text block appears to * be partly closed or closed. * @return * TRUE if some or all references to other objects are NULL, * FALSE otherwise. */ virtual BOOL IsLookLikeClosed() const; /** * @brief * Sets the end position to not ended children blocks. * @param pTxtSch [in] Text schema pointer to send notifications. * @param bEndByParent [in] BOOL flag * @return * Ended children blocks count. */ virtual int EndChildren(CXTPSyntaxEditLexTextSchema* pTxtSch = NULL, BOOL bEndByParent = TRUE); /** * @brief * Gets the previous child block from a specified child block. * @param pChild [in] Pointer to the child block to get * the previous child block from. * @param bWithAddRef [in] TRUE to call InternalAddRef, FALSE otherwise. * @details * The current text block is the parent block to the two child blocks. * @return * A pointer to the previous child block if successful, otherwise NULL. */ virtual CXTPSyntaxEditLexTextBlock* GetPrevChild(CXTPSyntaxEditLexTextBlock* pChild, BOOL bWithAddRef); # ifdef _DEBUG virtual void Dump(CDumpContext& dc) const; # endif protected: int m_nStartTagLen; /**< Start tag length. */ int m_nEndTagXLCLen; /**< End tag length in XLC form. */ CXTPSyntaxEditLexTextBlockPtr m_ptrLastChild; /**< For internal use only. This variable does not always contain the correct value. */ }; /** * @brief * The CXTPSyntaxEditLexTextSchema class is used to store data which is * necessary to parse a text and parsing results. It also contains * methods to run lex classes from a class schema, to update text schema * when text is edited, to reparse text, to get information which is * necessary to draw colorized text, and other helper methods. */ class _XTP_EXT_CLASS CXTPSyntaxEditLexTextSchema : public CXTPCmdTarget { /** @cond */ friend class CXTPSyntaxEditLexClass; friend class CXTPSyntaxEditLexClass_file; friend class CXTPSyntaxEditLexTextBlock; friend class CXTPSyntaxEditLexParser; /** @endcond */ public: /** * @brief * Default object constructor. * @param pcszSchName [in] Text schema name. */ CXTPSyntaxEditLexTextSchema(LPCTSTR pcszSchName); /** * @brief * Object destructor. Handles clean up and deallocations. */ virtual ~CXTPSyntaxEditLexTextSchema(); /** * @brief * Gets the text schema name. * @return * The text schema name. */ virtual CString GetSchName() const; /** * @brief * Destroys all interlocked object references and * frees all stored objects. * @details * This method deletes the schema object. * @see * RemoveAll, CXTPSyntaxEditLexClassSchema::Close */ virtual void Close(); /** * @brief * Destroys the text blocks list. * @param pFirst Pointer to the first element in the list to destroy. * @see * CXTPSyntaxEditLexTextBlock::Close */ static void AFX_CDECL Close(CXTPSyntaxEditLexTextBlock* pFirst); /** * @brief * Removes all text blocks from the schema. * @details * This method does not destroy the schema object. * It only removes the text blocks. * @see * RemoveAll, CXTPSyntaxEditLexClassSchema::Close */ virtual void RemoveAll(); /** * @brief * Creates a new text schema object and initializes its internal * infrastructure from the current schema. * @details * This method copies the class schema, but does not copy the text blocks. * @return * A pointer to the newly created and initialized text schema object. */ virtual CXTPSyntaxEditLexTextSchema* Clone(); /** * @brief * Gets the notification connection. * @return * A pointer to the notification connection. */ virtual CXTPNotifyConnection* GetConnection(); /** * @brief * Runs parse for the text. * @param bShort [in] TRUE to use the short * (global blocks only) class schema, * FALSE to use the full * (global and onscreen blocks) class schema. * @param pTxtIter [in] Pointer to a CTextIter object. * @param nRowStart [in] Start text position for parse/reparse. * @param nRowEnd [in] End text position for parse/reparse. * @param bSendProgressEvents [in] TRUE to send progress parsing events using * the connection object, FALSE otherwise. * @details * Special parameters values: * pLCStart = NULL and pLCEnd = NULL to * parse from the last parsed block to the end of the text. * * pLCStart = XTP_EDIT_LINECOL::Pos1 and pLCEnd = NULL to * parse/reparse all text from the beginning. * @return * The parse result; one of the values defined by * the XTPSyntaxEditLexParseResult enumeration. */ virtual int RunParseUpdate(BOOL bShort, CTextIter* pTxtIter, const XTP_EDIT_LINECOL* pLCStart = NULL, const XTP_EDIT_LINECOL* pLCEnd = NULL, BOOL bSendProgressEvents = FALSE); /** * @brief * Gets the text region for which the schema was updated during * the last parse/reparse operation. * @return * A reference to a CXTPSyntaxEditTextRegion object. */ virtual const CXTPSyntaxEditTextRegion& GetUpdatedTextRegion() const; /** * @brief * Runs parse for the text on screen. * @param pTxtIter [in] Pointer to a CTextIter object. * @param nRowStart [in] Start row for parse. * @param nRowEnd [in] End row for parse. * @param rPtrScreenSchFirstTB [out] Reference to a CXTPSyntaxEditLexTextBlockPtr * object to receive the first text block of * the built text schema. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL RunParseOnScreen(CTextIter* pTxtIter, int nRowStart, int nRowEnd, CXTPSyntaxEditLexTextBlockPtr& rPtrScreenSchFirstTB); /** * @brief * Gets a specified row as a list of blocks with different colors to draw. * @param pTxtIter [in] Pointer to a CTextIter object. * @param nRow [in] Row identifier. * @param nColFrom [in] Start column. * @param nColTo [in] End column. * @param clrDefault [in] Reference to an XTP_EDIT_COLORVALUES structure * containing the default colors. * @param rBlocks [out] Pointer to a CXTPSyntaxEditTextBlockList * object to receive the list of color blocks. * @param pptrTBStartCache [in, out] Reference to a cached text block to * start the search. * The value of this parameter may be NULL. * @param pFirstSchTB [in] Reference to the first block of the * external text schema or NULL. * This parameter is used for OnScreen schemas. */ virtual void GetRowColors(CTextIter* pTxtIter, int nRow, int nColFrom, int nColTo, const XTP_EDIT_COLORVALUES& clrDefault, CXTPSyntaxEditTextBlockList* rBlocks, CXTPSyntaxEditLexTextBlockPtr* pptrTBStartCache = NULL, CXTPSyntaxEditLexTextBlock* pFirstSchTB = NULL); /** * @brief * Gets a specified row as a list of collapsible blocks. * @param nRow [in] Row identifier. Passing a negative value * will return the blocks for all rows. * @param rArBlocks [out] Reference to a CXTPSyntaxEditRowsBlockArray * object to receive the list of collapsable blocks. * @param pptrTBStartCache [in, out] Reference to a cached text block to * start the search. * The value of this parameter may be NULL. */ virtual void GetCollapsableBlocksInfo(int nRow, CXTPSyntaxEditRowsBlockArray& rArBlocks, CXTPSyntaxEditLexTextBlockPtr* pptrTBStartCache = NULL); /** * @brief * Gets the text attributes from the lex class of a specified text block. * @param rTB [out] Reference to an XTP_EDIT_TEXTBLOCK structure * to receive the text attributes. * @param pTextBlock [in] Pointer to a CXTPSyntaxEditLexTextBlock object. */ virtual void GetTextAttributes(XTP_EDIT_TEXTBLOCK& rTB, CXTPSyntaxEditLexTextBlock* pTextBlock); /** * @brief * Applies a specified color theme to this text schema. * @param pTheme [in] Pointer to the color theme to apply. */ virtual void ApplyTheme(CXTPSyntaxEditColorTheme* pTheme); /** * @brief * Loads a specified class schema. * @param arClassInfo [in] Reference to a CXTPSyntaxEditLexClassInfoArray object. * @return * TRUE if successful, otherwise FALSE. */ BOOL LoadClassSchema(CXTPSyntaxEditLexClassInfoArray* arClassInfo); /** * @brief * Determines if this schema supports a specified file extension. * @param strExt [in] Reference to the file extension. * @details * Extension string format: ".ext" * For example: ".cpp" * @return * TRUE if the specified file extension is supported, otherwise FALSE. */ BOOL IsFileExtSupported(const CString& strExt); /** * @brief * Builds the schema if necessary, otherwise does nothing. * @details * Call this member function before using a schema object. * * In order to make edit control startup faster, schemas * are not built during loading. This member function will * build the schema if necessary or do nothing otherwise. */ void BuildIfNeed(); /** * @brief * Gets the top lex class for a specified file extension. * @param strExt [in] Reference to the file extension. * @details * Extension string format: ".ext" * For example: ".cpp" * InternalAddRef is called for the returned object. * @return * A pointer to the lex class if successful, otherwise NULL. */ CXTPSyntaxEditLexClass* GetTopClassForFileExt(const CString& strExt); /** * @brief * Retrieves a specified text block by its identifier. * @param dwID [in] Identifier of the text block to retrieve * (obtained from an xtpEditOnTextBlockParsed notification). * @details * This method should be used together with * an xtpEditOnTextBlockParsed notification. * * InternalAddRef is called for the returned object. * @return * A pointer to the text block if successful, otherwise NULL. */ virtual CXTPSyntaxEditLexTextBlock* GetLastParsedBlock(WPARAM dwID = 0); /** * @brief * Gets the first text schema block. * @details * InternalAddRef is called for the returned object. * @return * A pointer to the first text schema block if successful, otherwise NULL. */ CXTPSyntaxEditLexTextBlock* GetBlocks(); /** * @brief * Gets the critical section object to lock schema data * (i.e. text blocks and others). * @return * A pointer to the critical section object. */ CMutex* GetDataLoker(); /** * @brief * Gets the critical section object to lock class schema. * @return * A pointer to the critical section object. */ CMutex* GetClassSchLoker(); /** * @brief * Gets the event object to break the parsing process. * @return * A pointer to the event object. */ CEvent* GetBreakParsingEvent(); /** @cond */ static void AFX_CDECL TraceClrBlocks(CXTPSyntaxEditTextBlockArray& arBlocks); void TraceTxtBlocks(BOOL bFull); /**< for DEBUG only */ /** @endcond */ protected: /** * @brief * This enum describes the set of UpdateTextBlocks return results. */ enum XTPSyntaxEditUpdateTBRes { xtpEditUTBNothing = 0, /**< Void result.*/ xtpEditUTBError = 0x0001, /**< Error result.*/ xtpEditUTBReparse = 0x0002, /**< One or few global blocks changed and a reparse is needed.*/ xtpEditUTBNearestUpdated = 0x0100, /**< This flag is returned from UpdateTBNearest only.*/ }; /** * @brief * Gets the class schema of this text schema. * @details * InternalAddRef is called for the returned object. * @return * A pointer to the class schema of this text schema. */ CXTPSyntaxEditLexClassSchema* GetClassSchema(); /** * @brief * Applies a specified color theme to a specified lex class array. * @param pTheme [in] Pointer to the color theme to apply. * @param ptrClasses [in] Pointer to a lex class array. * @see * ApplyTheme */ virtual void ApplyThemeRecursive(CXTPSyntaxEditColorTheme* pTheme, CXTPSyntaxEditLexClassPtrArray* ptrClasses); /** * @brief * Updates text schema positions after an editing action. * @param posFrom [in] Start editing position. * @param posTo [in] End editing position. * @param eEditAction [in] Edit action. Must be one of the values defined by * the XTPSyntaxEditEditAction enumeration. * @return * The update result. One of the values defined by * the XTPSyntaxEditUpdateTBRes enumeration. */ int UpdateTextBlocks(XTP_EDIT_LINECOL posFrom, XTP_EDIT_LINECOL posTo, int eEditAction); /** @cond */ virtual int RunChildren(CTextIter* pTxtIter, CXTPSyntaxEditLexTextBlockPtr ptrTxtBlock, CXTPSyntaxEditLexClass* pBase, CXTPSyntaxEditLexOnScreenParseCnt* pOnScreenRunCnt = NULL); virtual CXTPSyntaxEditLexTextBlock* GetPrevBlock(BOOL bWithAddRef = TRUE); virtual CXTPSyntaxEditLexTextBlock* GetNewBlock(); /** @endcond */ private: int UpdateTBNearest(CXTPSyntaxEditLexTextBlock* pNarestTB1, int nLineDiff, int nColDiff, XTP_EDIT_LINECOL posFrom, XTP_EDIT_LINECOL posTo, int eEditAction); CXTPSyntaxEditLexTextBlock* FindNearestTextBlock(XTP_EDIT_LINECOL posText); virtual BOOL InitScreenSch(CTextIter* pTxtIter, int nRowStart, int nRowEnd, CXTPSyntaxEditLexTextBlockPtr& rPtrScreenSchFirstTB, CXTPSyntaxEditLexTextBlockPtr& rPtrTBParentToRun); virtual CXTPSyntaxEditLexTextBlockPtr InitScreenSch_RunTopClass(CTextIter* pTxtIter); virtual CXTPSyntaxEditLexTextBlock* CopyShortTBtoFull(CXTPSyntaxEditLexTextBlock* pTB); virtual CXTPSyntaxEditLexClass* FindLexClassByID(CXTPSyntaxEditLexClassPtrArray* pClassesAr, int nClassID); virtual int Run_OnScreenTBStack(CTextIter* pTxtIter, CXTPSyntaxEditLexTextBlock* pTBParentToRun, CXTPSyntaxEditLexOnScreenParseCnt* pRunCnt); virtual void UpdateLastSchBlock(CXTPSyntaxEditLexTextBlock* pLastTB, BOOL bPermanently = FALSE); virtual CXTPSyntaxEditLexTextBlock* GetLastSchBlock(BOOL bWithAddRef = TRUE); virtual UINT SendEvent_OnTextBlockParsed(CXTPSyntaxEditLexTextBlock* pTB); virtual int Run_ParseUpdate0(BOOL bShort, CTextIter* pTxtIter, const XTP_EDIT_LINECOL* pLCStart, const XTP_EDIT_LINECOL* pLCEnd, BOOL bSendProgressEvents); virtual int Run_ClassesUpdate1(CTextIter* pTxtIter, CXTPSyntaxEditLexTextBlockPtr ptrStartTB, BOOL bStarted); virtual int Run_ClassesUpdate2(CTextIter* pTxtIter, CXTPSyntaxEditLexClassPtrArray* pArClasses, CXTPSyntaxEditLexTextBlockPtr ptrParentTB, CXTPSyntaxEditLexOnScreenParseCnt* pOnScreenRunCnt = NULL); virtual BOOL IsBlockStartStillHere(CTextIter* pTxtIter, CXTPSyntaxEditLexTextBlock* pTB); virtual void FinishNewChain(BOOL bByBreak, BOOL bEOF); virtual void UpdateNewChainParentsChildren(); virtual void EndBlocksByParent(CXTPSyntaxEditLexTextBlock* pTBStart, CXTPSyntaxEditLexTextBlock* pTBEnd); virtual void SeekNextEx(CTextIter* pTxtIter, CXTPSyntaxEditLexClass* pRunClass = NULL, CXTPSyntaxEditLexOnScreenParseCnt* pOnScreenRunCnt = NULL, int nChars = 1); static void AFX_CDECL AddClrBlock(XTP_EDIT_TEXTBLOCK& rClrB, CXTPSyntaxEditTextBlockArray& arBlocks); //==== Run parse update context members ==== CXTPSyntaxEditTextRegion m_curInvalidZone; CXTPSyntaxEditLexTextBlockPtr m_ptrNewChainTB1; CXTPSyntaxEditLexTextBlockPtr m_ptrNewChainTB2; CXTPSyntaxEditLexTextBlockPtr m_ptrOldChainTBFirst; typedef CMap CXTPSyntaxEditLexID2TBmap; CXTPSyntaxEditLexID2TBmap m_mapLastParsedBlocks; CXTPSyntaxEditLexTextBlockPtr m_ptrLastParsedBlock; BOOL m_bSendProgressEvents; int m_nNoEndedClassesCount; //==== END Run parse update context members ==== private: // CCriticalSection m_csData; // CCriticalSection m_csClassSch; CMutex m_lockData; CMutex m_lockClassSch; CEvent m_evBreakParsing; CXTPSyntaxEditLexClassSchema* m_pClassSchema; CXTPSyntaxEditLexTextBlockPtr m_ptrFirstBlock; CXTPSyntaxEditLexTextBlockPtr m_ptrLastSchBlock; int m_nSeekNext_TagWaitChars; CString m_strSchName; CXTPNotifyConnectionMT* m_pConnectMT; }; /** * @brief * This class used to 'run' lex schema parsing in a separate thread. * It also controls this working thread and provides inter-thread interaction. */ class _XTP_EXT_CLASS CXTPSyntaxEditLexParser : public CXTPCmdTarget { public: /** * @brief * Default object constructor. */ CXTPSyntaxEditLexParser(); /** * @brief * Object destructor. Handles clean up and deallocations. */ virtual ~CXTPSyntaxEditLexParser(); /** * @brief * Stops parsing, destroys the working thread, and * unadvises from all events. * @see * CloseParseThread, StopParseInThread */ virtual void Close(); /** * @brief * Stops parsing and destroys the working thread. * @see * Close, StopParseInThread */ virtual void CloseParseThread(); /** * @brief * Starts parsing a specified text range in a separate (working) thread. * @param pBuffer Pointer to a CXTPSyntaxEditBufferManager object. * @param pLCStart Pointer to the start text position. * Set to NULL to parse from the beginning. * @param pLCEnd Pointer to the end text position. * Set to NULL to parse until the end. * @param eEditAction Edit action; must be either 0 or one of the values * defined by the XTPSyntaxEditEditAction enumeration. * @param bRunWithoutWait TRUE to start parsing immediately, * FALSE to wait until the timeout * specified in global schema options. * @details * If the parser is already running and parsing another text range, * then the specified text range will be added to a queue. * @see * StopParseInThread, CloseParseThread */ virtual void StartParseInThread(CXTPSyntaxEditBufferManager* pBuffer, const XTP_EDIT_LINECOL* pLCStart = NULL, const XTP_EDIT_LINECOL* pLCEnd = NULL, int eEditAction = 0, BOOL bRunWithoutWait = FALSE); /** * @brief * Stops parsing in thread. * @see * Close, StartParseInThread */ virtual void StopParseInThread(); /** * @brief * Stops parsing in thread before a call to OnEditChanged. * @see * OnEditChanged */ virtual void OnBeforeEditChanged(); /** * @brief * Reparses text after editing. * @param posFrom Reference to the start position for the edit action. * @param posTo Reference to the end position for the edit action. * @param eEditAction Edit action; must be one of the values defined by * the XTPSyntaxEditEditAction enumeration. * @param pBuffer Pointer to a CXTPSyntaxEditBufferManager object. * @see * OnBeforeEditChanged */ virtual void OnEditChanged(const XTP_EDIT_LINECOL& posFrom, const XTP_EDIT_LINECOL& posTo, int eEditAction, CXTPSyntaxEditBufferManager* pBuffer); /** * @brief * Gets the active text schema. * @return * A pointer to the active text schema. * @see * SetTextSchema */ virtual CXTPSyntaxEditLexTextSchema* GetTextSchema(); /** * @brief * Sets the active text schema. * @param pTextSchema Pointer to a text schema to be set. * @see * GetTextSchema */ virtual void SetTextSchema(CXTPSyntaxEditLexTextSchema* pTextSchema); /** * @brief * Gets the schema options. * @param strExt Reference to a file extension to lookup schema. * @return * A pointer to the schema options. */ virtual const CXTPSyntaxEditLexParserSchemaOptions* GetSchemaOptions(const CString& strExt); /** * @brief * Gets the priority of the working thread. * @return * The priority of the working thread. * @see * SetParseThreadPriority, CWinThread::GetThreadPriority */ virtual int GetParseThreadPriority(); /** * @brief * Sets the priority for the working thread. * @param nPriority Priority to be set. * @return * TRUE if successful, otherwise FALSE. * @see * GetParseThreadPriority, CWinThread::GetThreadPriority */ virtual BOOL SetParseThreadPriority(int nPriority); /** * @brief * Gets the auto-complete words of the active text schema. * @param rArTokens Reference to an array to receive the auto-complete * words of the active text schema. * @param bAppend TRUE to append to the contents of the specified array, * FALSE to replace the contents of the specified array. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL GetTokensForAutoCompleate(CXTPSyntaxEditLexTokensDefArray& rArTokens, BOOL bAppend); /** * @brief * Gets the notification connection. * @return * A pointer to the notification connection. */ virtual CXTPNotifyConnection* GetConnection(); protected: /** @cond */ class CXTPSyntaxEditParseThreadParams { public: CXTPSyntaxEditParseThreadParams(); void AddParseZone(const CXTPSyntaxEditTextRegion& rZone); CMutex lockThreadParams; CXTPSyntaxEditBufferManager* ptrBuffer; CXTPSyntaxEditInvalidZoneArray arInvalidZones; CEvent evParseRun; CEvent evRunWithoutWait; CEvent evExitThread; }; virtual CXTPSyntaxEditParseThreadParams* GetParseInThreadParams(); /** @endcond */ /** @cond */ virtual void SelfCloseParseThread(); static UINT AFX_CDECL ThreadParseProc(LPVOID); CCriticalSection m_csParserData; CWinThread* m_pParseThread; int m_nParseThreadPriority; /**< Saved priority to the parse thread */ CXTPSyntaxEditParseThreadParams m_PThreadParams; CXTPSyntaxEditLexTextSchema* m_ptrTextSchema; typedef CMap CXTPSyntaxEditLexParserSchemaOptionsMap; CXTPSyntaxEditLexParserSchemaOptionsMap m_mapSchOptions; CXTPSyntaxEditLexParserSchemaOptions* m_pSchOptions_default; CXTPNotifyConnection* m_pConnection; CXTPNotifySink* m_pSinkMT; /** @endcond */ /** @cond */ virtual void OnParseEvent_NotificationHandler(XTP_NOTIFY_CODE Event, WPARAM wParam, LPARAM lParam); virtual void GetStrsFromLVArray(CXTPSyntaxEditLexVariant* pLVArray, CStringArray& rArStrs) const; virtual BOOL ReadSchemaOptions(const CString& strExt, CXTPSyntaxEditLexTextSchema* pTextSchema, CXTPSyntaxEditLexParserSchemaOptions* pOpt); private: void RemoveAllOptions(); }; /** @endcond */ //////////////////////////////////////////////////////////////////////////// AFX_INLINE const CXTPSyntaxEditTextRegion& CXTPSyntaxEditLexTextSchema::GetUpdatedTextRegion() const { return m_curInvalidZone; } AFX_INLINE CMutex* CXTPSyntaxEditLexTextSchema::GetDataLoker() { return &m_lockData; } AFX_INLINE CMutex* CXTPSyntaxEditLexTextSchema::GetClassSchLoker() { return &m_lockClassSch; } AFX_INLINE CEvent* CXTPSyntaxEditLexTextSchema::GetBreakParsingEvent() { return &m_evBreakParsing; } AFX_INLINE XTP_EDIT_LINECOL CXTPSyntaxEditLexTextBlock::GetPosEndLC(BOOL bMaxIfInvalid) { if (!m_PosEndLC.IsValidData()) { return bMaxIfInvalid ? XTP_EDIT_LINECOL::MAXPOS : XTP_EDIT_LINECOL::MINPOS; } return m_PosEndLC; } AFX_INLINE DWORD CXTPSyntaxEditLexTextBlock::GetStartTagEndXLC() { return m_PosStartLC.GetXLC() + m_nStartTagLen; } AFX_INLINE DWORD CXTPSyntaxEditLexTextBlock::GetEndTagBeginXLC() { return m_PosEndLC.GetXLC() - (m_nEndTagXLCLen > 0 ? m_nEndTagXLCLen : 0); } AFX_INLINE DWORD CXTPSyntaxEditLexTextBlock::GetEndTagEndXLC() { return m_PosEndLC.GetXLC() - (m_nEndTagXLCLen < 0 ? m_nEndTagXLCLen : 0); } } // namespace XTPSyntaxEditLexAnalyser //////////////////////////////////////////////////////////////////////////// //#pragma warning(pop) //////////////////////////////////////////////////////////////////////////// /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // !defined(__XTPSYNTAXEDITLEXPARSER_H__) /** @endcond */