Refactored predicate argument parsing.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@@ -29,6 +30,9 @@ class Parser
|
||||
template<typename Type>
|
||||
Type parse();
|
||||
|
||||
template<class CharacterCondition>
|
||||
void parseUntil(std::vector<std::string> &container, CharacterCondition characterCondition);
|
||||
|
||||
template<typename Type>
|
||||
void expect(const Type &expectedValue);
|
||||
|
||||
@@ -59,6 +63,38 @@ class Parser
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class CharacterCondition>
|
||||
void Parser::parseUntil(std::vector<std::string> &container, CharacterCondition characterCondition)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
skipWhiteSpace();
|
||||
|
||||
std::string value;
|
||||
|
||||
while (true)
|
||||
{
|
||||
const auto character = *m_position;
|
||||
|
||||
if (characterCondition(character))
|
||||
{
|
||||
container.emplace_back(std::move(value));
|
||||
return;
|
||||
}
|
||||
|
||||
if (std::isspace(character))
|
||||
break;
|
||||
|
||||
value.push_back(character);
|
||||
advance();
|
||||
}
|
||||
|
||||
container.emplace_back(std::move(value));
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user