Implemented term parser.
This commit is contained in:
parent
716b4801aa
commit
89f3eb0306
@ -25,6 +25,8 @@ template<typename Argument, typename ArgumentParser>
|
||||
std::experimental::optional<ast::AtPointer<Argument>> parseAt(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentParser parseArgument);
|
||||
template<typename Argument, typename ArgumentParser>
|
||||
std::experimental::optional<ast::EitherPointer<Argument>> parseEither(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentParser parseArgument);
|
||||
template<typename ArgumentLeft, typename ArgumentRight, typename ArgumentLeftParser, typename ArgumentRightParser>
|
||||
std::experimental::optional<ast::EqualsPointer<ArgumentLeft, ArgumentRight>> parseEquals(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentLeftParser parseArgumentLeft, ArgumentRightParser parseArgumentRight);
|
||||
template<typename Argument, typename ArgumentParser>
|
||||
std::experimental::optional<ast::ExistsPointer<Argument>> parseExists(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentParser parseArgument);
|
||||
template<typename Argument, typename ArgumentParser>
|
||||
@ -177,6 +179,14 @@ std::experimental::optional<ast::EitherPointer<Argument>> parseEither(Context &c
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename ArgumentLeft, typename ArgumentRight, typename ArgumentLeftParser, typename ArgumentRightParser>
|
||||
std::experimental::optional<ast::EqualsPointer<ArgumentLeft, ArgumentRight>> parseEquals(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentLeftParser parseArgumentLeft, ArgumentRightParser parseArgumentRight)
|
||||
{
|
||||
return parseBinary<ast::Equals<ArgumentLeft, ArgumentRight>, ArgumentLeftParser, ArgumentRightParser>(context, astContext, variableStack, parseArgumentLeft, parseArgumentRight);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<typename Argument, typename ArgumentParser>
|
||||
std::experimental::optional<ast::ExistsPointer<Argument>> parseExists(Context &context, ASTContext &astContext, VariableStack &variableStack, ArgumentParser parseArgument)
|
||||
{
|
||||
|
27
lib/pddl/include/pddl/detail/parsing/Term.h
Normal file
27
lib/pddl/include/pddl/detail/parsing/Term.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef __PDDL__DETAIL__PARSING__TERM_H
|
||||
#define __PDDL__DETAIL__PARSING__TERM_H
|
||||
|
||||
#include <pddl/ASTForward.h>
|
||||
#include <pddl/Context.h>
|
||||
#include <pddl/detail/ASTContext.h>
|
||||
#include <pddl/detail/VariableStack.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Type
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::experimental::optional<ast::Term> parseTerm(Context &context, ASTContext &astContext, VariableStack &variableStack);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -1,8 +1,9 @@
|
||||
#include <pddl/detail/parsing/AtomicFormula.h>
|
||||
|
||||
#include <pddl/AST.h>
|
||||
#include <pddl/detail/parsing/Expressions.h>
|
||||
#include <pddl/detail/parsing/Predicate.h>
|
||||
#include <pddl/detail/parsing/Unsupported.h>
|
||||
#include <pddl/detail/parsing/Term.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
@ -17,20 +18,11 @@ namespace detail
|
||||
|
||||
std::experimental::optional<ast::AtomicFormula> parseAtomicFormula(Context &context, ASTContext &astContext, VariableStack &variableStack)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
std::experimental::optional<ast::AtomicFormula> atomicFormula;
|
||||
|
||||
// Test unsupported expressions first
|
||||
const auto position = tokenizer.position();
|
||||
if ((atomicFormula = parseEquals<ast::Term, ast::Term>(context, astContext, variableStack, parseTerm, parseTerm)))
|
||||
return std::move(atomicFormula.value());
|
||||
|
||||
tokenizer.expect<std::string>("(");
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
if (tokenizer.testIdentifierAndReturn("="))
|
||||
throw exceptUnsupportedExpression(position, context);
|
||||
|
||||
tokenizer.seek(position);
|
||||
|
||||
// Now, test supported expressions
|
||||
return parsePredicate(context, astContext, variableStack);
|
||||
}
|
||||
|
||||
|
42
lib/pddl/src/pddl/detail/parsing/Term.cpp
Normal file
42
lib/pddl/src/pddl/detail/parsing/Term.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <pddl/detail/parsing/Term.h>
|
||||
|
||||
#include <pddl/Exception.h>
|
||||
#include <pddl/detail/parsing/Constant.h>
|
||||
#include <pddl/detail/parsing/Variable.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Term
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::experimental::optional<ast::Term> parseTerm(Context &context, ASTContext &astContext, VariableStack &variableStack)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
// TODO: refactor
|
||||
auto variable = testParsingVariable(context, variableStack);
|
||||
|
||||
if (variable)
|
||||
return std::move(variable.value());
|
||||
|
||||
// Parse argument if it is a constant
|
||||
auto constant = testParsingConstant(context, astContext);
|
||||
|
||||
if (constant)
|
||||
return std::move(constant.value());
|
||||
|
||||
return std::experimental::nullopt;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user