MCPcopy Create free account
hub / github.com/Kitware/CMake / Parse

Method Parse

Source/cmListFileCache.cxx:154–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154bool cmListFileParser::Parse()
155{
156 // Use a simple recursive-descent parser to process the token
157 // stream.
158 bool haveNewline = true;
159 while (cmListFileLexer_Token* token =
160 cmListFileLexer_Scan(this->Lexer.get())) {
161 if (token->type == cmListFileLexer_Token_Space) {
162 } else if (token->type == cmListFileLexer_Token_Newline) {
163 haveNewline = true;
164 } else if (token->type == cmListFileLexer_Token_CommentBracket) {
165 haveNewline = false;
166 } else if (token->type == cmListFileLexer_Token_Identifier) {
167 if (haveNewline) {
168 haveNewline = false;
169 if (this->ParseFunction(cm::string_view(token->text, token->length),
170 token->line)) {
171 this->ListFile->Functions.emplace_back(
172 std::move(this->FunctionName), this->FunctionLine,
173 this->FunctionLineEnd, std::move(this->FunctionArguments));
174 } else {
175 return false;
176 }
177 } else {
178 auto error = cmStrCat(
179 "Parse error. Expected a newline, got ",
180 cmListFileLexer_GetTypeAsString(this->Lexer.get(), token->type),
181 " with text \"", cm::string_view(token->text, token->length), "\".");
182 this->IssueError(error);
183 return false;
184 }
185 } else {
186 auto error = cmStrCat(
187 "Parse error. Expected a command name, got ",
188 cmListFileLexer_GetTypeAsString(this->Lexer.get(), token->type),
189 " with text \"", cm::string_view(token->text, token->length), "\".");
190 this->IssueError(error);
191 return false;
192 }
193 }
194
195 // Check if all functions are nested properly.
196 if (auto badNesting = this->CheckNesting()) {
197 this->Messenger->IssueMessage(
198 MessageType::FATAL_ERROR,
199 "Flow control statements are not properly nested.",
200 this->Backtrace.Push(*badNesting));
201 cmSystemTools::SetFatalErrorOccurred();
202 return false;
203 }
204
205 return true;
206}
207
208bool cmListFileParser::ParseFunction(cm::string_view name, long line)
209{

Callers 2

ParseFileMethod · 0.95
ParseStringMethod · 0.95

Calls 11

ParseFunctionMethod · 0.95
IssueErrorMethod · 0.95
CheckNestingMethod · 0.95
cmListFileLexer_ScanFunction · 0.85
moveFunction · 0.85
emplace_backMethod · 0.80
PushMethod · 0.80
cmStrCatFunction · 0.70
getMethod · 0.45
IssueMessageMethod · 0.45

Tested by

no test coverage detected