Exemple #1
0
bool VdfParser::ProcessArrayDeclaration(Tokens& tokens, VariableSpace& variables)
{
    static map<TokenType, int> token_to_array_property{
        {TokenKeywordFloat, VariableFloatArray},
        {TokenKeywordInt, VariableIntArray},
        {TokenKeywordString, VariableStringArray},
        {TokenKeywordBool, VariableBoolArray},
		{TokenId, VariableStructArray},
    };

	tokens.AssertToken(TokenKeywordArray, true);
	tokens.AssertToken(TokenLessThan, true);

	auto type = tokens.GetCurrentToken().type;
	auto element_type_id = tokens.GetCurrentToken().text;
	auto fq_type_id = ResolveFqId(element_type_id.c_str(), true, tokens);

	assert(type == TokenKeywordFloat || type == TokenKeywordInt ||
		   type == TokenKeywordBool || type == TokenKeywordString ||
			type == TokenId);
	tokens.Next();
	tokens.AssertToken(TokenGreaterThan, true);

	auto id = (&variables == _variables.get()) ?
		GetFqId(tokens.GetId().c_str()) : tokens.GetId();

	if (!tokens.IsTokenOfType(TokenSharp, true))
	{
		variables.AddArray(fq_type_id.c_str(), id.c_str(), L"");
	}
	else
	{
		tokens.AssertToken(TokenLessThan, true);
		auto start_index = _wtoi(tokens.GetLiteralValue().c_str());
		tokens.AssertToken(TokenComma, true);
		auto end_index = _wtoi(tokens.GetLiteralValue().c_str());
		tokens.AssertToken(TokenGreaterThan, true);

		for (int i = start_index; i <= end_index; ++i)
		{
			wostringstream output;
			output << id << i;
			auto variable_id = (&variables == _variables.get()) ?
				GetFqId(output.str().c_str()) : output.str();
			variables.AddArray(fq_type_id.c_str(), variable_id.c_str(), L"");
		}
	}
	tokens.AssertToken(TokenSemiColon, true);

	return true;
}
Exemple #2
0
bool VdfParser::ProcessSimpleDeclaration(Tokens& tokens)
{
    assert(_variables);

	auto type = tokens.GetCurrentToken().type;
    auto type_id = tokens.GetCurrentToken().text;

	assert(type == TokenKeywordFloat || type == TokenKeywordInt ||
           type == TokenKeywordBool || type == TokenKeywordString ||
           type == TokenId);

	tokens.Next();
	auto id = tokens.GetId();
	auto fq_type_id = ResolveFqId(type_id.c_str(), true, tokens);

	if (!tokens.IsTokenOfType(TokenSharp, true))
	{
        _variables->Add(fq_type_id.c_str(), GetFqId(id.c_str()).c_str(), L"");
	}
	else
	{
		tokens.AssertToken(TokenLessThan, true);

		auto start_index = boost::lexical_cast<int>(tokens.GetLiteralValue());
		tokens.AssertToken(TokenComma, true);
		auto end_index = boost::lexical_cast<int>(tokens.GetLiteralValue());
		tokens.AssertToken(TokenGreaterThan, true);

		for (int i = start_index; i <= end_index; ++i)
		{
			wostringstream output;
			output << id << i;
			wstring variable_id = GetFqId(output.str().c_str());
			
            _variables->Add(fq_type_id.c_str(), variable_id.c_str(), L"");
		}
	}
	tokens.AssertToken(TokenSemiColon, true);

	return true;
}