| 152 | } |
| 153 | |
| 154 | bool 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 | |
| 208 | bool cmListFileParser::ParseFunction(cm::string_view name, long line) |
| 209 | { |
no test coverage detected