Continued working on reimplementing action parser.
This commit is contained in:
@@ -15,7 +15,32 @@ namespace detail
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void parseAndAddAction(Context &context, ast::Domain &domain);
|
||||
class ActionParser
|
||||
{
|
||||
public:
|
||||
ActionParser(Context &context, ast::Domain &domain);
|
||||
ast::ActionPointer parse();
|
||||
|
||||
private:
|
||||
void findSections(ast::Action &action);
|
||||
|
||||
void parseParameterSection(ast::Action &action);
|
||||
void parsePreconditionSection(ast::Action &action);
|
||||
void parseEffectSection(ast::Action &action);
|
||||
|
||||
// For compatibility with old PDDL versions
|
||||
void parseVarsSection(ast::Action &action);
|
||||
|
||||
Context &m_context;
|
||||
ast::Domain &m_domain;
|
||||
|
||||
tokenize::Stream::Position m_parametersPosition;
|
||||
tokenize::Stream::Position m_preconditionPosition;
|
||||
tokenize::Stream::Position m_effectPosition;
|
||||
|
||||
// For compatibility with old PDDL versions
|
||||
tokenize::Stream::Position m_varsPosition;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@@ -146,7 +146,7 @@ std::experimental::optional<std::unique_ptr<Derived>> parseQuantified(Context &c
|
||||
auto argument = parseArgument(context, astContext, variableStack);
|
||||
|
||||
if (!argument)
|
||||
throw ParserException(tokenizer.location(), "could not parse argument of “" + Derived::Identifier + "” expression");
|
||||
throw ParserException(tokenizer.location(), "could not parse argument of “" + std::string(Derived::Identifier) + "” expression");
|
||||
|
||||
// Clean up variable stack
|
||||
variableStack.pop();
|
||||
@@ -176,6 +176,22 @@ std::experimental::optional<ast::EitherPointer<Argument>> parseEither(Context &c
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename Argument, typename ArgumentParser>
|
||||
std::experimental::optional<ast::ExistsPointer<Argument>> parseExists(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentParser parseArgument)
|
||||
{
|
||||
return parseQuantified<ast::Exists<Argument>, ArgumentParser>(context, astContext, variableStack, parseArgument);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename Argument, typename ArgumentParser>
|
||||
std::experimental::optional<ast::ForAllPointer<Argument>> parseForAll(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentParser parseArgument)
|
||||
{
|
||||
return parseQuantified<ast::ForAll<Argument>, ArgumentParser>(context, astContext, variableStack, parseArgument);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename Argument, typename ArgumentParser>
|
||||
std::experimental::optional<ast::ImplyPointer<Argument>> parseImply(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentParser parseArgument)
|
||||
{
|
||||
@@ -184,6 +200,35 @@ std::experimental::optional<ast::ImplyPointer<Argument>> parseImply(Context &con
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename Argument, typename ArgumentParser>
|
||||
std::experimental::optional<ast::NotPointer<Argument>> parseNot(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentParser parseArgument)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
const auto position = tokenizer.position();
|
||||
|
||||
if (!tokenizer.testAndSkip<std::string>("(")
|
||||
|| !tokenizer.testIdentifierAndSkip("not"))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return std::experimental::nullopt;
|
||||
}
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
// Parse argument
|
||||
auto argument = parseArgument(context, astContext, variableStack);
|
||||
|
||||
if (!argument)
|
||||
throw ParserException(tokenizer.location(), "could not parse argument of “not” expression");
|
||||
|
||||
tokenizer.expect<std::string>(")");
|
||||
|
||||
return std::make_unique<ast::Not<Argument>>(std::move(argument.value()));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename Argument, typename ArgumentParser>
|
||||
std::experimental::optional<ast::OrPointer<Argument>> parseOr(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentParser parseArgument)
|
||||
{
|
||||
|
@@ -15,6 +15,7 @@ namespace detail
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void parseAndAddVariableDeclarations(Context &context, ast::Domain &domain, ast::VariableDeclarations &variableDeclarations);
|
||||
ast::VariableDeclarations parseVariableDeclarations(Context &context, ast::Domain &domain);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Reference in New Issue
Block a user