returns cmd == nullptr on eof */
| 327 | |
| 328 | /* returns cmd == nullptr on eof */ |
| 329 | static ParsedCommandString ParseCommandString(StringConsumer &consumer) |
| 330 | { |
| 331 | ParsedCommandString result; |
| 332 | |
| 333 | /* Scan to the next command, exit if there's no next command. */ |
| 334 | consumer.SkipUntilChar('{', StringConsumer::KEEP_SEPARATOR); |
| 335 | if (!consumer.ReadCharIf('{')) return {}; |
| 336 | |
| 337 | if (auto argno = consumer.TryReadIntegerBase<uint32_t>(10); argno.has_value()) { |
| 338 | result.argno = argno; |
| 339 | if (!consumer.ReadCharIf(':')) StrgenFatal("missing arg #"); |
| 340 | } |
| 341 | |
| 342 | /* parse command name */ |
| 343 | auto command = consumer.ReadUntilCharIn("} =."); |
| 344 | result.cmd = FindCmd(command); |
| 345 | if (result.cmd == nullptr) { |
| 346 | StrgenError("Undefined command '{}'", command); |
| 347 | return {}; |
| 348 | } |
| 349 | |
| 350 | /* parse case */ |
| 351 | if (consumer.ReadCharIf('.')) { |
| 352 | if (!result.cmd->flags.Test(CmdFlag::Case)) { |
| 353 | StrgenFatal("Command '{}' can't have a case", result.cmd->cmd); |
| 354 | } |
| 355 | |
| 356 | auto casep = consumer.ReadUntilCharIn("} "); |
| 357 | result.casei = ResolveCaseName(casep); |
| 358 | } |
| 359 | |
| 360 | /* parse params */ |
| 361 | result.param = consumer.ReadUntilChar('}', StringConsumer::KEEP_SEPARATOR); |
| 362 | |
| 363 | if (!consumer.ReadCharIf('}')) { |
| 364 | StrgenError("Missing }} from command '{}'", result.cmd->cmd); |
| 365 | return {}; |
| 366 | } |
| 367 | |
| 368 | return result; |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * Prepare reading. |
no test coverage detected