WSF
AutoComplete.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef AUTOCOMPLETE_HPP
13#define AUTOCOMPLETE_HPP
14#include <string>
15#include <vector>
16
17#include "WsfParseType.hpp"
18class WsfParseRule;
19class WsfParseNode;
20class WsfParseType;
22
23namespace wizard
24{
25class ParseResults;
26class TextSource;
27
52{
53public:
64 void GetSuggestions(ParseResults& aParseData,
65 TextSource& aSource,
66 WsfParseNode* aNodePtr,
67 const std::string& aText,
68 size_t aInsertPosition,
69 Results& aResults);
70 using Syntax = std::vector<std::string>;
71 using SyntaxList = std::vector<Syntax>;
73 {
74 size_t mWordIndex;
75 // The number of words that are in the base command
76 // For instance: platform <name> <type> ... end_platform
77 // has 3 concrete words. We stop showing syntax once '...' is reached
80 };
81 void GetSyntax(ParseResults& aParseData,
82 TextSource& aSource,
83 WsfParseNode* aNodePtr,
84 const std::string& aText,
85 size_t aInsertPosition,
86 SyntaxResults& aResults);
87
88protected:
94
95 struct Entry
96 {
112 Entry();
113 Entry(const std::string& aText, bool aWordIsPattern);
114 Entry(const Entry& aRhs);
115 Entry& operator=(const Entry&) = default; // Copy assignment
116 ~Entry();
117 void Set(const std::string& aText);
118 void SetTypeRef(const WsfParseTypePath& aRefType, bool aIsNestedLookup);
119 void SetNameRef(const std::string& aRefType);
120 int GetWordCount() const;
121
123 std::string mWordText;
128 std::vector<Entry*> mChildren;
135 // std::string mRefType;
136 std::string mRuleName;
137 };
138
139 struct Query
140 {
141 public:
142 ~Query() = default;
143 std::vector<std::string> mQueryWords;
145
147 };
148
149 SyntaxList CollectSyntax(Entry* aEntryTreePtr, bool aFirstWord = true);
150 SyntaxList JoinSyntax(const SyntaxList& aLhs, const SyntaxList& aRhs);
151 void GetIncludeSuggestions(const std::string& aText, TextSource& aSource, ParseResults& aParseData, Results& aResults);
152 bool FullyExpandWord(size_t aWordIndex) const;
153 void DigestInput(const std::string& aText, size_t aInputPosition, size_t& aReplaceCharacters, size_t& aInsertPosition);
154 int ExpandTree(Entry& aEntry, const WsfParseType* aCurrentTypePtr, int aWordIndex, int aMaxWordIndex);
155 bool TextMatches(const std::string& aText, size_t aWordIndex);
156 bool TextMatches(const std::string& aText, const std::string& aQuery);
157
158 WsfParseNode* FindBlock(WsfParseNode* aNodePtr, int aInsertPosition);
159
160 bool ExpandRule(int aWordIndex,
161 WsfParseRule* aReaderPtr,
162 const WsfParseType* aCurrentTypePtr,
163 Entry& aEntry,
164 bool aExpandBlock = false);
165 void ExpandRefType(Entry& aEntry, const WsfParseType* aCurrentTypePtr, int aWordIndex);
166 void Prune(int aQueryWordIndex, Entry*& aEntry);
167 void CollectSuggestions(Entry* aRootEntry, size_t aWordIndex, std::vector<std::string>& aSuggestions, bool& aLastToken);
168 bool FindSuggestionTerminator(Entry* aEntryWord, std::string& aTerminatorToken);
170 int CountSuggestions(Entry* aRootEntry);
171
172 const WsfParseType* FindCurrentType(WsfParseNode* aNodePtr);
173
176 // WsfParseType* mCurrentTypePtr;
179
181};
182} // namespace wizard
183
184#endif
std::vector< UtStringRef > WsfParseTypePath
Definition WsfParseTypePath.hpp:21
Definition WsfParseNode.hpp:61
Definition WsfParseRule.hpp:131
Definition WsfParseSequence.hpp:21
Definition WsfParseType.hpp:40
std::vector< Syntax > SyntaxList
Definition AutoComplete.hpp:71
void GetSuggestions(ParseResults &aParseData, TextSource &aSource, WsfParseNode *aNodePtr, const std::string &aText, size_t aInsertPosition, Results &aResults)
Definition AutoComplete.cpp:184
int CountSuggestions(Entry *aRootEntry)
Definition AutoComplete.cpp:1286
WsfParseNode * FindNextBlock(WsfParseNode *aBlockPtr)
Definition AutoComplete.cpp:1334
bool ExpandRule(int aWordIndex, WsfParseRule *aReaderPtr, const WsfParseType *aCurrentTypePtr, Entry &aEntry, bool aExpandBlock=false)
Definition AutoComplete.cpp:668
bool TextMatches(const std::string &aText, size_t aWordIndex)
Definition AutoComplete.cpp:440
void GetIncludeSuggestions(const std::string &aText, TextSource &aSource, ParseResults &aParseData, Results &aResults)
Definition AutoComplete.cpp:386
const WsfParseType * mCurrentTypeRef
Definition AutoComplete.hpp:177
void DigestInput(const std::string &aText, size_t aInputPosition, size_t &aReplaceCharacters, size_t &aInsertPosition)
Definition AutoComplete.cpp:531
void Prune(int aQueryWordIndex, Entry *&aEntry)
Definition AutoComplete.cpp:1120
AutoComplete()
Definition AutoComplete.cpp:55
std::vector< std::string > Syntax
Definition AutoComplete.hpp:70
Operation
Definition AutoComplete.hpp:90
@ cAUTOCOMPLETE
Definition AutoComplete.hpp:91
@ cSYNTAX
Definition AutoComplete.hpp:92
bool mExpandTypeCommand
Definition AutoComplete.hpp:178
Query mCurrentQuery
Definition AutoComplete.hpp:180
void ExpandRefType(Entry &aEntry, const WsfParseType *aCurrentTypePtr, int aWordIndex)
Definition AutoComplete.cpp:1012
bool mExpanded
Definition AutoComplete.hpp:174
SyntaxList JoinSyntax(const SyntaxList &aLhs, const SyntaxList &aRhs)
Definition AutoComplete.cpp:280
bool FullyExpandWord(size_t aWordIndex) const
Definition AutoComplete.cpp:1349
WsfParseNode * FindBlock(WsfParseNode *aNodePtr, int aInsertPosition)
Definition AutoComplete.cpp:620
int ExpandTree(Entry &aEntry, const WsfParseType *aCurrentTypePtr, int aWordIndex, int aMaxWordIndex)
Definition AutoComplete.cpp:920
void CollectSuggestions(Entry *aRootEntry, size_t aWordIndex, std::vector< std::string > &aSuggestions, bool &aLastToken)
Definition AutoComplete.cpp:1220
const WsfParseType * FindCurrentType(WsfParseNode *aNodePtr)
Definition AutoComplete.cpp:469
ParseResults * mParseResultsPtr
Definition AutoComplete.hpp:175
SyntaxList CollectSyntax(Entry *aEntryTreePtr, bool aFirstWord=true)
Definition AutoComplete.cpp:341
bool FindSuggestionTerminator(Entry *aEntryWord, std::string &aTerminatorToken)
Definition AutoComplete.cpp:1199
void GetSyntax(ParseResults &aParseData, TextSource &aSource, WsfParseNode *aNodePtr, const std::string &aText, size_t aInsertPosition, SyntaxResults &aResults)
Definition AutoComplete.cpp:63
Provides access to the results of parsing the WSF inputs.
Definition ParseResults.hpp:147
Definition TextSource.hpp:48
Definition Runner.hpp:22
Definition AutoComplete.hpp:96
bool mWordIsPattern
Definition AutoComplete.hpp:131
Entry & operator=(const Entry &)=default
void SetTypeRef(const WsfParseTypePath &aRefType, bool aIsNestedLookup)
Definition AutoComplete.cpp:1416
EntryType mEntryType
Definition AutoComplete.hpp:122
int mFlags
Definition AutoComplete.hpp:129
int GetWordCount() const
Definition AutoComplete.cpp:1442
WsfParseRule * mReaderPtr
Definition AutoComplete.hpp:124
~Entry()
Definition AutoComplete.cpp:1400
bool mComplete
Definition AutoComplete.hpp:130
EntryType
Definition AutoComplete.hpp:98
@ cTYPE_CHANGE
Definition AutoComplete.hpp:104
@ cUNEXPANDED
Definition AutoComplete.hpp:100
@ cSEQUENCE
Definition AutoComplete.hpp:102
@ cWORD
Definition AutoComplete.hpp:101
@ cALTERNATE
Definition AutoComplete.hpp:103
@ cNONE
Definition AutoComplete.hpp:99
WsfParseTypePath mRefType
Definition AutoComplete.hpp:133
std::string mWordText
Definition AutoComplete.hpp:123
void Set(const std::string &aText)
Definition AutoComplete.cpp:1408
void SetNameRef(const std::string &aRefType)
Definition AutoComplete.cpp:1431
int mWordCount
Definition AutoComplete.hpp:132
Entry()
Definition AutoComplete.cpp:1354
bool mNestedLookup
Definition AutoComplete.hpp:134
std::string mRuleName
Definition AutoComplete.hpp:136
const WsfParseType * mCurrentTypeChangePtr
Definition AutoComplete.hpp:126
size_t mCommandWordIndex
Definition AutoComplete.hpp:127
WsfParseSequence * mParentCommandPtr
Definition AutoComplete.hpp:125
Flags
Definition AutoComplete.hpp:107
@ cBLOCK_PLACEHOLDER
Definition AutoComplete.hpp:110
@ cNAMED_WORD
Definition AutoComplete.hpp:108
@ cTYPE_REF_WORD
Definition AutoComplete.hpp:109
std::vector< Entry * > mChildren
Definition AutoComplete.hpp:128
Definition AutoComplete.hpp:140
size_t mQueryWordIndex
Definition AutoComplete.hpp:144
std::vector< std::string > mQueryWords
Definition AutoComplete.hpp:143
Operation mOperation
Definition AutoComplete.hpp:146
Definition AutoComplete.hpp:55
std::vector< std::string > mSuggestionList
Definition AutoComplete.hpp:56
bool mLastToken
Definition AutoComplete.hpp:60
bool mPartialToken
Definition AutoComplete.hpp:61
WsfParseNode * mParentNodePtr
Definition AutoComplete.hpp:57
size_t mReplaceCharacters
Definition AutoComplete.hpp:59
size_t mInsertPosition
Definition AutoComplete.hpp:58
Definition AutoComplete.hpp:73
size_t mWordIndex
Definition AutoComplete.hpp:74
size_t mConcreteWordCount
Definition AutoComplete.hpp:78
SyntaxList mSequences
Definition AutoComplete.hpp:79
Copyrights Multiple, All Rights Reserved