Simplified Parser interface.
This commit is contained in:
@@ -28,10 +28,21 @@ Predicate Predicate::fromSAS(utils::Parser &parser)
|
||||
|
||||
predicate.m_name = parser.parse<std::string>();
|
||||
|
||||
parser.parseUntil(predicate.m_arguments, [](const auto character)
|
||||
{
|
||||
return character == '\n';
|
||||
});
|
||||
while (true)
|
||||
{
|
||||
// Parse arguments until reaching newline
|
||||
parser.skipWhiteSpace(
|
||||
[&](const auto character)
|
||||
{
|
||||
return character != '\n' && std::isspace(character);
|
||||
});
|
||||
|
||||
if (parser.currentCharacter() == '\n')
|
||||
break;
|
||||
|
||||
const auto value = parser.parse<std::string>();
|
||||
predicate.m_arguments.emplace_back(std::move(value));
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
|
@@ -54,6 +54,15 @@ size_t Parser::column() const
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Parser::CharacterType Parser::currentCharacter() const
|
||||
{
|
||||
checkStream();
|
||||
|
||||
return *m_position;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Parser::checkStream() const
|
||||
{
|
||||
if (m_position == EndOfFile)
|
||||
@@ -100,10 +109,11 @@ bool Parser::advanceIf(CharacterType expectedCharacter)
|
||||
|
||||
void Parser::skipWhiteSpace()
|
||||
{
|
||||
checkStream();
|
||||
|
||||
while (std::isspace(*m_position))
|
||||
advance();
|
||||
return skipWhiteSpace(
|
||||
[](const auto character)
|
||||
{
|
||||
return std::isspace(character);
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user