Removed now unnecessary Parser function arguments.
This commit is contained in:
parent
a776fc9e06
commit
813fecbf15
|
@ -21,7 +21,7 @@ namespace pddl
|
||||||
class Action
|
class Action
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Action &parseDeclaration(utils::Parser &parser, Context &context);
|
static Action &parseDeclaration(Context &context);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const std::string &name() const;
|
const std::string &name() const;
|
||||||
|
|
|
@ -75,13 +75,11 @@ class Expression
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parsePreconditionExpression(utils::Parser &parser, Context &context,
|
ExpressionPointer parsePreconditionExpression(Context &context,
|
||||||
const expressions::Variables ¶meters);
|
|
||||||
ExpressionPointer parseExpression(utils::Parser &parser, Context &context,
|
|
||||||
const expressions::Variables ¶meters);
|
const expressions::Variables ¶meters);
|
||||||
|
ExpressionPointer parseExpression(Context &context, const expressions::Variables ¶meters);
|
||||||
|
|
||||||
ExpressionPointer parseEffectExpression(utils::Parser &parser, Context &context,
|
ExpressionPointer parseEffectExpression(Context &context, const expressions::Variables ¶meters);
|
||||||
const expressions::Variables ¶meters);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/utils/Parser.h>
|
#include <plasp/pddl/Context.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
|
@ -49,7 +49,7 @@ class Requirement
|
||||||
ActionCosts
|
ActionCosts
|
||||||
};
|
};
|
||||||
|
|
||||||
static Requirement parse(utils::Parser &parser);
|
static Requirement parse(Context &context);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Requirement(Type type);
|
Requirement(Type type);
|
||||||
|
|
|
@ -20,8 +20,8 @@ class And: public NAry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
static AndPointer parse(utils::Parser &parser, Context &context,
|
static AndPointer parse(Context &context, const Variables ¶meters,
|
||||||
const Variables ¶meters, ExpressionParser parseExpression);
|
ExpressionParser parseExpression);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||||
|
@ -33,12 +33,12 @@ class And: public NAry
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
AndPointer And::parse(utils::Parser &parser, Context &context,
|
AndPointer And::parse(Context &context, const Variables ¶meters,
|
||||||
const Variables ¶meters, ExpressionParser parseExpression)
|
ExpressionParser parseExpression)
|
||||||
{
|
{
|
||||||
auto expression = std::make_unique<And>(And());
|
auto expression = std::make_unique<And>(And());
|
||||||
|
|
||||||
expression->NAry::parse(parser, context, parameters, parseExpression);
|
expression->NAry::parse(context, parameters, parseExpression);
|
||||||
|
|
||||||
if (expression->arguments().empty())
|
if (expression->arguments().empty())
|
||||||
throw ConsistencyException("\"and\" expressions should not be empty");
|
throw ConsistencyException("\"and\" expressions should not be empty");
|
||||||
|
|
|
@ -22,10 +22,10 @@ namespace expressions
|
||||||
class Constant: public Expression
|
class Constant: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static ConstantPointer parseDeclaration(utils::Parser &parser, Context &context);
|
static ConstantPointer parseDeclaration(Context &context);
|
||||||
static void parseTypedDeclaration(utils::Parser &parser, Context &context);
|
static void parseTypedDeclaration(Context &context);
|
||||||
|
|
||||||
static Constant *parseExisting(utils::Parser &parser, Context &context);
|
static Constant *parseExisting(Context &context);
|
||||||
|
|
||||||
// TODO: method for lazy creation if not existing
|
// TODO: method for lazy creation if not existing
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ class Either: public NAry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
static EitherPointer parse(utils::Parser &parser, Context &context,
|
static EitherPointer parse(Context &context, const Variables ¶meters,
|
||||||
const Variables ¶meters, ExpressionParser parseExpression);
|
ExpressionParser parseExpression);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||||
|
@ -33,12 +33,12 @@ class Either: public NAry
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
EitherPointer Either::parse(utils::Parser &parser, Context &context,
|
EitherPointer Either::parse(Context &context, const Variables ¶meters,
|
||||||
const Variables ¶meters, ExpressionParser parseExpression)
|
ExpressionParser parseExpression)
|
||||||
{
|
{
|
||||||
auto expression = std::make_unique<Either>(Either());
|
auto expression = std::make_unique<Either>(Either());
|
||||||
|
|
||||||
expression->NAry::parse(parser, context, parameters, parseExpression);
|
expression->NAry::parse(context, parameters, parseExpression);
|
||||||
|
|
||||||
if (expression->arguments().empty())
|
if (expression->arguments().empty())
|
||||||
throw ConsistencyException("\"and\" expressions should not be empty");
|
throw ConsistencyException("\"and\" expressions should not be empty");
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
#define __PLASP__PDDL__EXPRESSION__N_ARY_H
|
#define __PLASP__PDDL__EXPRESSION__N_ARY_H
|
||||||
|
|
||||||
#include <plasp/pddl/ConsistencyException.h>
|
#include <plasp/pddl/ConsistencyException.h>
|
||||||
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Expression.h>
|
#include <plasp/pddl/Expression.h>
|
||||||
#include <plasp/pddl/expressions/Variable.h>
|
#include <plasp/pddl/expressions/Variable.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
|
@ -26,8 +26,7 @@ class NAry: public Expression
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
void parse(utils::Parser &parser, Context &context, const Variables ¶meters,
|
void parse(Context &context, const Variables ¶meters, ExpressionParser parseExpression);
|
||||||
ExpressionParser parseExpression);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Expressions m_arguments;
|
Expressions m_arguments;
|
||||||
|
@ -36,18 +35,17 @@ class NAry: public Expression
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
void NAry::parse(utils::Parser &parser, Context &context,
|
void NAry::parse(Context &context, const Variables ¶meters, ExpressionParser parseExpression)
|
||||||
const Variables ¶meters, ExpressionParser parseExpression)
|
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
// Assume that expression identifier (and, or, etc.) is already parsed
|
// Assume that expression identifier (and, or, etc.) is already parsed
|
||||||
// Parse arguments of the expression
|
// Parse arguments of the expression
|
||||||
while (parser.currentCharacter() != ')')
|
while (context.parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
m_arguments.emplace_back(parseExpression(parser, context, parameters));
|
m_arguments.emplace_back(parseExpression(context, parameters));
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef __PLASP__PDDL__EXPRESSION__NOT_H
|
#ifndef __PLASP__PDDL__EXPRESSION__NOT_H
|
||||||
#define __PLASP__PDDL__EXPRESSION__NOT_H
|
#define __PLASP__PDDL__EXPRESSION__NOT_H
|
||||||
|
|
||||||
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Expression.h>
|
#include <plasp/pddl/Expression.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
|
@ -20,8 +21,8 @@ class Not: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
static NotPointer parse(utils::Parser &parser, Context &context,
|
static NotPointer parse(Context &context, const Variables ¶meters,
|
||||||
const Variables ¶meters, ExpressionParser parseExpression);
|
ExpressionParser parseExpression);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||||
|
@ -37,15 +38,15 @@ class Not: public Expression
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
NotPointer Not::parse(utils::Parser &parser, Context &context,
|
NotPointer Not::parse(Context &context, const Variables ¶meters,
|
||||||
const Variables ¶meters, ExpressionParser parseExpression)
|
ExpressionParser parseExpression)
|
||||||
{
|
{
|
||||||
auto expression = std::make_unique<Not>(Not());
|
auto expression = std::make_unique<Not>(Not());
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
// Parse argument
|
// Parse argument
|
||||||
expression->m_argument = parseExpression(parser, context, parameters);
|
expression->m_argument = parseExpression(context, parameters);
|
||||||
|
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ class Or: public NAry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
static OrPointer parse(utils::Parser &parser, Context &context,
|
static OrPointer parse(Context &context, const Variables ¶meters,
|
||||||
const Variables ¶meters, ExpressionParser parseExpression);
|
ExpressionParser parseExpression);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||||
|
@ -33,12 +33,11 @@ class Or: public NAry
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename ExpressionParser>
|
template<typename ExpressionParser>
|
||||||
OrPointer Or::parse(utils::Parser &parser, Context &context,
|
OrPointer Or::parse(Context &context, const Variables ¶meters, ExpressionParser parseExpression)
|
||||||
const Variables ¶meters, ExpressionParser parseExpression)
|
|
||||||
{
|
{
|
||||||
auto expression = std::make_unique<Or>(Or());
|
auto expression = std::make_unique<Or>(Or());
|
||||||
|
|
||||||
expression->NAry::parse(parser, context, parameters, parseExpression);
|
expression->NAry::parse(context, parameters, parseExpression);
|
||||||
|
|
||||||
if (expression->arguments().empty())
|
if (expression->arguments().empty())
|
||||||
throw ConsistencyException("\"or\" expressions should not be empty");
|
throw ConsistencyException("\"or\" expressions should not be empty");
|
||||||
|
|
|
@ -19,8 +19,8 @@ namespace expressions
|
||||||
class Predicate: public Expression
|
class Predicate: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static PredicatePointer parse(std::string name, utils::Parser &parser,
|
static PredicatePointer parse(std::string name, Context &context,
|
||||||
Context &context, const Variables ¶meters);
|
const Variables ¶meters);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace expressions
|
||||||
class PredicateDeclaration: public Expression
|
class PredicateDeclaration: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void parse(utils::Parser &parser, Context &context);
|
static void parse(Context &context);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <plasp/pddl/ConsistencyException.h>
|
#include <plasp/pddl/ConsistencyException.h>
|
||||||
#include <plasp/pddl/Expression.h>
|
#include <plasp/pddl/Expression.h>
|
||||||
#include <plasp/pddl/Identifier.h>
|
#include <plasp/pddl/Identifier.h>
|
||||||
#include <plasp/utils/Parser.h>
|
|
||||||
#include <plasp/utils/ParserException.h>
|
#include <plasp/utils/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
|
@ -23,12 +22,10 @@ namespace expressions
|
||||||
class PrimitiveType: public Expression
|
class PrimitiveType: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static PrimitiveType *parseDeclaration(utils::Parser &parser, Context &context);
|
static PrimitiveType *parseDeclaration(Context &context);
|
||||||
static void parseTypedDeclaration(utils::Parser &parser, Context &context);
|
static void parseTypedDeclaration(Context &context);
|
||||||
|
|
||||||
static PrimitiveType *parseExisting(utils::Parser &parser, Context &context);
|
static PrimitiveType *parseExisting(Context &context);
|
||||||
|
|
||||||
// TODO: method for lazy creation if not existing
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||||
|
|
|
@ -20,8 +20,7 @@ namespace expressions
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parseExistingPrimitiveType(utils::Parser &parser, Context &context,
|
ExpressionPointer parseExistingPrimitiveType(Context &context, const Variables ¶meters);
|
||||||
const Variables ¶meters);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,11 @@ namespace expressions
|
||||||
class Variable: public Expression
|
class Variable: public Expression
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static VariablePointer parseDeclaration(utils::Parser &parser);
|
static VariablePointer parseDeclaration(Context &context);
|
||||||
|
|
||||||
static void parseTypedDeclaration(utils::Parser &parser, Context &context,
|
static void parseTypedDeclaration(Context &context, Variables ¶meters);
|
||||||
Variables ¶meters);
|
|
||||||
|
|
||||||
static const Variable *parseExisting(utils::Parser &parser, const Variables &variables);
|
static const Variable *parseExisting(Context &context, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void accept(ExpressionVisitor &expressionVisitor) const override;
|
void accept(ExpressionVisitor &expressionVisitor) const override;
|
||||||
|
|
|
@ -25,39 +25,39 @@ Action::Action(std::string name)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Action &Action::parseDeclaration(utils::Parser &parser, Context &context)
|
Action &Action::parseDeclaration(Context &context)
|
||||||
{
|
{
|
||||||
const auto actionName = parser.parseIdentifier(isIdentifier);
|
const auto actionName = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
auto action = std::make_unique<Action>(Action(actionName));
|
auto action = std::make_unique<Action>(Action(actionName));
|
||||||
|
|
||||||
parser.expect<std::string>(":parameters");
|
context.parser.expect<std::string>(":parameters");
|
||||||
|
|
||||||
parser.expect<std::string>("(");
|
context.parser.expect<std::string>("(");
|
||||||
|
|
||||||
// Read parameters
|
// Read parameters
|
||||||
while (parser.currentCharacter() != ')')
|
while (context.parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
expressions::Variable::parseTypedDeclaration(parser, context, action->m_parameters);
|
expressions::Variable::parseTypedDeclaration(context, action->m_parameters);
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.expect<std::string>(")");
|
context.parser.expect<std::string>(")");
|
||||||
|
|
||||||
// Parse preconditions and effects
|
// Parse preconditions and effects
|
||||||
while (parser.currentCharacter() != ')')
|
while (context.parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
parser.expect<std::string>(":");
|
context.parser.expect<std::string>(":");
|
||||||
|
|
||||||
const auto sectionIdentifier = parser.parseIdentifier(isIdentifier);
|
const auto sectionIdentifier = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
if (sectionIdentifier == "precondition")
|
if (sectionIdentifier == "precondition")
|
||||||
action->m_precondition = parsePreconditionExpression(parser, context, action->m_parameters);
|
action->m_precondition = parsePreconditionExpression(context, action->m_parameters);
|
||||||
else if (sectionIdentifier == "effect")
|
else if (sectionIdentifier == "effect")
|
||||||
action->m_effect = parseEffectExpression(parser, context, action->m_parameters);
|
action->m_effect = parseEffectExpression(context, action->m_parameters);
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store new action
|
// Store new action
|
||||||
|
|
|
@ -162,7 +162,7 @@ void Domain::parseRequirementSection()
|
||||||
if (m_context.parser.currentCharacter() == ':')
|
if (m_context.parser.currentCharacter() == ':')
|
||||||
m_context.parser.advance();
|
m_context.parser.advance();
|
||||||
|
|
||||||
m_requirements.emplace_back(Requirement::parse(m_context.parser));
|
m_requirements.emplace_back(Requirement::parse(m_context));
|
||||||
|
|
||||||
m_context.parser.skipWhiteSpace();
|
m_context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ void Domain::parseTypeSection()
|
||||||
if (m_context.parser.currentCharacter() == '(')
|
if (m_context.parser.currentCharacter() == '(')
|
||||||
throw utils::ParserException(m_context.parser, "Only primitive types are allowed in type section");
|
throw utils::ParserException(m_context.parser, "Only primitive types are allowed in type section");
|
||||||
|
|
||||||
expressions::PrimitiveType::parseTypedDeclaration(m_context.parser, m_context);
|
expressions::PrimitiveType::parseTypedDeclaration(m_context);
|
||||||
|
|
||||||
m_context.parser.skipWhiteSpace();
|
m_context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
@ -259,7 +259,7 @@ void Domain::parseConstantSection()
|
||||||
// Store constants
|
// Store constants
|
||||||
while (m_context.parser.currentCharacter() != ')')
|
while (m_context.parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
expressions::Constant::parseTypedDeclaration(m_context.parser, m_context);
|
expressions::Constant::parseTypedDeclaration(m_context);
|
||||||
|
|
||||||
m_context.parser.skipWhiteSpace();
|
m_context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
@ -276,7 +276,7 @@ void Domain::parsePredicateSection()
|
||||||
// Store predicates and their arguments
|
// Store predicates and their arguments
|
||||||
while (m_context.parser.currentCharacter() != ')')
|
while (m_context.parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
expressions::PredicateDeclaration::parse(m_context.parser, m_context);
|
expressions::PredicateDeclaration::parse(m_context);
|
||||||
|
|
||||||
m_context.parser.skipWhiteSpace();
|
m_context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ void Domain::parseActionSection()
|
||||||
{
|
{
|
||||||
m_context.parser.skipWhiteSpace();
|
m_context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
Action::parseDeclaration(m_context.parser, m_context);
|
Action::parseDeclaration(m_context);
|
||||||
|
|
||||||
m_context.parser.expect<std::string>(")");
|
m_context.parser.expect<std::string>(")");
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,10 @@ namespace pddl
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier,
|
ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier,
|
||||||
utils::Parser &parser, Context &context, const expressions::Variables ¶meters);
|
Context &context, const expressions::Variables ¶meters);
|
||||||
ExpressionPointer parseEffectBodyExpressionContent(const std::string &expressionIdentifier,
|
ExpressionPointer parseEffectBodyExpressionContent(const std::string &expressionIdentifier,
|
||||||
utils::Parser &parser, Context &context, const expressions::Variables ¶meters);
|
Context &context, const expressions::Variables ¶meters);
|
||||||
ExpressionPointer parsePredicate(utils::Parser &parser, Context &context,
|
ExpressionPointer parsePredicate(Context &context, const expressions::Variables ¶meters);
|
||||||
const expressions::Variables ¶meters);
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -37,45 +36,44 @@ void throwUnsupported(const utils::Parser &parser, const std::string &expression
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parsePreconditionExpression(utils::Parser &parser, Context &context,
|
ExpressionPointer parsePreconditionExpression(Context &context,
|
||||||
const expressions::Variables ¶meters)
|
const expressions::Variables ¶meters)
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("(");
|
context.parser.expect<std::string>("(");
|
||||||
|
|
||||||
const auto expressionIdentifier = parser.parseIdentifier(isIdentifier);
|
const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
ExpressionPointer expression;
|
ExpressionPointer expression;
|
||||||
|
|
||||||
if (expressionIdentifier == "and")
|
if (expressionIdentifier == "and")
|
||||||
{
|
{
|
||||||
expression = expressions::And::parse(parser, context, parameters,
|
expression = expressions::And::parse(context, parameters,
|
||||||
parsePreconditionExpression);
|
parsePreconditionExpression);
|
||||||
}
|
}
|
||||||
else if (expressionIdentifier == "forall"
|
else if (expressionIdentifier == "forall"
|
||||||
|| expressionIdentifier == "preference")
|
|| expressionIdentifier == "preference")
|
||||||
{
|
{
|
||||||
throwUnsupported(parser, expressionIdentifier);
|
throwUnsupported(context.parser, expressionIdentifier);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
expression = parseExpressionContent(expressionIdentifier, parser, context, parameters);
|
expression = parseExpressionContent(expressionIdentifier, context, parameters);
|
||||||
|
|
||||||
parser.expect<std::string>(")");
|
context.parser.expect<std::string>(")");
|
||||||
|
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parseExpression(utils::Parser &parser, Context &context,
|
ExpressionPointer parseExpression(Context &context, const expressions::Variables ¶meters)
|
||||||
const expressions::Variables ¶meters)
|
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("(");
|
context.parser.expect<std::string>("(");
|
||||||
|
|
||||||
const auto expressionIdentifier = parser.parseIdentifier(isIdentifier);
|
const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
auto expression = parseExpressionContent(expressionIdentifier, parser, context, parameters);
|
auto expression = parseExpressionContent(expressionIdentifier, context, parameters);
|
||||||
|
|
||||||
parser.expect<std::string>(")");
|
context.parser.expect<std::string>(")");
|
||||||
|
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
@ -83,18 +81,18 @@ ExpressionPointer parseExpression(utils::Parser &parser, Context &context,
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier,
|
ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier,
|
||||||
utils::Parser &parser, Context &context, const expressions::Variables ¶meters)
|
Context &context, const expressions::Variables ¶meters)
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
ExpressionPointer expression;
|
ExpressionPointer expression;
|
||||||
|
|
||||||
if (expressionIdentifier == "and")
|
if (expressionIdentifier == "and")
|
||||||
expression = expressions::And::parse(parser, context, parameters, parseExpression);
|
expression = expressions::And::parse(context, parameters, parseExpression);
|
||||||
else if (expressionIdentifier == "or")
|
else if (expressionIdentifier == "or")
|
||||||
expression = expressions::Or::parse(parser, context, parameters, parseExpression);
|
expression = expressions::Or::parse(context, parameters, parseExpression);
|
||||||
else if (expressionIdentifier == "not")
|
else if (expressionIdentifier == "not")
|
||||||
expression = expressions::Not::parse(parser, context, parameters, parseExpression);
|
expression = expressions::Not::parse(context, parameters, parseExpression);
|
||||||
else if (expressionIdentifier == "imply"
|
else if (expressionIdentifier == "imply"
|
||||||
|| expressionIdentifier == "exists"
|
|| expressionIdentifier == "exists"
|
||||||
|| expressionIdentifier == "forall"
|
|| expressionIdentifier == "forall"
|
||||||
|
@ -110,7 +108,7 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier
|
||||||
|| expressionIdentifier == ">="
|
|| expressionIdentifier == ">="
|
||||||
|| expressionIdentifier == "<=")
|
|| expressionIdentifier == "<=")
|
||||||
{
|
{
|
||||||
throwUnsupported(parser, expressionIdentifier);
|
throwUnsupported(context.parser, expressionIdentifier);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -123,9 +121,9 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier
|
||||||
|
|
||||||
// If predicate exists, parse it
|
// If predicate exists, parse it
|
||||||
if (match != context.predicateDeclarations.cend())
|
if (match != context.predicateDeclarations.cend())
|
||||||
expression = expressions::Predicate::parse(expressionIdentifier, parser, context, parameters);
|
expression = expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
||||||
else
|
else
|
||||||
throw utils::ParserException(parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
||||||
}
|
}
|
||||||
|
|
||||||
return expression;
|
return expression;
|
||||||
|
@ -133,26 +131,25 @@ ExpressionPointer parseExpressionContent(const std::string &expressionIdentifier
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parseEffectExpression(utils::Parser &parser, Context &context,
|
ExpressionPointer parseEffectExpression(Context &context, const expressions::Variables ¶meters)
|
||||||
const expressions::Variables ¶meters)
|
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("(");
|
context.parser.expect<std::string>("(");
|
||||||
|
|
||||||
const auto expressionIdentifier = parser.parseIdentifier(isIdentifier);
|
const auto expressionIdentifier = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
ExpressionPointer expression;
|
ExpressionPointer expression;
|
||||||
|
|
||||||
if (expressionIdentifier == "and")
|
if (expressionIdentifier == "and")
|
||||||
expression = expressions::And::parse(parser, context, parameters, parseEffectExpression);
|
expression = expressions::And::parse(context, parameters, parseEffectExpression);
|
||||||
else if (expressionIdentifier == "forall"
|
else if (expressionIdentifier == "forall"
|
||||||
|| expressionIdentifier == "when")
|
|| expressionIdentifier == "when")
|
||||||
{
|
{
|
||||||
throwUnsupported(parser, expressionIdentifier);
|
throwUnsupported(context.parser, expressionIdentifier);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
expression = parseEffectBodyExpressionContent(expressionIdentifier, parser, context, parameters);
|
expression = parseEffectBodyExpressionContent(expressionIdentifier, context, parameters);
|
||||||
|
|
||||||
parser.expect<std::string>(")");
|
context.parser.expect<std::string>(")");
|
||||||
|
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
@ -160,12 +157,12 @@ ExpressionPointer parseEffectExpression(utils::Parser &parser, Context &context,
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parseEffectBodyExpressionContent(const std::string &expressionIdentifier,
|
ExpressionPointer parseEffectBodyExpressionContent(const std::string &expressionIdentifier,
|
||||||
utils::Parser &parser, Context &context, const expressions::Variables ¶meters)
|
Context &context, const expressions::Variables ¶meters)
|
||||||
{
|
{
|
||||||
ExpressionPointer expression;
|
ExpressionPointer expression;
|
||||||
|
|
||||||
if (expressionIdentifier == "not")
|
if (expressionIdentifier == "not")
|
||||||
expression = expressions::Not::parse(parser, context, parameters, parsePredicate);
|
expression = expressions::Not::parse(context, parameters, parsePredicate);
|
||||||
else if (expressionIdentifier == "="
|
else if (expressionIdentifier == "="
|
||||||
|| expressionIdentifier == "assign"
|
|| expressionIdentifier == "assign"
|
||||||
|| expressionIdentifier == "scale-up"
|
|| expressionIdentifier == "scale-up"
|
||||||
|
@ -173,7 +170,7 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression
|
||||||
|| expressionIdentifier == "increase"
|
|| expressionIdentifier == "increase"
|
||||||
|| expressionIdentifier == "decrease")
|
|| expressionIdentifier == "decrease")
|
||||||
{
|
{
|
||||||
throwUnsupported(parser, expressionIdentifier);
|
throwUnsupported(context.parser, expressionIdentifier);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -186,9 +183,9 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression
|
||||||
|
|
||||||
// If predicate exists, parse it
|
// If predicate exists, parse it
|
||||||
if (match != context.predicateDeclarations.cend())
|
if (match != context.predicateDeclarations.cend())
|
||||||
expression = expressions::Predicate::parse(expressionIdentifier, parser, context, parameters);
|
expression = expressions::Predicate::parse(expressionIdentifier, context, parameters);
|
||||||
else
|
else
|
||||||
throw utils::ParserException(parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
throw utils::ParserException(context.parser, "Expression \"" + expressionIdentifier + "\" not allowed in this context");
|
||||||
}
|
}
|
||||||
|
|
||||||
return expression;
|
return expression;
|
||||||
|
@ -196,12 +193,11 @@ ExpressionPointer parseEffectBodyExpressionContent(const std::string &expression
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parsePredicate(utils::Parser &parser, Context &context,
|
ExpressionPointer parsePredicate(Context &context, const expressions::Variables ¶meters)
|
||||||
const expressions::Variables ¶meters)
|
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("(");
|
context.parser.expect<std::string>("(");
|
||||||
|
|
||||||
const auto predicateName = parser.parseIdentifier(isIdentifier);
|
const auto predicateName = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
ExpressionPointer expression;
|
ExpressionPointer expression;
|
||||||
|
|
||||||
|
@ -214,11 +210,11 @@ ExpressionPointer parsePredicate(utils::Parser &parser, Context &context,
|
||||||
|
|
||||||
// If predicate exists, parse it
|
// If predicate exists, parse it
|
||||||
if (match == context.predicateDeclarations.cend())
|
if (match == context.predicateDeclarations.cend())
|
||||||
throw utils::ParserException(parser, "Unknown predicate \"" + predicateName + "\"");
|
throw utils::ParserException(context.parser, "Unknown predicate \"" + predicateName + "\"");
|
||||||
|
|
||||||
expression = expressions::Predicate::parse(predicateName, parser, context, parameters);
|
expression = expressions::Predicate::parse(predicateName, context, parameters);
|
||||||
|
|
||||||
parser.expect<std::string>(")");
|
context.parser.expect<std::string>(")");
|
||||||
|
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,14 +79,14 @@ Requirement::Requirement(Requirement::Type type)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Requirement Requirement::parse(utils::Parser &parser)
|
Requirement Requirement::parse(Context &context)
|
||||||
{
|
{
|
||||||
const auto requirementName = parser.parseIdentifier(isIdentifier);
|
const auto requirementName = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
const auto match = requirementTypesToPDDL.right.find(requirementName);
|
const auto match = requirementTypesToPDDL.right.find(requirementName);
|
||||||
|
|
||||||
if (match == requirementTypesToPDDL.right.end())
|
if (match == requirementTypesToPDDL.right.end())
|
||||||
throw utils::ParserException(parser, "Unknown PDDL requirement \"" + requirementName + "\"");
|
throw utils::ParserException(context.parser, "Unknown PDDL requirement \"" + requirementName + "\"");
|
||||||
|
|
||||||
return Requirement(match->second);
|
return Requirement(match->second);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,13 @@ Constant::Constant()
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ConstantPointer Constant::parseDeclaration(utils::Parser &parser, Context &context)
|
ConstantPointer Constant::parseDeclaration(Context &context)
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
auto constant = std::make_unique<Constant>(Constant());
|
auto constant = std::make_unique<Constant>(Constant());
|
||||||
|
|
||||||
constant->m_name = parser.parseIdentifier(isIdentifier);
|
constant->m_name = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
BOOST_ASSERT(constant->m_name != "-");
|
BOOST_ASSERT(constant->m_name != "-");
|
||||||
|
|
||||||
|
@ -48,24 +48,24 @@ ConstantPointer Constant::parseDeclaration(utils::Parser &parser, Context &conte
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Constant::parseTypedDeclaration(utils::Parser &parser, Context &context)
|
void Constant::parseTypedDeclaration(Context &context)
|
||||||
{
|
{
|
||||||
// Parse and store constant
|
// Parse and store constant
|
||||||
context.constants.emplace_back(parseDeclaration(parser, context));
|
context.constants.emplace_back(parseDeclaration(context));
|
||||||
|
|
||||||
const auto &constant = context.constants.back();
|
const auto &constant = context.constants.back();
|
||||||
|
|
||||||
// Flag constant as correctly declared in the types section
|
// Flag constant as correctly declared in the types section
|
||||||
constant->setDeclared();
|
constant->setDeclared();
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
// Check for typing information
|
// Check for typing information
|
||||||
if (!parser.advanceIf('-'))
|
if (!context.parser.advanceIf('-'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// If existing, parse and store parent type
|
// If existing, parse and store parent type
|
||||||
auto *type = PrimitiveType::parseExisting(parser, context);
|
auto *type = PrimitiveType::parseExisting(context);
|
||||||
|
|
||||||
// Assign parent type to all types that were previously flagged
|
// Assign parent type to all types that were previously flagged
|
||||||
std::for_each(context.constants.begin(), context.constants.end(),
|
std::for_each(context.constants.begin(), context.constants.end(),
|
||||||
|
@ -81,11 +81,11 @@ void Constant::parseTypedDeclaration(utils::Parser &parser, Context &context)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Constant *Constant::parseExisting(utils::Parser &parser, Context &context)
|
Constant *Constant::parseExisting(Context &context)
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
const auto constantName = parser.parseIdentifier(isIdentifier);
|
const auto constantName = context.parser.parseIdentifier(isIdentifier);
|
||||||
// TODO: use hash map
|
// TODO: use hash map
|
||||||
const auto match = std::find_if(context.constants.cbegin(), context.constants.cend(),
|
const auto match = std::find_if(context.constants.cbegin(), context.constants.cend(),
|
||||||
[&](const auto &constant)
|
[&](const auto &constant)
|
||||||
|
@ -95,7 +95,7 @@ Constant *Constant::parseExisting(utils::Parser &parser, Context &context)
|
||||||
const auto constantExists = (match != context.constants.cend());
|
const auto constantExists = (match != context.constants.cend());
|
||||||
|
|
||||||
if (!constantExists)
|
if (!constantExists)
|
||||||
throw utils::ParserException(parser, "Constant \"" + constantName + "\" used but never declared");
|
throw utils::ParserException(context.parser, "Constant \"" + constantName + "\" used but never declared");
|
||||||
|
|
||||||
return match->get();
|
return match->get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,34 +27,33 @@ Predicate::Predicate()
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
PredicatePointer Predicate::parse(std::string name, utils::Parser &parser,
|
PredicatePointer Predicate::parse(std::string name, Context &context, const Variables ¶meters)
|
||||||
Context &context, const Variables ¶meters)
|
|
||||||
{
|
{
|
||||||
auto predicate = std::make_unique<Predicate>(Predicate());
|
auto predicate = std::make_unique<Predicate>(Predicate());
|
||||||
|
|
||||||
predicate->m_name = name;
|
predicate->m_name = name;
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
// Parse arguments
|
// Parse arguments
|
||||||
while (parser.currentCharacter() != ')')
|
while (context.parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
// Parse variables
|
// Parse variables
|
||||||
if (parser.currentCharacter() == '?')
|
if (context.parser.currentCharacter() == '?')
|
||||||
{
|
{
|
||||||
const auto *variable = Variable::parseExisting(parser, parameters);
|
const auto *variable = Variable::parseExisting(context, parameters);
|
||||||
auto variableReference = std::make_unique<Reference<Variable>>(variable);
|
auto variableReference = std::make_unique<Reference<Variable>>(variable);
|
||||||
predicate->m_arguments.emplace_back(std::move(variableReference));
|
predicate->m_arguments.emplace_back(std::move(variableReference));
|
||||||
}
|
}
|
||||||
// Parse constants
|
// Parse constants
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto *constant = Constant::parseExisting(parser, context);
|
const auto *constant = Constant::parseExisting(context);
|
||||||
auto constantReference = std::make_unique<Reference<Constant>>(constant);
|
auto constantReference = std::make_unique<Reference<Constant>>(constant);
|
||||||
predicate->m_arguments.emplace_back(std::move(constantReference));
|
predicate->m_arguments.emplace_back(std::move(constantReference));
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: check that signature matches one of the declared ones
|
// TODO: check that signature matches one of the declared ones
|
||||||
|
|
|
@ -27,28 +27,28 @@ PredicateDeclaration::PredicateDeclaration()
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void PredicateDeclaration::parse(utils::Parser &parser, Context &context)
|
void PredicateDeclaration::parse(Context &context)
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("(");
|
context.parser.expect<std::string>("(");
|
||||||
|
|
||||||
auto predicate = std::make_unique<PredicateDeclaration>(PredicateDeclaration());
|
auto predicate = std::make_unique<PredicateDeclaration>(PredicateDeclaration());
|
||||||
|
|
||||||
predicate->m_name = parser.parseIdentifier(isIdentifier);
|
predicate->m_name = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
// Flag predicate as correctly declared in the types section
|
// Flag predicate as correctly declared in the types section
|
||||||
predicate->setDeclared();
|
predicate->setDeclared();
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
// Parse arguments
|
// Parse arguments
|
||||||
while (parser.currentCharacter() != ')')
|
while (context.parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
expressions::Variable::parseTypedDeclaration(parser, context, predicate->m_arguments);
|
expressions::Variable::parseTypedDeclaration(context, predicate->m_arguments);
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.expect<std::string>(")");
|
context.parser.expect<std::string>(")");
|
||||||
|
|
||||||
// Store new predicate
|
// Store new predicate
|
||||||
context.predicateDeclarations.emplace_back(std::move(predicate));
|
context.predicateDeclarations.emplace_back(std::move(predicate));
|
||||||
|
|
|
@ -46,11 +46,11 @@ PrimitiveType *PrimitiveType::create(std::string name, Context &context)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
PrimitiveType *PrimitiveType::parseDeclaration(utils::Parser &parser, Context &context)
|
PrimitiveType *PrimitiveType::parseDeclaration(Context &context)
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
const auto typeName = parser.parseIdentifier(isIdentifier);
|
const auto typeName = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
// TODO: use hash map
|
// TODO: use hash map
|
||||||
const auto match = std::find_if(context.primitiveTypes.cbegin(), context.primitiveTypes.cend(),
|
const auto match = std::find_if(context.primitiveTypes.cbegin(), context.primitiveTypes.cend(),
|
||||||
|
@ -74,22 +74,22 @@ PrimitiveType *PrimitiveType::parseDeclaration(utils::Parser &parser, Context &c
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void PrimitiveType::parseTypedDeclaration(utils::Parser &parser, Context &context)
|
void PrimitiveType::parseTypedDeclaration(Context &context)
|
||||||
{
|
{
|
||||||
// Parse and store type
|
// Parse and store type
|
||||||
auto *type = parseDeclaration(parser, context);
|
auto *type = parseDeclaration(context);
|
||||||
|
|
||||||
// Flag type as correctly declared in the types section
|
// Flag type as correctly declared in the types section
|
||||||
type->setDeclared();
|
type->setDeclared();
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
// Check for type inheritance
|
// Check for type inheritance
|
||||||
if (!parser.advanceIf('-'))
|
if (!context.parser.advanceIf('-'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// If existing, parse and store parent type
|
// If existing, parse and store parent type
|
||||||
auto *parentType = parseExisting(parser, context);
|
auto *parentType = parseExisting(context);
|
||||||
|
|
||||||
parentType->setDirty(false);
|
parentType->setDirty(false);
|
||||||
|
|
||||||
|
@ -110,11 +110,11 @@ void PrimitiveType::parseTypedDeclaration(utils::Parser &parser, Context &contex
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
PrimitiveType *PrimitiveType::parseExisting(utils::Parser &parser, Context &context)
|
PrimitiveType *PrimitiveType::parseExisting(Context &context)
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
const auto typeName = parser.parseIdentifier(isIdentifier);
|
const auto typeName = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
BOOST_ASSERT(!typeName.empty());
|
BOOST_ASSERT(!typeName.empty());
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,9 @@ namespace expressions
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ExpressionPointer parseExistingPrimitiveType(utils::Parser &parser, Context &context,
|
ExpressionPointer parseExistingPrimitiveType(Context &context, const Variables ¶meters)
|
||||||
const Variables ¶meters)
|
|
||||||
{
|
{
|
||||||
auto primitiveType = PrimitiveType::parseExisting(parser, context);
|
auto primitiveType = PrimitiveType::parseExisting(context);
|
||||||
|
|
||||||
return std::make_unique<Reference<PrimitiveType>>(primitiveType);
|
return std::make_unique<Reference<PrimitiveType>>(primitiveType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,15 +29,15 @@ Variable::Variable()
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
VariablePointer Variable::parseDeclaration(utils::Parser &parser)
|
VariablePointer Variable::parseDeclaration(Context &context)
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
parser.expect<std::string>("?");
|
context.parser.expect<std::string>("?");
|
||||||
|
|
||||||
auto variable = std::make_unique<Variable>(Variable());
|
auto variable = std::make_unique<Variable>(Variable());
|
||||||
|
|
||||||
variable->m_name = parser.parseIdentifier(isIdentifier);
|
variable->m_name = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
// Flag variable for potentially upcoming type declaration
|
// Flag variable for potentially upcoming type declaration
|
||||||
variable->setDirty();
|
variable->setDirty();
|
||||||
|
@ -47,17 +47,17 @@ VariablePointer Variable::parseDeclaration(utils::Parser &parser)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Variable::parseTypedDeclaration(utils::Parser &parser, Context &context, Variables ¶meters)
|
void Variable::parseTypedDeclaration(Context &context, Variables ¶meters)
|
||||||
{
|
{
|
||||||
// Parse and store variable itself
|
// Parse and store variable itself
|
||||||
parameters.emplace_back(parseDeclaration(parser));
|
parameters.emplace_back(parseDeclaration(context));
|
||||||
|
|
||||||
auto ¶meter = parameters.back();
|
auto ¶meter = parameters.back();
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
// Check if the variable has a type declaration
|
// Check if the variable has a type declaration
|
||||||
if (!parser.advanceIf('-'))
|
if (!context.parser.advanceIf('-'))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: do not allow nested either expressions
|
// TODO: do not allow nested either expressions
|
||||||
|
@ -77,37 +77,37 @@ void Variable::parseTypedDeclaration(utils::Parser &parser, Context &context, Va
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
// Parse argument of "either" type (always begins with opening parenthesis)
|
// Parse argument of "either" type (always begins with opening parenthesis)
|
||||||
if (parser.currentCharacter() == '(')
|
if (context.parser.currentCharacter() == '(')
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("(");
|
context.parser.expect<std::string>("(");
|
||||||
parser.expect<std::string>("either");
|
context.parser.expect<std::string>("either");
|
||||||
|
|
||||||
parameter->m_eitherExpression = Either::parse(parser, context, parameters, parseExistingPrimitiveType);
|
parameter->m_eitherExpression = Either::parse(context, parameters, parseExistingPrimitiveType);
|
||||||
|
|
||||||
parser.expect<std::string>(")");
|
context.parser.expect<std::string>(")");
|
||||||
|
|
||||||
setType(parameter->m_eitherExpression.get());
|
setType(parameter->m_eitherExpression.get());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse primitive type
|
// Parse primitive type
|
||||||
const auto *type = PrimitiveType::parseExisting(parser, context);
|
const auto *type = PrimitiveType::parseExisting(context);
|
||||||
|
|
||||||
setType(type);
|
setType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const Variable *Variable::parseExisting(utils::Parser &parser, const Variables &variables)
|
const Variable *Variable::parseExisting(Context &context, const Variables &variables)
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
context.parser.skipWhiteSpace();
|
||||||
|
|
||||||
parser.expect<std::string>("?");
|
context.parser.expect<std::string>("?");
|
||||||
|
|
||||||
const auto variableName = parser.parseIdentifier(isIdentifier);
|
const auto variableName = context.parser.parseIdentifier(isIdentifier);
|
||||||
|
|
||||||
const auto match = std::find_if(variables.cbegin(), variables.cend(),
|
const auto match = std::find_if(variables.cbegin(), variables.cend(),
|
||||||
[&](const auto &variable)
|
[&](const auto &variable)
|
||||||
|
@ -116,7 +116,7 @@ const Variable *Variable::parseExisting(utils::Parser &parser, const Variables &
|
||||||
});
|
});
|
||||||
|
|
||||||
if (match == variables.cend())
|
if (match == variables.cend())
|
||||||
throw utils::ParserException(parser, "Variable \"" + variableName + "\" used but never declared");
|
throw utils::ParserException(context.parser, "Variable \"" + variableName + "\" used but never declared");
|
||||||
|
|
||||||
return match->get();
|
return match->get();
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue