void NxsTaxaAssociationBlock::HandleTaxaCommand( NxsToken &token) { if (!this->nexusReader) { NxsNCLAPIException("No NxsReader when reading TaxaAssociation block."); } token.GetNextToken(); this->firstTaxaBlock = this->ProcessTaxaBlockName(token.GetTokenReference(), token); token.GetNextToken(); if (!token.Equals(",")) { errormsg << "Expecting comma in the TAXA command, found \"" << token.GetTokenReference() << "\"."; throw NxsException(errormsg, token); } token.GetNextToken(); this->secondTaxaBlock = this->ProcessTaxaBlockName(token.GetTokenReference(), token); NxsToken::DemandEndSemicolon(token, this->errormsg, "TAXA"); }
void NxsBlock::SkipCommand(NxsToken & token) { if (nexusReader) { errormsg = "Skipping command: "; errormsg << token.GetTokenReference(); nexusReader->NexusWarnToken(errormsg, NxsReader::SKIPPING_CONTENT_WARNING, token); errormsg.clear(); } if (!token.Equals(";")) SkippingCommand(token.GetToken()); if (storeSkippedCommands) { ProcessedNxsCommand pnc; token.ProcessAsCommand(&pnc); skippedCommands.push_back(pnc); } else token.ProcessAsCommand(NULL); }
/*! used internally to do most of the work of Execute() */ void NxsReader::CoreExecutionTasks( NxsToken &token, /* the token object used to grab NxsReader tokens */ bool notifyStartStop) /* if true, ExecuteStarting and ExecuteStopping will be called */ { unsigned numSigInts = NxsReader::getNumSignalIntsCaught(); const bool checkingSignals = NxsReader::getNCLCatchesSignals(); lastExecuteBlocksInOrder.clear(); currBlock = NULL; NxsString errormsg; token.SetEOFAllowed(true); try { token.SetLabileFlagBit(NxsToken::saveCommandComments); token.GetNextToken(); } catch (NxsException x) { NexusError(token.errormsg, 0, 0, 0); return; } if (token.Equals("#NEXUS")) { token.SetLabileFlagBit(NxsToken::saveCommandComments); token.GetNextToken(); } else { errormsg = "Expecting #NEXUS to be the first token in the file, but found "; errormsg += token.GetToken(); errormsg += " instead"; /*mth changed this to a warning instead of an error because of the large number of files that violate this requirement. */ NexusWarn(errormsg, NxsReader::AMBIGUOUS_CONTENT_WARNING, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } if (notifyStartStop) { ExecuteStarting(); } bool keepReading = true; for (; keepReading && !token.AtEOF(); ) { if (checkingSignals && NxsReader::getNumSignalIntsCaught() != numSigInts) { throw NxsSignalCanceledParseException("Reading NEXUS content"); } if (token.Equals("BEGIN")) { token.SetEOFAllowed(false); /*must exit the block before and EOF*/ token.GetNextToken(); token.SetBlockName(token.GetTokenReference().c_str()); for (currBlock = blockList; currBlock != NULL; currBlock = currBlock->next) { if (currBlock->CanReadBlockType(token)) { break; } } NxsString currBlockName = token.GetToken(); currBlockName.ToUpper(); NxsBlockFactory * sourceOfBlock = NULL; if (currBlock == NULL) { try { currBlock = CreateBlockFromFactories(currBlockName, token, &sourceOfBlock); } catch (NxsException x) { NexusError(x.msg, x.pos, x.line, x.col); token.SetBlockName(0L); token.SetEOFAllowed(true); return; } } if (currBlock == NULL) { SkippingBlock(currBlockName); if (!ReadUntilEndblock(token, currBlockName)) { token.SetBlockName(0L); token.SetEOFAllowed(true); return; } } else if (currBlock->IsEnabled()) { keepReading = ExecuteBlock(token, currBlockName, currBlock, sourceOfBlock); } else { SkippingDisabledBlock(token.GetToken()); if (sourceOfBlock) { sourceOfBlock->BlockSkipped(currBlock); } if (!ReadUntilEndblock(token, currBlockName)) { token.SetBlockName(0L); token.SetEOFAllowed(true); return; } } currBlock = NULL; token.SetEOFAllowed(true); token.SetBlockName(0L); } // if (token.Equals("BEGIN")) else if (token.Equals("&SHOWALL")) { for (NxsBlock* showBlock = blockList; showBlock != NULL; showBlock = showBlock->next) { DebugReportBlock(*showBlock); } } else if (token.Equals("&LEAVE")) { break; } if (keepReading) { token.SetLabileFlagBit(NxsToken::saveCommandComments); token.GetNextToken(); } } if (notifyStartStop) { ExecuteStopping(); } currBlock = NULL; }
void NxsTaxaAssociationBlock::HandleAssociatesCommand( NxsToken &token) { if (this->firstTaxaBlock == 0L || this->secondTaxaBlock == 0L) { errormsg << "Expecting TAXA command to precede an ASSOCIATES command."; throw NxsException(errormsg, token); } token.GetNextToken(); for (;; ) { std::set<unsigned> fSet; while (!token.IsPunctuationToken() || !(token.Equals(";") || token.Equals(",") || token.Equals("/"))) { try { this->firstTaxaBlock->GetIndicesForLabel(token.GetTokenReference(), &fSet); } catch(...) { errormsg << "Unrecognized taxon \"" << token.GetTokenReference() << "\" in ASSOCIATES command"; throw NxsException(errormsg, token); } token.GetNextToken(); } if (!token.Equals("/")) { errormsg << "Expecting / in ASSOCIATES command, found \"" << token.GetTokenReference() << "\""; throw NxsException(errormsg, token); } if (fSet.empty()) { errormsg << "Expecting taxon labels from the first TAXA block before the / in ASSOCIATES command."; throw NxsException(errormsg, token); } token.GetNextToken(); std::set<unsigned> sSet; while (!token.IsPunctuationToken() || !(token.Equals(";") || token.Equals(",") || token.Equals("/"))) { try { this->secondTaxaBlock->GetIndicesForLabel(token.GetTokenReference(), &sSet); } catch(...) { errormsg << "Unrecognized taxon \"" << token.GetTokenReference() << "\" in ASSOCIATES command"; throw NxsException(errormsg, token); } token.GetNextToken(); } if (!(token.Equals(";") || token.Equals(","))) { errormsg << "Expecting , or ; in ASSOCIATES command, found \"" << token.GetTokenReference() << "\""; throw NxsException(errormsg, token); } if (sSet.empty()) { errormsg << "Expecting taxon labels from the second TAXA block after the / in ASSOCIATES command."; throw NxsException(errormsg, token); } for (std::set<unsigned>::const_iterator fIt = fSet.begin(); fIt != fSet.end(); ++fIt) { this->AddAssociation(*fIt, sSet); } if (token.Equals(";")) { break; } token.GetNextToken(); } }