Example #1
0
/**
 * @method Read [void:protected]
 * @param token [NexusToken&] the token used to read from in
 * @throws XNexus
 *
 * This function provides the ability to read everything following
 * the block name (which is read by the Nexus 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 AssumptionsBlock::Read( NexusToken& token )
{
   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 XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
	}

	for(;;)
	{
		token.GetNextToken();

		if( token.Equals("EXSET") ) {
			HandleExset( token );
		}
		else if( token.Equals("TAXSET") ) {
			HandleTaxset( token );
		}
		else if( token.Equals("CHARSET") ) {
			HandleCharset( token );
		}
		else 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 XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }
		}
   }
}
Example #2
0
/**
 * @method Read [void:protected]
 * @param token [NexusToken&] the token used to read from in
 * @throws XNexus
 *
 * This function provides the ability to read everything following the block name
 * (which is read by the Nexus 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 TaxaBlock::Read( NexusToken& token )
{
   isEmpty = false;
	token.GetNextToken(); // this should be the semicolon after the block name
	if( !token.Equals(";") ) {
		errormsg = "Expecting ';' after TAXA block name, but found ";
      errormsg += token.GetToken();
      errormsg += " instead";
		throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
	}

	for(;;)
	{
		token.GetNextToken();
		
		if( token.Equals("DIMENSIONS") ) {
			token.GetNextToken(); // this should be the NTAX keyword
			if( !token.Equals("NTAX") ) {
				errormsg = "Expecting NTAX keyword, but found ";
            errormsg += token.GetToken();
            errormsg += " instead";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
			}

			token.GetNextToken(); // this should be the equals sign
         if( !token.Equals("=") ) {
				errormsg = "Expecting '=', but found ";
            errormsg += token.GetToken();
            errormsg += " instead";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }

			token.GetNextToken(); // this should be the number of taxa
         ntax = atoi( token.GetToken().c_str() );
         if( ntax <= 0 ) {
				errormsg = "NTAX should be greater than zero (";
            errormsg += token.GetToken();
            errormsg += " was specified)";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }

			token.GetNextToken(); // this should be the terminating semicolon
         if( !token.Equals(";") ) {
				errormsg = "Expecting ';' to terminate DIMENSIONS command, but found ";
            errormsg += token.GetToken();
            errormsg += " instead";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }
		}
		else if( token.Equals("TAXLABELS") ) {
      	if( ntax <= 0 ) {
				errormsg = "NTAX must be specified before TAXLABELS command";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }

         for( int i = 0; i < ntax; i++ ) {
				token.GetNextToken();
            taxonLabels.push_back( token.GetToken() );
         }

			token.GetNextToken(); // this should be terminating semicolon
         if( !token.Equals(";") ) {
				errormsg = "Expecting ';' to terminate TAXLABELS command, but found ";
            errormsg += token.GetToken();
            errormsg += " instead";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }
		}
		else if( token.Equals("END") ) {
			// get the semicolon following END
			token.GetNextToken();
         if( !token.Equals(";") ) {
				errormsg = "Expecting ';' to terminate the END command, but found ";
            errormsg += token.GetToken();
            errormsg += " instead";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }
			break;
		}
		else if( token.Equals("ENDBLOCK") ) {
			// get the semicolon following ENDBLOCK
			token.GetNextToken();
         if( !token.Equals(";") ) {
				errormsg = "Expecting ';' to terminate the ENDBLOCK command, but found ";
            errormsg += token.GetToken();
            errormsg += " instead";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }
			break;
		}
		else {
      	SkippingCommand( token.GetToken() );
         do {
            token.GetNextToken();
         } while( !token.AtEOF() && !token.Equals(";") );
         if( token.AtEOF() ) {
				errormsg = "Unexpected end of file encountered";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }
		}
	}
}
Example #3
0
/**
 * @method Execute [void:public]
 * @param token [NexusToken&] the token object used to grab Nexus tokens
 * @param notifyStartStop [bool] if true, ExecuteStarting and ExecuteStopping will be called (true by default)
 *
 * Reads the Nexus data file from the input stream provided by token.  This function
 * is responsible for reading through the name of a each block.  Once
 * it has read a block name, it searches blockList for a block object
 * to handle reading the remainder of the block's contents. The block
 * object is responsible for reading the end or endblock command as well
 * as the trailing semicolon.  This function also handles reading
 * comments that are outside of blocks, as well as the initial #NEXUS
 * keyword.  The notifyStartStop argument is provided in case you do not
 * wish the ExecuteStart and ExecuteStop functions to be called.  These functions
 * are primarily used for creating and destroying a dialog box to show progress,
 * and nested Execute calls can thus cause problems (e.g., a dialog box is
 * destroyed when the inner Execute calls ExecuteStop and the outer Execute
 * still expects the dialog box to be available).  Specifying notifyStartStop
 * false for all the nested Execute calls thus allows the outermost Execute call
 * to control creation and destruction of the dialog box.
 */
void Nexus::Execute( NexusToken& token, bool notifyStartStop /* = true */ )
{
	char id_str[256];
	
	bool disabledBlock = false;
	nxsstring errormsg;


        
   try {
   	token.GetNextToken();
   }
   catch( XNexus x ) {
      NexusError( token.errormsg, 0, 0, 0 );
      return;
   }
   
	if( !token.Equals("#NEXUS") ) {
      errormsg = "Expecting #NEXUS to be the first token in the file, but found ";
      errormsg += token.GetToken();
      errormsg += " instead";
		NexusError( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
      return;
	}
	
	if( notifyStartStop )
		ExecuteStarting();
	
	for(;;)
	{
		token.SetLabileFlagBit( NexusToken::saveCommandComments );

		token.GetNextToken();
		
		if( token.AtEOF() )
			break;

		if( token.Equals("BEGIN") )
		{
			disabledBlock = false;
			token.GetNextToken();

			NexusBlock* curr;
			for( curr = blockList; curr != NULL; curr = curr->next )
			{
				if( !token.Equals( curr->GetID() ) )
					continue;

				if( !curr->IsEnabled() ) {
					disabledBlock = true;
					SkippingDisabledBlock( token.GetToken() );
					continue;
				}

				strcpy( id_str, curr->GetID().c_str() );
				EnteringBlock( id_str /*curr->GetID()*/ );
            curr->Reset();
				try {
					curr->Read( token );
				}
				catch( XNexus x ) {
					NexusError( curr->errormsg, x.pos, x.line, x.col );
	            curr->Reset();
               return;
				}
				ExitingBlock( id_str /*curr->GetID()*/ );
				break;
			}

			if( curr == NULL )
			{
				token.BlanksToUnderscores();
            nxsstring currBlock = token.GetToken();
				if( !disabledBlock ) 
					SkippingBlock( currBlock );
				for(;;)
				{
					token.GetNextToken();
					if( token.Equals("END") || token.Equals("ENDBLOCK") ) {
						token.GetNextToken();
						if( !token.Equals(";") ) {
							errormsg = "Expecting ';' after END or ENDBLOCK command, but found ";
                     errormsg += token.GetToken();
                     errormsg += " instead";
							NexusError( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
                     return;
						}
						break;
					}
					if( token.AtEOF() ) {
						errormsg = "Encountered end of file before END or ENDBLOCK in block ";
                  errormsg += currBlock;
						NexusError( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
                  return;
					}
				}
			} // if token not found amongst known block IDs
		} // if token equals BEGIN

		else if( token.Equals("&SHOWALL") ) {

			NexusBlock* curr;
			for( curr = blockList; curr != NULL; curr = curr->next )
			{
				DebugReportBlock(*curr);
			}

		}

		else if( token.Equals("&LEAVE") ) {
         break;
		}

	} // for(;;)
	
	if( notifyStartStop )
		ExecuteStopping();
}
Example #4
0
/**
 * @method Read [void:protected]
 * @param token [NexusToken&] the token used to read from in
 * @throws XNexus
 *
 * This function provides the ability to read everything following the block name
 * (which is read by the Nexus 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 DistancesBlock::Read( NexusToken& token )
{
   isEmpty = false;
	token.GetNextToken(); // this should be the semicolon after the block name
	if( !token.Equals(";") ) {
		errormsg = "Expecting ';' after ";
      errormsg += id;
      errormsg += " block name, but found ";
      errormsg += token.GetToken();
      errormsg += " instead";
		throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
	}

	for(;;)
	{
		token.GetNextToken();

		if( token.Equals("DIMENSIONS") ) {
         HandleDimensionsCommand( token );
		}
		else if( token.Equals("FORMAT") ) {
         HandleFormatCommand( token );
		}
		else if( token.Equals("TAXLABELS") ) {
         HandleTaxlabelsCommand( token );
		}
		else if( token.Equals("MATRIX") ) {
         HandleMatrixCommand( token );
		}
		else if( token.Equals("END") ) {
			// get the semicolon following END
			token.GetNextToken();
         if( !token.Equals(";") ) {
				errormsg = "Expecting ';' to terminate the END command, but found ";
            errormsg += token.GetToken();
            errormsg += " instead";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }
			break;
		}
		else if( token.Equals("ENDBLOCK") ) {
			// get the semicolon following ENDBLOCK
			token.GetNextToken();
         if( !token.Equals(";") ) {
				errormsg = "Expecting ';' to terminate the ENDBLOCK command, but found ";
            errormsg += token.GetToken();
            errormsg += " instead";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }
			break;
		}
		else {
      	SkippingCommand( token.GetToken() );
         do {
            token.GetNextToken();
         } while( !token.AtEOF() && !token.Equals(";") );
         if( token.AtEOF() ) {
				errormsg = "Unexpected end of file encountered";
				throw XNexus( errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn() );
         }
		}
	}
}