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"
37
#include <cmath>
gsell's avatar
gsell committed
38 39 40 41
#include <ctime>
#include <exception>
#include <iostream>
#include <new>
42
#include <boost/algorithm/string.hpp>
gsell's avatar
gsell committed
43 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

#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 {
74
        std::string name = parseString(stat, "Identifier or keyword expected.");
gsell's avatar
gsell committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

        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.
92 93
            stat.mark();
            stat.start();
94 95 96 97 98 99 100 101 102
            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";
103 104
                std::ostringstream statStr;
                stat.print(statStr);
105 106
                if (hint != "") {
                    throw ParseError("OpalParser::parse()",
107
                                     statStr.str() +
108 109 110 111 112
                                     positionIndicator +
                                     "Syntax error, either the keyword REAL is missing or\n" +
                                     hint);
                } else {
                    throw ParseError("OpalParser::parse()",
113
                                     statStr.str() +
114 115 116
                                     positionIndicator +
                                     "Syntax error, the keyword REAL is missing\n");
                }
117
            }
gsell's avatar
gsell committed
118 119 120 121 122 123
            parseAssign(stat);
        }
    }
}


124
void OpalParser::execute(Object *object, const std::string &name) const {
gsell's avatar
gsell committed
125 126 127 128 129 130 131 132 133 134 135 136 137
    // 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
138 139
    object->execute();

gsell's avatar
gsell committed
140 141 142 143 144 145 146 147 148
    // 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;
    }
}


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


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

    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
166
        Object *copy = 0;
gsell's avatar
gsell committed
167
        try {
kraus's avatar
kraus committed
168
            copy = object->clone("");
gsell's avatar
gsell committed
169 170
            copy->parse(stat);
            parseEnd(stat);
kraus's avatar
kraus committed
171 172 173 174
            execute(copy, cmdName);
            delete copy;
        } catch (...) {
            delete copy;
gsell's avatar
gsell committed
175 176 177
            throw;
        }
    } else {
178 179
        std::string hint = getHint(cmdName, "command");
        if (hint != "") {
180
            throw ParseError("OpalParser::parseAction()",
181 182 183
                             "Syntax error, " + hint);
        }

gsell's avatar
gsell committed
184 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
        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;
        }
    }

223
    std::string objName = parseString(stat, "Object name expected.");
gsell's avatar
gsell committed
224 225
    // Test for attribute name.
    Object *object = 0;
226
    std::string attrName;
gsell's avatar
gsell committed
227 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

    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('[')) {
288
        index = int(std::round(parseRealConst(stat)));
gsell's avatar
gsell committed
289 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
        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");
327
    std::string objName = parseString(stat, "Object name expected.");
gsell's avatar
gsell committed
328 329

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

        if(classObject == 0) {
kraus's avatar
kraus committed
334
            if (clsName == "SURFACEPHYSICS")
335
              throw ParseError("OpalParser::parseDefine()",
kraus's avatar
kraus committed
336 337 338 339
                               "The object \"" + clsName + "\" is changed to \"PARTICLEMATTERINTERACTION\".");
            else
                throw ParseError("OpalParser::parseDefine()",
                                 "The object \"" + clsName + "\" is unknown.");
gsell's avatar
gsell committed
340 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
        }

        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(';')) {
373 374 375

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

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


387
void OpalParser::parseMacro(const std::string &macName, Statement &stat) const {
gsell's avatar
gsell committed
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
    // 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.
405
        std::string className = parseString(stat, "Class name expected.");
gsell's avatar
gsell committed
406 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

        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.");
        }
    }
}


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

    if(object == 0) {
        *gmsg << "\nOpalParser::printHelp(): Unknown object \""
              << cmdName << "\".\n" << endl;
    } else {
450
        object->printHelp(std::cerr);
gsell's avatar
gsell committed
451 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
    }
}


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) {
583 584 585
        ERRORMSG("\n*** Parse error detected by function \""
                 << "OpalParser::readStatement()" << "\"\n");
        stat->printWhere(*IpplInfo::Error, true);
586 587 588 589

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

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

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

    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) {
608
            Inform errorMsg("Error", std::cerr);
609 610 611
            errorMsg << "\n*** Parse error detected by function \""
                     << ex.where() << "\"\n";
            stat->printWhere(errorMsg, true);
612
            std::string what = ex.what();
613 614
            size_t pos = what.find_first_of('\n');
            do {
615
                errorMsg << "    " << what.substr(0, pos) << endl;
616 617 618
                what = what.substr(pos + 1, std::string::npos);
                pos = what.find_first_of('\n');
            } while (pos != std::string::npos);
619
            errorMsg << "    " << what << endl;
620

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

        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;
638 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
}

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
700
}