20#include "UtCallback.hpp"
21#include "UtCircularBuffer.hpp"
23#include "UtTextDocument.hpp"
26#include "wsf_parser_export.h"
39 const UtPath& aWorkingDirectory,
49 UtTextDocument*
PushSource(
const std::string& aFilePath,
51 UtTextDocumentRange* aIncludeLocation =
nullptr,
52 bool aSearchIncludePaths =
true);
54 UtTextDocument*
FindSource(
const std::string& aFilePath,
bool aSearchIncludePaths =
true,
bool aReadFile =
true);
62 UtTextDocumentRange ReadWord();
68 UtTextDocumentRange ReadTerminator(
const std::string& aTerminator);
70 void UndoRead(
size_t aWordCount = 1);
71 UtTextDocumentRange UndoReadAndGetRange(
size_t aWordCount);
72 void PushToUndoStack(
const UtTextDocumentRange& aRange);
74 void PartialMatch(UtTextDocumentRange aRange) { mPartialMatches.push_back(aRange); }
76 void AddError(
WsfParseRule* aReader, UtTextDocumentRange& aRange);
93 ++mTerminatorPrefixCheck[(
unsigned char)*aTerminatorString];
94 mTerminatorList.push_back(aTerminatorString);
98 char c = mTerminatorList.back()[0];
99 --mTerminatorPrefixCheck[(
unsigned char)c];
100 mTerminatorList.pop_back();
102 void SetWorkingDirectory(
const UtPath& aWorkingDirectory) { mSharedPtr->mWorkingDirectory = aWorkingDirectory; }
104 const std::vector<WsfParseError*>&
GetErrors()
const {
return mSharedPtr->mErrors; }
112 void DelayLoad(
const std::string& aKind,
113 const std::string& aName,
115 ptrdiff_t aTextOffset,
118 bool Requires(
const std::string& aKind,
const std::string& aName);
120 void ResolveDelayLoad();
133 return mSharedPtr->NewNode(aRule, aType, aValue);
146 void FinalizeParseTree(
WsfParseNode* aRootNodePtr, std::vector<WsfParseNode*>& aFileTransitionNodes);
153 void PushSourceP(UtTextDocument* aSource, UtTextDocumentRange* aIncludeLocation =
nullptr,
size_t aIncludeCount = 1);
155 using DelayLoadId = std::pair<std::string, std::string>;
163 , mIncludePtr(nullptr)
167 WsfParseNode* mNodePtr;
169 WsfParseRule* mRulePtr;
170 ptrdiff_t mTextOffset;
171 WsfParseSourceInclude* mIncludePtr;
174 using DelayLoaderMap = std::multimap<DelayLoadId, DelayLoader>;
178 class Shared :
public WsfParseNodePool
182 : mDelayLoadingCount(0)
188 std::vector<WsfParseError*> mErrors;
189 UtPath mWorkingDirectory;
190 DelayLoaderMap mDelayLoaders;
191 std::set<DelayLoadId> mCompletedDelayLoaders;
192 std::set<DelayLoadId> mLoadingDelayLoaders;
194 std::vector<DelayLoadId> mDelayLoadOrdering;
195 size_t mDelayLoadingCount;
201 UtTextDocument* mSource;
202 WsfParseSourceInclude* mIncludePtr;
203 UtTextDocument::iterator mPos;
206 static const int cRECALL_SIZE = 100;
208 static const int cMAXIMUM_REINCLUDE_COUNT = 10;
221 UtTextDocumentRange ReadWordP();
224 UtReferenceCount* mSharedReferenceCountPtr;
229 std::list<UtPath> mDeferredSources;
231 WsfParseIndex* mParseData;
237 std::vector<SourceData> mSourceStack;
239 WsfParseDefinitions* mDefinitions;
241 std::vector<UtTextDocumentRange> mPartialMatches;
243 std::vector<std::pair<UtTextDocument*, WsfParseSourceInclude*>> mSourceIncludes;
245 WsfParseSourceInclude* mCurrentSourcePtr;
246 WsfParseSourceInclude* mRootSourcePtr;
247 WsfParseSourceProvider* mSourceProvider;
249 UtFixedCircularBuffer<UtTextDocumentRange> mRecall;
250 ptrdiff_t mRecallPosition;
252 std::vector<const char*> mTerminatorList;
253 unsigned char mTerminatorPrefixCheck[256];
254 bool mCheckForTerminator;
257 std::vector<WsfParseNode*> mCurrentSequenceStack;
259 bool mIsDelayLoading;
260 bool mIgnoreIncludes;
261 bool mInsidePreprocessorVariable;
265 bool mFullyExpandNodes;
@ cMDB_PARSE_PARSER_SHARED
Definition WsfParseDebugMarkers.hpp:29
@ cMDB_PARSE_PARSER
Definition WsfParseDebugMarkers.hpp:28
Abstract class for encapsulating auxiliary data to be attached to a parse node.
Definition WsfParseAuxData.hpp:19
Definition WsfParseDefinitions.hpp:39
Definition WsfParser.hpp:270
UtTextDocumentRange mRange
Definition WsfParser.hpp:273
WsfParseRule * mReaderPtr
Definition WsfParser.hpp:272
Definition WsfParseIndex.hpp:40
To improve efficiency, WsfParseNodePool handles the allocation and deletion of WsfParseNode's.
Definition WsfParseNode.hpp:204
Definition WsfParseNode.hpp:61
Definition WsfParseRule.hpp:131
Definition WsfParseSourceInclude.hpp:31
Interface providing source files to the WsfParser.
Definition WsfParseSourceProvider.hpp:24
void SetFullyExpandNodes(bool aValue)
Definition WsfParser.hpp:149
void ClearPartialMatches()
Definition WsfParser.hpp:77
WsfParseSourceInclude * GetCurrentInclude()
Definition WsfParser.hpp:79
void PushSequence(WsfParseNode *aNodePtr)
Definition WsfParser.hpp:109
const std::vector< WsfParseError * > & GetErrors() const
Definition WsfParser.hpp:104
void FreeNode(WsfParseNode *aNodePtr)
Definition WsfParser.hpp:138
void DeleteAllNodes()
Node pool functions.
Definition WsfParser.hpp:126
WsfParseSourceProvider * GetSourceProvider()
Definition WsfParser.hpp:106
WsfParseNode * GetCurrentSequence()
Definition WsfParser.hpp:108
WsfParseNode * NewNode()
Definition WsfParser.hpp:136
void PushTerminator(const char *aTerminatorString)
Definition WsfParser.hpp:91
void PartialMatch(UtTextDocumentRange aRange)
Definition WsfParser.hpp:74
void AddAuxiliaryValue(WsfParseAuxData *aDataPtr)
Definition WsfParser.hpp:144
void PopTerminator()
Definition WsfParser.hpp:96
bool FullyExpandNodes() const
Definition WsfParser.hpp:148
void SetWorkingDirectory(const UtPath &aWorkingDirectory)
Definition WsfParser.hpp:102
void SetIgnoreIncludes(bool aIngoreIncludes)
Definition WsfParser.hpp:150
WsfParseDefinitions * GetDefinitions()
Definition WsfParser.hpp:83
void SwapPool(WsfParser &aRhs)
Definition WsfParser.hpp:128
WsfParser & operator=(const WsfParser &)=delete
void PushDeferredSource(const UtPath &aFilePath)
Definition WsfParser.cpp:719
bool IsDelayLoading()
Definition WsfParser.hpp:122
void SwapPool(WsfParseNodePool &aPool)
Definition WsfParser.hpp:129
UtTextDocument * PushSource(const std::string &aFilePath, bool aForceInclude, UtTextDocumentRange *aIncludeLocation=nullptr, bool aSearchIncludePaths=true)
Definition WsfParser.cpp:265
const UtPath & GetWorkingDirectory() const
Definition WsfParser.hpp:103
UtTextDocument * FindSource(const std::string &aFilePath, bool aSearchIncludePaths=true, bool aReadFile=true)
Definition WsfParser.cpp:209
size_t GetWordsRead() const
Returns the number of words that have been read since the last call to Reset().
Definition WsfParser.hpp:57
void PopSequence()
Definition WsfParser.hpp:110
WsfParser(WsfParseSourceProvider *aSourceProviderPtr, const UtPath &aWorkingDirectory, WsfParseDefinitions *aDefinitionsPtr=nullptr)
Definition WsfParser.cpp:37
WsfParseNode * NewNode(WsfParseRule *aRule, const char *aType, UtTextDocumentRange aValue=UtTextDocumentRange())
Definition WsfParser.hpp:131
WsfParseIndex *& GetParseIndex()
Definition WsfParser.hpp:82
WsfParseNode * ParseFiles(const std::vector< UtPath > &aFileList, int aMaxErrors)
Definition WsfParser.cpp:813
void AddError(WsfParseError *aErrorPtr)
Definition WsfParser.hpp:75