| 298 | } |
| 299 | |
| 300 | std::optional<std::pair<std::string_view, std::optional<int>>> Parser::parseASTIDComment( |
| 301 | std::string_view _arguments, |
| 302 | langutil::SourceLocation const& _commentLocation |
| 303 | ) |
| 304 | { |
| 305 | static std::regex const argRegex = std::regex( |
| 306 | R"~~(^(\d+)(?:\s|$))~~", |
| 307 | std::regex_constants::ECMAScript | std::regex_constants::optimize |
| 308 | ); |
| 309 | std::match_results<std::string_view::const_iterator> match; |
| 310 | std::optional<int> astID; |
| 311 | bool matched = regex_search(_arguments.cbegin(), _arguments.cend(), match, argRegex); |
| 312 | std::string_view tail = _arguments; |
| 313 | if (matched) |
| 314 | { |
| 315 | solAssert(match.size() == 2, ""); |
| 316 | tail = _arguments.substr(static_cast<size_t>(match.position() + match.length())); |
| 317 | |
| 318 | astID = toInt(match[1].str()); |
| 319 | } |
| 320 | |
| 321 | if (!matched || !astID || *astID < 0 || static_cast<int64_t>(*astID) != *astID) |
| 322 | { |
| 323 | m_errorReporter.syntaxError(1749_error, _commentLocation, "Invalid argument for @ast-id."); |
| 324 | astID = std::nullopt; |
| 325 | } |
| 326 | if (matched) |
| 327 | return {{_arguments, astID}}; |
| 328 | else |
| 329 | return std::nullopt; |
| 330 | } |
| 331 | |
| 332 | Block Parser::parseBlock() |
| 333 | { |