/*! Writes the command `c` (with all embedded comments) a terminating ; will be written if any tokens are written. */ bool WriteCommandAsNexus(std::ostream & out, const ProcessedNxsCommand &c) { if (c.empty()) return false; out << " "; /* command indentation - 1 space*/ for(ProcessedNxsCommand::const_iterator cIt = c.begin(); cIt != c.end(); ++cIt) { out << ' '; cIt->WriteAsNexus(out); } out << ";"; return true; }
void NxsBlock::DemandEquals(ProcessedNxsCommand::const_iterator & tokIt, const ProcessedNxsCommand::const_iterator & endIt, const char *contextString) const { ++tokIt; if (tokIt == endIt) { errormsg = "Expecting '=' "; if (contextString) errormsg.append(contextString); errormsg << " but found ; instead"; --tokIt; throw NxsException(errormsg, *tokIt); } if (!tokIt->Equals("=")) { errormsg = "Expecting '=' "; if (contextString) errormsg.append(contextString); errormsg << " but found " << tokIt->GetToken() << " instead"; throw NxsException(errormsg, *tokIt); } }
std::map<std::string, std::string> NxsToken::ParseAsSimpleKeyValuePairs(const ProcessedNxsCommand & tv, const char *cmdName) { std::map<std::string, std::string> kv; std::string key; ProcessedNxsCommand::const_iterator tvIt = tv.begin(); ProcessedNxsCommand::const_iterator prevIt; ProcessedNxsCommand::const_iterator endIt = tv.end(); while (tvIt != endIt) { key = tvIt->GetToken().c_str(); prevIt = tvIt++; if (tvIt == endIt || tvIt->GetToken() != "=") { NxsString m("Expecting = after "); m += key.c_str(); m += " in "; m += cmdName; m += " command."; if (tvIt == endIt) throw NxsException(m, prevIt->GetFilePosition(), prevIt->GetLineNumber(), prevIt->GetColumnNumber()); else throw NxsException(m, tvIt->GetFilePosition(), tvIt->GetLineNumber(), tvIt->GetColumnNumber()); } prevIt = tvIt++; if (tvIt == endIt) { NxsString m("Expecting a value after = in the "); m += key.c_str(); m += " subcommand of the in "; m += cmdName; m += " command."; throw NxsException(m, prevIt->GetFilePosition(), prevIt->GetLineNumber(), prevIt->GetColumnNumber()); } kv[key] = tvIt->GetToken(); tvIt++; } return kv; }