Refactoring to reuse term parsing code.
This commit is contained in:
parent
89f3eb0306
commit
7de9980c10
@ -3,9 +3,7 @@
|
|||||||
#include <pddl/AST.h>
|
#include <pddl/AST.h>
|
||||||
#include <pddl/Exception.h>
|
#include <pddl/Exception.h>
|
||||||
#include <pddl/detail/SignatureMatching.h>
|
#include <pddl/detail/SignatureMatching.h>
|
||||||
#include <pddl/detail/parsing/Constant.h>
|
#include <pddl/detail/parsing/Term.h>
|
||||||
#include <pddl/detail/parsing/Variable.h>
|
|
||||||
#include <pddl/detail/parsing/VariableDeclaration.h>
|
|
||||||
|
|
||||||
namespace pddl
|
namespace pddl
|
||||||
{
|
{
|
||||||
@ -39,29 +37,17 @@ std::experimental::optional<ast::PredicatePointer> parsePredicate(Context &conte
|
|||||||
// Parse arguments
|
// Parse arguments
|
||||||
while (tokenizer.currentCharacter() != ')')
|
while (tokenizer.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
// Parse argument if it is a variable
|
auto term = parseTerm(context, astContext, variableStack);
|
||||||
auto variable = testParsingVariable(context, variableStack);
|
|
||||||
|
|
||||||
if (variable)
|
if (term)
|
||||||
{
|
{
|
||||||
arguments.emplace_back(std::move(variable.value()));
|
arguments.emplace_back(std::move(term.value()));
|
||||||
|
|
||||||
tokenizer.skipWhiteSpace();
|
tokenizer.skipWhiteSpace();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse argument if it is a constant
|
// If the term couldn’t be parsed, this is not a valid predicate
|
||||||
auto constant = testParsingConstant(context, astContext);
|
|
||||||
|
|
||||||
if (constant)
|
|
||||||
{
|
|
||||||
arguments.emplace_back(std::move(constant.value()));
|
|
||||||
|
|
||||||
tokenizer.skipWhiteSpace();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If argument is neither variable nor constant, this is not a valid predicate
|
|
||||||
tokenizer.seek(previousPosition);
|
tokenizer.seek(previousPosition);
|
||||||
return std::experimental::nullopt;
|
return std::experimental::nullopt;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user