Put parsing of typed variables into Variables class.
This commit is contained in:
parent
79773ba634
commit
0a4541a401
@ -27,7 +27,8 @@ using Variables = std::vector<Variable>;
|
||||
class Variable
|
||||
{
|
||||
public:
|
||||
static Variable parse(utils::Parser &parser, Context &context);
|
||||
static Variable parse(utils::Parser &parser);
|
||||
static void parseTyped(utils::Parser &parser, Context &context, std::vector<Variable> &variables);
|
||||
|
||||
public:
|
||||
const std::string &name() const;
|
||||
|
@ -39,31 +39,7 @@ Predicate &Predicate::parseDeclaration(utils::Parser &parser, Context &context)
|
||||
|
||||
// Parse arguments
|
||||
while (parser.currentCharacter() != ')')
|
||||
{
|
||||
predicate->m_arguments.emplace_back(Variable::parse(parser, context));
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
// Check if the variable has a type declaration
|
||||
if (!parser.advanceIf('-'))
|
||||
continue;
|
||||
|
||||
// Parse argument type
|
||||
const auto type = parseType(parser, context);
|
||||
|
||||
// Set the argument type for all previously flagged arguments
|
||||
std::for_each(predicate->m_arguments.begin(), predicate->m_arguments.end(),
|
||||
[&](auto &argument)
|
||||
{
|
||||
if (!argument.isDirty())
|
||||
return;
|
||||
|
||||
argument.setType(type);
|
||||
argument.setDirty(false);
|
||||
});
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
}
|
||||
Variable::parseTyped(parser, context, predicate->m_arguments);
|
||||
|
||||
parser.expect<std::string>(")");
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <plasp/pddl/Context.h>
|
||||
#include <plasp/pddl/Identifier.h>
|
||||
#include <plasp/pddl/Type.h>
|
||||
|
||||
namespace plasp
|
||||
{
|
||||
@ -24,7 +25,7 @@ Variable::Variable(std::string name)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Variable Variable::parse(utils::Parser &parser, Context &context)
|
||||
Variable Variable::parse(utils::Parser &parser)
|
||||
{
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
@ -40,6 +41,34 @@ Variable Variable::parse(utils::Parser &parser, Context &context)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Variable::parseTyped(utils::Parser &parser, Context &context, std::vector<Variable> &variables)
|
||||
{
|
||||
// Parse and store variable itself
|
||||
variables.emplace_back(parse(parser));
|
||||
|
||||
parser.skipWhiteSpace();
|
||||
|
||||
// Check if the variable has a type declaration
|
||||
if (!parser.advanceIf('-'))
|
||||
return;
|
||||
|
||||
// Parse argument type
|
||||
const auto type = parseType(parser, context);
|
||||
|
||||
// Set the argument type for all previously flagged arguments
|
||||
std::for_each(variables.begin(), variables.end(),
|
||||
[&](auto &variable)
|
||||
{
|
||||
if (!variable.isDirty())
|
||||
return;
|
||||
|
||||
variable.setType(type);
|
||||
variable.setDirty(false);
|
||||
});
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void Variable::setDirty(bool isDirty)
|
||||
{
|
||||
m_isDirty = isDirty;
|
||||
|
Reference in New Issue
Block a user