/*---------------------------------------------------------------------------------------------------------------------- | This function provides the ability to read everything following the block name (which is read by the NxsReader | object) to the END or ENDBLOCK statement. Characters are read from the input stream `in'. Overrides the pure | virtual function in the base class. */ void NxsEmptyBlock::Read( NxsToken &token) /* the token used to read from `in'*/ { isEmpty = false; // This should be the semicolon after the block name // token.GetNextToken(); if (!token.Equals(";")) { errormsg = "Expecting ';' after "; errormsg += id; errormsg += " block name, but found "; errormsg += token.GetToken(); errormsg += " instead"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } for(;;) { token.GetNextToken(); if (token.Equals("END")) { HandleEndblock(token); break; } else if(token.Equals("ENDBLOCK")) { HandleEndblock(token); break; } else { SkippingCommand(token.GetToken()); do { token.GetNextToken(); } while (!token.AtEOF() && !token.Equals(";")); if (token.AtEOF()) { errormsg = "Unexpected end of file encountered"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } } } }
/*---------------------------------------------------------------------------------------------------------------------- | This function provides the ability to read everything following the block name (which is read by the NxsReader | object) to the end or endblock statement. Characters are read from the input stream in. Overrides the abstract | virtual function in the base class. */ void NxsTaxaBlock::Read( NxsToken &token) /* the token used to read from in */ { ntax = 0; unsigned nominal_ntax = 0; isEmpty = false; isUserSupplied = true; DemandEndSemicolon(token, "BEGIN TAXA"); for (;;) { token.GetNextToken(); if (token.Equals("DIMENSIONS")) { // This should be the NTAX keyword // token.GetNextToken(); if (!token.Equals("NTAX")) { errormsg = "Expecting NTAX keyword, but found "; errormsg += token.GetToken(); errormsg += " instead"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } DemandEquals(token, "after NTAX"); nominal_ntax = DemandPositiveInt(token, "NTAX"); DemandEndSemicolon(token, "DIMENSIONS"); } // if (token.Equals("DIMENSIONS")) else if (token.Equals("TAXLABELS")) { if (nominal_ntax <= 0) { errormsg = "NTAX must be specified before TAXLABELS command"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } for (unsigned i = 0; i < nominal_ntax; i++) { token.GetNextToken(); //@pol should check to make sure this is not punctuation AddTaxonLabel(token.GetToken()); } DemandEndSemicolon(token, "TAXLABELS"); } // if (token.Equals("TAXLABELS")) else if (token.Equals("END") || token.Equals("ENDBLOCK")) { DemandEndSemicolon(token, "ENDBLOCK"); break; } // if (token.Equals("END") || token.Equals("ENDBLOCK")) else { SkippingCommand(token.GetToken()); do { token.GetNextToken(); } while (!token.AtEOF() && !token.Equals(";")); if (token.AtEOF()) { errormsg = "Unexpected end of file encountered"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } } // token not END, ENDBLOCK, TAXLABELS, or DIMENSIONS } // GetNextToken loop }
/*---------------------------------------------------------------------------------------------------------------------- | This function provides the ability to read everything following the block name (which is read by the NxsReader | object) to the END or ENDBLOCK statement. Characters are read from the input stream `in'. Overrides the virtual | function in the base class. */ void GarliReader::Read( NxsToken &token) /* the token used to read from `in' */ { isEmpty = false; // This should be the semicolon after the block name // token.GetNextToken(); if (!token.Equals(";")) { errormsg = "Expecting ';' after "; errormsg += id; errormsg += " block name, but found "; errormsg += token.GetToken(); errormsg += " instead"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } for (;;) { token.GetNextToken(); if (token.Abbreviation("ENdblock")) { HandleEndblock(token); break; } else if (token.Abbreviation("GarliReader")) { HandleGarliReader(token); } else if (token.Abbreviation("Help")) { HandleHelp(token); } else if (token.Abbreviation("Log")) { HandleLog(token); } else if (token.Abbreviation("EXecute")) { HandleExecute(token); } else if (token.Abbreviation("Show")) { HandleShow(token); } else if (token.Abbreviation("Quit")) { quit_now = true; message = "\nGarliReader says goodbye\n"; PrintMessage(); break; } else { SkippingCommand(token.GetToken()); do { token.GetNextToken(); } while (!token.AtEOF() && !token.Equals(";")); if (token.AtEOF()) { errormsg = "Unexpected end of file encountered"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } } } }
/*---------------------------------------------------------------------------------------------------------------------- | This function provides the ability to read everything following the block name (which is read by the NxsReader | object) to the end or endblock statement. Characters are read from the input stream in. Overrides the abstract | virtual function in the base class. */ void NxsTaxaBlock::Read( NxsToken &token) /* the token used to read from in */ { ntax = 0; int nominal_ntax = 0; isEmpty = false; isUserSupplied = true; // This should be the semicolon after the block name // token.GetNextToken(); if (!token.Equals(";")) { errormsg = "Expecting ';' after TAXA block name, but found "; errormsg += token.GetToken(); errormsg += " instead"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } for (;;) { token.GetNextToken(); if (token.Equals("DIMENSIONS")) { // This should be the NTAX keyword // token.GetNextToken(); if (!token.Equals("NTAX")) { errormsg = "Expecting NTAX keyword, but found "; errormsg += token.GetToken(); errormsg += " instead"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } // This should be the equals sign // token.GetNextToken(); if (!token.Equals("=")) { errormsg = "Expecting '=', but found "; errormsg += token.GetToken(); errormsg += " instead"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } // This should be the number of taxa // token.GetNextToken(); nominal_ntax = atoi(token.GetToken().c_str()); if (nominal_ntax <= 0) { errormsg = "NTAX should be greater than zero ("; errormsg += token.GetToken(); errormsg += " was specified)"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } // This should be the terminating semicolon // token.GetNextToken(); if (!token.Equals(";")) { errormsg = "Expecting ';' to terminate DIMENSIONS command, but found "; errormsg += token.GetToken(); errormsg += " instead"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } } // if (token.Equals("DIMENSIONS")) else if (token.Equals("TAXLABELS")) { if (nominal_ntax <= 0) { errormsg = "NTAX must be specified before TAXLABELS command"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } for (unsigned i = 0; (int)i < nominal_ntax; i++) { token.SetLabileFlagBit(NxsToken::hyphenNotPunctuation + NxsToken::preserveUnderscores); token.GetNextToken(); //@pol should check to make sure this is not punctuation AddTaxonLabel(token.GetToken()); } // This should be terminating semicolon // token.GetNextToken(); if (!token.Equals(";")) { errormsg = "Expecting ';' to terminate TAXLABELS command, but found "; errormsg += token.GetToken(); errormsg += " instead"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } } // if (token.Equals("TAXLABELS")) else if (token.Equals("END") || token.Equals("ENDBLOCK")) { // Get the semicolon following END // token.GetNextToken(); if (!token.Equals(";")) { errormsg = "Expecting ';' to terminate the ENDBLOCK command, but found "; errormsg += token.GetToken(); errormsg += " instead"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } break; } // if (token.Equals("END") || token.Equals("ENDBLOCK")) else { SkippingCommand(token.GetToken()); do { token.GetNextToken(); } while (!token.AtEOF() && !token.Equals(";")); if (token.AtEOF()) { errormsg = "Unexpected end of file encountered"; throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } } // token not END, ENDBLOCK, TAXLABELS, or DIMENSIONS } // GetNextToken loop }