MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / NextToken

Method NextToken

neo/d3xp/script/Script_Compiler.cpp:668–765  ·  view source on GitHub ↗

============== idCompiler::NextToken Sets token, immediateType, and possibly immediate ============== */

Source from the content-addressed store, hash-verified

666==============
667*/
668void idCompiler::NextToken( void ) {
669 int i;
670
671 // reset our type
672 immediateType = NULL;
673 memset( &immediate, 0, sizeof( immediate ) );
674
675 // Save the token's line number and filename since when we emit opcodes the current
676 // token is always the next one to be read
677 currentLineNumber = token.line;
678 currentFileNumber = gameLocal.program.GetFilenum( parserPtr->GetFileName() );
679
680 if ( !parserPtr->ReadToken( &token ) ) {
681 eof = true;
682 return;
683 }
684
685 if ( currentFileNumber != gameLocal.program.GetFilenum( parserPtr->GetFileName() ) ) {
686 if ( ( braceDepth > 0 ) && ( token != "}" ) ) {
687 // missing a closing brace. try to give as much info as possible.
688 if ( scope->Type() == ev_function ) {
689 Error( "Unexpected end of file inside function '%s'. Missing closing braces.", scope->Name() );
690 } else if ( scope->Type() == ev_object ) {
691 Error( "Unexpected end of file inside object '%s'. Missing closing braces.", scope->Name() );
692 } else if ( scope->Type() == ev_namespace ) {
693 Error( "Unexpected end of file inside namespace '%s'. Missing closing braces.", scope->Name() );
694 } else {
695 Error( "Unexpected end of file inside braced section" );
696 }
697 }
698 }
699
700 switch( token.type ) {
701 case TT_STRING:
702 // handle quoted strings as a unit
703 immediateType = &type_string;
704 return;
705
706 case TT_LITERAL: {
707 // handle quoted vectors as a unit
708 immediateType = &type_vector;
709 idLexer lex( token, token.Length(), parserPtr->GetFileName(), LEXFL_NOERRORS );
710 idToken token2;
711 for( i = 0; i < 3; i++ ) {
712 if ( !lex.ReadToken( &token2 ) ) {
713 Error( "Couldn't read vector. '%s' is not in the form of 'x y z'", token.c_str() );
714 }
715 if ( token2.type == TT_PUNCTUATION && token2 == "-" ) {
716 if ( !lex.CheckTokenType( TT_NUMBER, 0, &token2 ) ) {
717 Error( "expected a number following '-' but found '%s' in vector '%s'", token2.c_str(), token.c_str() );
718 }
719 immediate.vector[ i ] = -token2.GetFloatValue();
720 } else if ( token2.type == TT_NUMBER ) {
721 immediate.vector[ i ] = token2.GetFloatValue();
722 } else {
723 Error( "vector '%s' is not in the form of 'x y z'. expected float value, found '%s'", token.c_str(), token2.c_str() );
724 }
725 }

Callers

nothing calls this directly

Calls 10

GetFloatValueMethod · 0.80
ErrorFunction · 0.50
GetFilenumMethod · 0.45
GetFileNameMethod · 0.45
ReadTokenMethod · 0.45
TypeMethod · 0.45
NameMethod · 0.45
LengthMethod · 0.45
c_strMethod · 0.45
CheckTokenTypeMethod · 0.45

Tested by

no test coverage detected