OpalParser.cpp 23.4 KB
Newer Older
Adelmann Andreas's avatar
Adelmann Andreas committed
1

gsell's avatar
gsell committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// ------------------------------------------------------------------------
// $RCSfile: OpalParser.cpp,v $
// ------------------------------------------------------------------------
// $Revision: 1.3 $
// ------------------------------------------------------------------------
// Copyright: see Copyright.readme
// ------------------------------------------------------------------------
//
// Class OpalParser:
//   This is the default parser for OPAL statements.
//
// ------------------------------------------------------------------------
//
// $Date: 2001/08/13 15:17:27 $
// $Author: jowett $
//
// ------------------------------------------------------------------------

#include "OpalParser/OpalParser.h"
#include "AbstractObjects/Action.h"
#include "AbstractObjects/Attribute.h"
#include "AbstractObjects/Expressions.h"
#include "AbstractObjects/OpalData.h"
#include "AbstractObjects/Object.h"
#include "AbstractObjects/ValueDefinition.h"
#include "Attributes/Attributes.h"
#include "OpalParser/CompoundStatement.h"
#include "OpalParser/IfStatement.h"
#include "OpalParser/WhileStatement.h"
#include "MemoryManagement/Pointer.h"
#include "Parser/SimpleStatement.h"
#include "Parser/Token.h"
#include "Utilities/OpalException.h"
#include "Utilities/ParseError.h"
36
#include "Utilities/Options.h"
gsell's avatar
gsell committed
37
#include <cassert>
38
#include <cmath>
gsell's avatar
gsell committed
39 40 41 42
#include <ctime>
#include <exception>
#include <iostream>
#include <new>
43
#include <boost/algorithm/string.hpp>
gsell's avatar
gsell committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

#include <Ippl.h>

using namespace Expressions;

extern Inform *gmsg;

// Class OpalParser
// ------------------------------------------------------------------------

std::vector<Pointer<TokenStream> > OpalParser::inputStack;


OpalParser::OpalParser(): stopFlag(false)
{}


OpalParser::~OpalParser()
{}


void OpalParser::parse(Statement &stat) const {
    if(stat.keyword("SHARED")) {
        // "SHARED ...": Shared object definition.
        parseDefine(stat);
    } else if(stat.keyword("CONSTANT") || stat.keyword("CONST") ||
              stat.keyword("BOOL") || stat.keyword("REAL") ||
              stat.keyword("STRING") || stat.keyword("VECTOR")) {
        // Keywords introducing variable definitions.
        parseAssign(stat);
    } else {
75
        std::string name = parseString(stat, "Identifier or keyword expected.");
gsell's avatar
gsell committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

        if(stat.delimiter('?')) {
            // "<class>?": give help for class.
            printHelp(name);
        } else if(stat.delimiter(':')) {
            // "<object>:<class>...": labeled command.
            parseDefine(stat);
        } else if(stat.delimiter('(')) {
            // "<macro>(...)...": macro definition or call.
            // We are positioned just after the '(' of the argument list.
            parseMacro(name, stat);
        } else if(stat.delimiter(',') || stat.delimiter(';') ||
                  stat.atEnd()) {
            // "<class>" or "<class>,<attributes>": Executable command.
            parseAction(stat);
        } else {
            // Assignment beginning with a name.
93 94
            stat.mark();
            stat.start();
95 96 97 98 99 100 101 102 103
            std::string objName = parseString(stat, "Object name expected.");
            if (OpalData::getInstance()->find(objName) == 0) {
                Token tok = stat.getCurrent();
                stat.restore();

                std::string name = tok.getLex();
                std::string hint = getHint(name);
                unsigned int position = stat.position();
                std::string positionIndicator = std::string(position, ' ') + "^\n";
104 105
                std::ostringstream statStr;
                stat.print(statStr);
106 107
                if (hint != "") {
                    throw ParseError("OpalParser::parse()",
108
                                     statStr.str() +
109 110 111 112 113
                                     positionIndicator +
                                     "Syntax error, either the keyword REAL is missing or\n" +
                                     hint);
                } else {
                    throw ParseError("OpalParser::parse()",
114
                                     statStr.str() +
115 116 117
                                     positionIndicator +
                                     "Syntax error, the keyword REAL is missing\n");
                }
118
            }
gsell's avatar
gsell committed
119 120 121 122 123 124
            parseAssign(stat);
        }
    }
}


125
void OpalParser::execute(Object *object, const std::string &name) const {
gsell's avatar
gsell committed
126 127 128 129 130 131 132 133 134 135 136 137 138
    // Trace execution.
    if(Options::mtrace && object->shouldTrace()) {
        double time = double(clock()) / double(CLOCKS_PER_SEC);
        *gmsg << "\nBegin execution: \"" << name
              << "\", CPU time = " << time << " seconds.\n" << endl;
    }

    // Force updating of all attributes which might have been changed.
    if(object->shouldUpdate()) {
        OpalData::getInstance()->update();
    }

    // Execute or check the command.
kraus's avatar
kraus committed
139 140
    object->execute();

gsell's avatar
gsell committed
141 142 143 144 145 146 147 148 149
    // Trace execution.
    if(Options::mtrace && object->shouldTrace()) {
        double time = double(clock()) / double(CLOCKS_PER_SEC);
        *gmsg << "\nEnd execution:   \"" << name
              << "\", CPU time = " << time << " seconds.\n" << endl;
    }
}


150
Object *OpalParser::find(const std::string &name) const {
gsell's avatar
gsell committed
151 152 153 154 155 156
    return OpalData::getInstance()->find(name);
}


void OpalParser::parseAction(Statement &stat) const {
    stat.start();
157
    std::string cmdName = parseString(stat, "Command name expected");
gsell's avatar
gsell committed
158 159 160 161 162 163 164 165 166

    if(cmdName == "STOP") {
        stopFlag = true;
    } else if(cmdName == "QUIT") {
        stopFlag = true;
    } else if(cmdName == "HELP"  &&  stat.delimiter(',')) {
        cmdName = parseString(stat, "Object name expected");
        printHelp(cmdName);
    } else if(Object *object = find(cmdName)) {
kraus's avatar
kraus committed
167
        Object *copy = 0;
gsell's avatar
gsell committed
168
        try {
kraus's avatar
kraus committed
169
            copy = object->clone("");
gsell's avatar
gsell committed
170 171
            copy->parse(stat);
            parseEnd(stat);
kraus's avatar
kraus committed
172 173 174 175
            execute(copy, cmdName);
            delete copy;
        } catch (...) {
            delete copy;
gsell's avatar
gsell committed
176 177 178
            throw;
        }
    } else {
179 180 181 182 183 184
        std::string hint = getHint(cmdName, "command");
        if (hint != "") {
            throw ParseError("OpalParser::parse()",
                             "Syntax error, " + hint);
        }

gsell's avatar
gsell committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
        throw ParseError("OpalParser::parseAction()",
                         "Command \"" + cmdName + "\" is unknown.");
    }
}


void OpalParser::parseAssign(Statement &stat) const {
    stat.start();

    // Find various model objects.
    /*static*/
    Object *boolConstant   = OpalData::getInstance()->find("BOOL_CONSTANT");
    /*static*/
    Object *realConstant   = OpalData::getInstance()->find("REAL_CONSTANT");
    /*static*/
    Object *realVariable   = OpalData::getInstance()->find("REAL_VARIABLE");
    /*static*/
    Object *realVector     = OpalData::getInstance()->find("REAL_VECTOR");
    /*static*/
    Object *stringConstant = OpalData::getInstance()->find("STRING_CONSTANT");

    // Gobble up any prefix.
    int code = 0x00;
    while(true) {
        if(stat.keyword("CONSTANT") || stat.keyword("CONST")) {
            code |= 0x01;
        } else if(stat.keyword("BOOL")) {
            code |= 0x02;
        } else if(stat.keyword("REAL")) {
            code |= 0x04;
        } else if(stat.keyword("STRING")) {
            code |= 0x08;
        } else if(stat.keyword("VECTOR")) {
            code |= 0x10;
        } else {
            break;
        }
    }

224
    std::string objName = parseString(stat, "Object name expected.");
gsell's avatar
gsell committed
225 226
    // Test for attribute name.
    Object *object = 0;
227
    std::string attrName;
gsell's avatar
gsell committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288

    if(stat.delimiter("->")) {
        // Assignment to object attribute.
        attrName = parseString(stat, "Attribute name expected.");

        if(code != 0) {
            throw ParseError("OpalParser::parseAssign()",
                             "Invalid type specification for this value.");
        } else if((object = OpalData::getInstance()->find(objName)) == 0) {
            throw ParseError("OpalParser::parseAssign()",
                             "The object \"" + objName + "\" is unknown.");
        }
    } else {
        // Assignment to variable-like object.
        if((object = OpalData::getInstance()->find(objName)) == 0) {
            Object *model = 0;
            switch(code) {
                case 0x01:  // CONSTANT
                case 0x05:  // CONSTANT REAL
                    model = realConstant;
                    break;
                case 0x02:  // BOOL
                case 0x03:  // BOOL CONSTANT
                    model = boolConstant;
                    break;
                case 0x00:  // empty <type>.
                case 0x04:  // REAL
                    model = realVariable;
                    break;
                case 0x10:  // VECTOR
                case 0x11:  // CONSTANT VECTOR
                case 0x14:  // REAL VECTOR
                case 0x15:  // CONSTANT REAL VECTOR
                    model = realVector;
                    break;
                case 0x08:  // STRING
                case 0x09:  // STRING CONSTANT
                    model = stringConstant;
                    break;
                default:
                    break;
            }

            if(model != 0) {
                object = model->clone(objName);
                OpalData::getInstance()->define(object);
            } else {
                throw ParseError("OpalParser::parseAssign()", "Invalid <type> field.");
            }
        } else if(object->isTreeMember(realConstant)) {
            throw ParseError("OpalParser::parseAssign()",
                             "You cannot redefine the constant \"" + objName + "\".");
        }

        attrName = "VALUE";
    }

    // Test for index; it is evaluated immediately.
    int index = 0;

    if(stat.delimiter('[')) {
289
        index = int(std::round(parseRealConst(stat)));
gsell's avatar
gsell committed
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
        parseDelimiter(stat, ']');

        if(index <= 0) {
            throw ParseError("Expressions::parseReference()",
                             "Index must be positive.");
        }
    }

    if(object != 0) {
        if(Attribute *attr = object->findAttribute(attrName)) {
            if(stat.delimiter('=') || object->isTreeMember(realConstant)) {
                if(index > 0) {
                    attr->parseComponent(stat, true, index);
                } else {
                    attr->parse(stat, true);
                }
            } else if(stat.delimiter(":=")) {
                if(index > 0) {
                    attr->parseComponent(stat, false, index);
                } else {
                    attr->parse(stat, false);
                }
            }
        } else {
            throw ParseError("OpalParser::parseAssign()",
                             "Object \"" + objName + "\" has no attribute \"" +
                             attrName + "\".");
        }

        parseEnd(stat);
        OpalData::getInstance()->makeDirty(object);
    }
}


void OpalParser::parseDefine(Statement &stat) const {
    stat.start();
    bool isShared = stat.keyword("SHARED");
328
    std::string objName = parseString(stat, "Object name expected.");
gsell's avatar
gsell committed
329 330

    if(stat.delimiter(':')) {
331
        std::string clsName = parseString(stat, "Class name expected.");
gsell's avatar
gsell committed
332 333 334
        Object *classObject = find(clsName);

        if(classObject == 0) {
kraus's avatar
kraus committed
335
            if (clsName == "SURFACEPHYSICS")
336
              throw ParseError("OpalParser::parseDefine()",
kraus's avatar
kraus committed
337 338 339 340
                               "The object \"" + clsName + "\" is changed to \"PARTICLEMATTERINTERACTION\".");
            else
                throw ParseError("OpalParser::parseDefine()",
                                 "The object \"" + clsName + "\" is unknown.");
gsell's avatar
gsell committed
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
        }

        Object *copy = 0;
        try {
            if(stat.delimiter('(')) {
                // Macro-like objects are always classes, instances never.
                // There is no further check required.
                copy = classObject->makeInstance(objName, stat, this);
            } else {
                copy = classObject->clone(objName);
                copy->parse(stat);
                copy->setShared(isShared);
            }

            parseEnd(stat);
            execute(copy, clsName);
            OpalData::getInstance()->define(copy);
        } catch(...) {
            delete copy;
            throw;
        }
    } else {
        // Redefine an object to be a class.
        Object *classObject = find(objName);
        Object *copy = classObject->clone(objName);
        copy->parse(stat);
        copy->setShared(isShared);
    }
}


void OpalParser::parseEnd(Statement &stat) const {
    if(! stat.atEnd()  &&  ! stat.delimiter(';')) {
374 375 376

        unsigned int position = stat.position();
        std::string positionIndicator = std::string(position + 1, ' ') + "^\n";
377 378
        std::ostringstream statStr;
        stat.print(statStr);
379

gsell's avatar
gsell committed
380
        throw ParseError("OpalParser::parseEnd()",
381
                         statStr.str() +
382
                         positionIndicator +
gsell's avatar
gsell committed
383 384 385 386 387
                         "Syntax error (maybe missing comma or semicolon ? )");
    }
}


388
void OpalParser::parseMacro(const std::string &macName, Statement &stat) const {
gsell's avatar
gsell committed
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
    // Record the position just after the '(' of the argument list.
    stat.mark();

    // Skip argument list.
    int par_level = 1;
    while(true) {
        if(stat.delimiter('(')) {
            ++par_level;
        } else if(stat.delimiter(')')) {
            if(--par_level == 0) break;
        } else {
            stat.getCurrent();
        }
    }

    if(stat.delimiter(':')) {
        // Macro definition.
406
        std::string className = parseString(stat, "Class name expected.");
gsell's avatar
gsell committed
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443

        if(Object *macro = OpalData::getInstance()->find(className)) {
            // Backtrack to first argument.
            stat.restore();

            if(Object *copy =
                   macro->makeTemplate(macName, *inputStack.back(), stat)) {
                OpalData::getInstance()->define(copy);
            } else {
                throw ParseError("OpalParser::parseMacro()", "Command \"" +
                                 macName + "\" cannot be defined with arguments.");
            }
        } else {
            throw ParseError("OpalParser::parseMacro()",
                             "Object \"" + className + "\" is unknown.");
        }
    } else {
        // Macro call.
        if(Object *macro = OpalData::getInstance()->find(macName)) {
            // Backtrack to first argument.
            stat.restore();
            Object *instance = 0;
            try {
                instance = macro->makeInstance(macName, stat, this);
                execute(instance, macName);
            } catch(...) {
                delete instance;
                throw;
            }
        } else {
            throw ParseError("OpalParser::parseMacro()",
                             "Macro \"" + macName + "\" is unknown.");
        }
    }
}


444
void OpalParser::printHelp(const std::string &cmdName) const {
gsell's avatar
gsell committed
445 446 447 448 449 450
    Object *object = find(cmdName);

    if(object == 0) {
        *gmsg << "\nOpalParser::printHelp(): Unknown object \""
              << cmdName << "\".\n" << endl;
    } else {
451
        object->printHelp(std::cerr);
gsell's avatar
gsell committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
    }
}


void OpalParser::parseBracketList(char close, Statement &stat) {
    Token token = readToken();

    while(! token.isEOF()) {
        stat.append(token);

        if(token.isDel('(')) {
            parseBracketList(')', stat);
        } else if(token.isDel('[')) {
            parseBracketList(']', stat);
        } else if(token.isDel('{')) {
            parseBracketList('}', stat);
        } else if(token.isDel(close)) {
            return;
        }

        token = readToken();
    }
}


void OpalParser::parseTokenList(Statement &stat) {
    Token token = readToken();

    while(! token.isEOF()) {
        // End of list if semicolon occurs outside of brackets.
        if(token.isDel(';')) break;
        stat.append(token);

        if(token.isDel('(')) {
            parseBracketList(')', stat);
        } else if(token.isDel('[')) {
            parseBracketList(']', stat);
        } else if(token.isDel('{')) {
            parseBracketList('}', stat);
        }

        token = readToken();
    }
}


Token OpalParser::readToken() {
    if(inputStack.empty()) {
        return Token("", 0, Token::IS_EOF, "End of input");
    } else {
        return inputStack.back()->readToken();
    }
}


Statement *OpalParser::readStatement(TokenStream *is) const {
    Statement *stat = 0;
    Token token = is->readToken();

    try {
        if(token.isDel('{')) {
            // Compound statement.
            inputStack.back()->putBack(token);
            stat = new CompoundStatement(*inputStack.back());
        } else if(token.isKey("IF")) {
            // IF statement.
            inputStack.back()->putBack(token);
            stat = new IfStatement(*this, *inputStack.back());
        } else if(token.isKey("WHILE")) {
            // WHILE statement.
            inputStack.back()->putBack(token);
            stat = new WhileStatement(*this, *inputStack.back());
        } else if(token.isWord() || token.isString()) {
            // Simple statement or MACRO statement.
            stat = new SimpleStatement(token.getFile(), token.getLine());
            stat->append(token);
            token = is->readToken();

            if(! token.isEOF()) {
                if(token.isDel('(')) {
                    // Macro statement; statement already contains initial word.
                    stat->append(token);
                    parseBracketList(')', *stat);
                    token = is->readToken();

                    if(! token.isEOF() && token.isDel(':')) {
                        // Macro definition.
                        stat->append(token);
                        token = is->readToken();

                        if(! token.isEOF()) {
                            stat->append(token);
                            if(token.isKey("MACRO")) {
                                token = is->readToken();

                                if(! token.isEOF() && token.isDel('{')) {
                                    stat->append(token);
                                    parseBracketList('}', *stat);
                                } else {
                                    throw ParseError("OpalParser::readStatement()",
                                                     "MACRO definition lacks \"{...}\".");
                                }
                            } else {
                                parseTokenList(*stat);
                            }
                        }
                    } else if(! token.isDel(';')) {
                        throw ParseError("OpalParser::readStatement()",
                                         "MACRO call is not terminated by ';'.");
                    }
                } else if(! token.isDel(';')) {
                    stat->append(token);
                    parseTokenList(*stat);
                }
            }
            stat->start();
        } else if(token.isDel(';')) {
            // Skip empty statement.
            stat = readStatement(is);
        } else if(token.isDel('?')) {
            // Give help.
            *gmsg << "\ntry typing \"HELP\" or \"SHOW\" for help.\n" << endl;
            stat = readStatement(is);
        } else if(! token.isEOF()) {
            stat = new SimpleStatement(token.getFile(), token.getLine());
            stat->append(token);
            parseTokenList(*stat);
            stat->start();
            throw ParseError("OpalParser::readStatement()",
                             "Command should begin with a <name>.");
        }
    } catch(ParseError &ex) {
584 585 586
        ERRORMSG("\n*** Parse error detected by function \""
                 << "OpalParser::readStatement()" << "\"\n");
        stat->printWhere(*IpplInfo::Error, true);
587 588 589 590

        std::string what = ex.what();
        boost::replace_all(what, "\n", "\n    ");

591
        ERRORMSG("     " << *stat <<"    a" << what << '\n' << endl);
kraus's avatar
kraus committed
592

gsell's avatar
gsell committed
593
        stat = readStatement(is);
kraus's avatar
kraus committed
594
        exit(1);
gsell's avatar
gsell committed
595 596 597 598 599 600 601 602 603 604 605 606 607 608
    }

    return stat;
}


void OpalParser::run() const {
    stopFlag = false;
    while(Statement *stat = readStatement(&*inputStack.back())) {
        try {
            // The dispatch via Statement::execute() allows a special
            // treatment of structured statements.
            stat->execute(*this);
        } catch(ParseError &ex) {
609
            Inform errorMsg("Error", std::cerr);
610 611 612
            errorMsg << "\n*** Parse error detected by function \""
                     << ex.where() << "\"\n";
            stat->printWhere(errorMsg, true);
613
            std::string what = ex.what();
614 615
            size_t pos = what.find_first_of('\n');
            do {
616
                errorMsg << "    " << what.substr(0, pos) << endl;
617 618 619
                what = what.substr(pos + 1, std::string::npos);
                pos = what.find_first_of('\n');
            } while (pos != std::string::npos);
620
            errorMsg << "    " << what << endl;
621

kraus's avatar
kraus committed
622
            MPI_Abort(MPI_COMM_WORLD, -100);
gsell's avatar
gsell committed
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
        }

        delete stat;
        if(stopFlag) break;
    }
}

void OpalParser::run(TokenStream *is) const {
    inputStack.push_back(is);
    run();
    inputStack.pop_back();
}


void OpalParser::stop() const {
    stopFlag = true;
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
}

std::string OpalParser::getHint(const std::string &name, const std::string &type) {
    auto owner = AttributeHandler::getOwner(name);
    if (owner.size() > 0) {
        std::string hint = "the " + type + " '" + name + "' could belong to\n";
        {
            std::string elements = "";
            auto its = owner.equal_range(AttributeHandler::ELEMENT);
            if (its.first != its.second) {
                elements = (its.first)->second;
                bool any = (its.first)->second == "Any";
                for (auto it = std::next(its.first); it != its.second && !any; ++ it) {
                    elements += ", " + it->second;
                    any = it->second == "Any";
                }
                if (any) {
                    hint += std::string("  - any element\n");
                } else {
                    hint += std::string("  - the element") + (std::distance(its.first, its.second) > 1? "s ": " ") + elements + "\n";
                }
            }
        }
        {
            std::string commands = "";
            auto its = owner.equal_range(AttributeHandler::COMMAND);
            if (its.first != its.second) {
                commands = (its.first)->second;
                for (auto it = std::next(its.first); it != its.second; ++ it) {
                    commands += ", " + it->second;
                }
                hint += std::string("  - the command") + (std::distance(its.first, its.second) > 1? "s ": " ") + commands + "\n";
            }
        }
        {
            std::string sub_commands = "";
            auto its = owner.equal_range(AttributeHandler::SUB_COMMAND);
            if (its.first != its.second) {
                sub_commands = (its.first)->second;
                for (auto it = std::next(its.first); it != its.second; ++ it) {
                    sub_commands += ", " + it->second;
                }
                hint += std::string("  - the sub-command") + (std::distance(its.first, its.second) > 1? "s ": " ") + sub_commands + "\n";
            }
        }
        {
            std::string statements = "";
            auto its = owner.equal_range(AttributeHandler::STATEMENT);
            if (its.first != its.second) {
                statements = (its.first)->second;
                for (auto it = std::next(its.first); it != its.second; ++ it) {
                    statements += ", " + it->second;
                }
                hint += std::string("  - the statement") + (std::distance(its.first, its.second) > 1? "s ": " ") + statements + "\n";
            }
        }

        hint += "but it's not present!";
        return hint;
    }

    return "";
kraus's avatar
kraus committed
701
}