mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-19 15:52:53 +00:00
Improve raw templater error cases
This commit is contained in:
parent
28636cc4fe
commit
b3dbf4a104
@ -173,8 +173,8 @@ namespace templating
|
||||
m_skip_pass(false),
|
||||
m_write_output_to_file(false)
|
||||
{
|
||||
fs::path filenamePath(m_filename);
|
||||
m_default_output_file = (m_output_directory / filenamePath.replace_extension()).string();
|
||||
const fs::path filenamePath(m_filename);
|
||||
m_default_output_file = (m_output_directory / filenamePath.filename().replace_extension()).string();
|
||||
}
|
||||
|
||||
bool RunNextPass(std::ostream* buildLogFile)
|
||||
@ -217,6 +217,12 @@ namespace templating
|
||||
|
||||
if (!m_write_output_to_file)
|
||||
{
|
||||
if (!m_active_variations.empty())
|
||||
{
|
||||
std::cerr << "Template with variations must specify a filename\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!OpenOutputStream())
|
||||
return false;
|
||||
|
||||
@ -227,7 +233,7 @@ namespace templating
|
||||
|
||||
std::cout << "Templated file \"" << m_output_file << "\"\n";
|
||||
|
||||
if(buildLogFile)
|
||||
if (buildLogFile)
|
||||
*buildLogFile << "Templated file \"" << m_output_file << "\"\n";
|
||||
|
||||
m_first_line = true;
|
||||
@ -266,13 +272,22 @@ namespace templating
|
||||
{
|
||||
const auto existingVariation = m_active_variations_by_name.find(switchName);
|
||||
if (existingVariation != m_active_variations_by_name.end())
|
||||
return existingVariation->second->GetVariationType() == TemplatingVariationType::SWITCH;
|
||||
{
|
||||
const auto isValidRedefinition = existingVariation->second->GetVariationType() == TemplatingVariationType::SWITCH;
|
||||
|
||||
if (!isValidRedefinition)
|
||||
std::cerr << "Redefinition of \"" << switchName << "\" as switch is invalid\n";
|
||||
|
||||
return isValidRedefinition;
|
||||
}
|
||||
|
||||
auto switchVariation = std::make_unique<SwitchVariation>(std::move(switchName));
|
||||
if (m_current_pass.m_defines_proxy)
|
||||
switchVariation->Apply(m_current_pass.m_defines_proxy.get());
|
||||
|
||||
m_active_variations_by_name.emplace(switchVariation->m_name, switchVariation.get());
|
||||
m_active_variations.emplace_back(std::move(switchVariation));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -280,13 +295,22 @@ namespace templating
|
||||
{
|
||||
const auto existingVariation = m_active_variations_by_name.find(optionsName);
|
||||
if (existingVariation != m_active_variations_by_name.end())
|
||||
return existingVariation->second->GetVariationType() == TemplatingVariationType::SWITCH;
|
||||
{
|
||||
const auto isValidRedefinition = existingVariation->second->GetVariationType() == TemplatingVariationType::OPTIONS;
|
||||
|
||||
if (!isValidRedefinition)
|
||||
std::cerr << "Redefinition of \"" << optionsName << "\" as options is invalid\n";
|
||||
|
||||
return isValidRedefinition;
|
||||
}
|
||||
|
||||
auto optionsVariation = std::make_unique<OptionsVariation>(std::move(optionsName), std::move(optionValues));
|
||||
if (m_current_pass.m_defines_proxy)
|
||||
optionsVariation->Apply(m_current_pass.m_defines_proxy.get());
|
||||
|
||||
m_active_variations_by_name.emplace(optionsVariation->m_name, optionsVariation.get());
|
||||
m_active_variations.emplace_back(std::move(optionsVariation));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,10 @@ bool TemplatingStreamProxy::MatchSwitchDirective(const ParserLine& line, const u
|
||||
throw ParsingException(CreatePos(line, currentPosition), "Invalid switch directive.");
|
||||
|
||||
auto name = line.m_line.substr(nameStartPosition, currentPosition - nameStartPosition);
|
||||
|
||||
m_templater_control->AddSwitch(std::move(name));
|
||||
|
||||
if (!m_templater_control->AddSwitch(std::move(name)))
|
||||
throw ParsingException(TokenPos(*line.m_filename, line.m_line_number, 1), "switch directive failed");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -79,13 +81,15 @@ bool TemplatingStreamProxy::MatchOptionsDirective(const ParserLine& line, const
|
||||
const auto optionStartPosition = currentPosition;
|
||||
if (!ExtractIdentifier(line, currentPosition))
|
||||
throw ParsingException(CreatePos(line, currentPosition), "Invalid options directive.");
|
||||
|
||||
|
||||
options.emplace_back(line.m_line.substr(optionStartPosition, currentPosition - optionStartPosition));
|
||||
|
||||
firstArg = false;
|
||||
}
|
||||
|
||||
m_templater_control->AddOptions(std::move(name), std::move(options));
|
||||
if (!m_templater_control->AddOptions(std::move(name), std::move(options)))
|
||||
throw ParsingException(TokenPos(*line.m_filename, line.m_line_number, 1), "options directive failed");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -117,8 +121,10 @@ bool TemplatingStreamProxy::MatchFilenameDirective(const ParserLine& line, const
|
||||
|
||||
if (value.m_type != SimpleExpressionValue::Type::STRING)
|
||||
throw ParsingException(CreatePos(line, currentPosition), "pragma filename expression must evaluate to string");
|
||||
|
||||
m_templater_control->SetFileName(*value.m_string_value);
|
||||
|
||||
if (!m_templater_control->SetFileName(*value.m_string_value))
|
||||
throw ParsingException(TokenPos(*line.m_filename, line.m_line_number, 1), "filename directive failed");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user