UINT Lexer::expectUInt( UINT & value, UINT min, UINT max ) { Token token; lex.ExpectTokenType( TT_NUMBER, TT_INTEGER, &token ); INT value = token.GetIntValue(); if( value < 0 ) { dxWarnf("File '%s', line '%d': expected a positive integer value but got '%s'.\n", lex.GetFileName(),lex.GetLineNum(),token.ToChars()); } if( value < min || value > max ) { lex.Error("expected a positive integer value in range [%u,%u] but got '%s'.\n" ,min,max,token.ToChars()); } return (UINT)value; }
FLOAT Lexer::expectFloat( FLOAT & value, FLOAT min, FLOAT max ) { Token token; lex.ExpectTokenType( TT_NUMBER, TT_FLOAT, &token ); FLOAT f = token.GetFloatValue(); if( f < min || f > max ) { lex.Error("expected a floating-point value in range [%f,%f] but got '%s'.\n" ,min,max,token.ToChars()); } return f; }
INT Lexer::expectInt( INT & value, INT min, INT max ) { Token token; lex.ExpectTokenType( TT_NUMBER, TT_INTEGER, &token ); INT value = token.GetIntValue(); if( value < min || value > max ) { lex.Error("expected an integer value in range [%u,%u] but got '%s'.\n" ,min,max,token.ToChars()); } return value; }
BOOL Lexer::expectBool( bool & value ) { Token token; lex.ReadToken( &token ); if( token.equals( "TRUE" ) ) { return TRUE; } if( token.equals( "FALSE" ) ) { return FALSE; } lex.Error( "Expected boolean, but got '%s'.\n",token.ToChars()); return FALSE; }