Reimplemented initial state parser.
This commit is contained in:
parent
fbcb790611
commit
f90009b6d1
@ -241,11 +241,14 @@ using Literals = std::vector<Literal>;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Fact;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
using FactT = Variant<
|
||||
AtomicFormula,
|
||||
AtPointer<Literal>>;
|
||||
AtPointer<Literal>,
|
||||
NotPointer<Fact>>;
|
||||
}
|
||||
|
||||
class Fact : public detail::FactT
|
||||
|
27
lib/pddlparse/include/pddlparse/detail/parsing/Fact.h
Normal file
27
lib/pddlparse/include/pddlparse/detail/parsing/Fact.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef __PDDL_PARSE__DETAIL__PARSING__FACT_H
|
||||
#define __PDDL_PARSE__DETAIL__PARSING__FACT_H
|
||||
|
||||
#include <pddlparse/ASTForward.h>
|
||||
#include <pddlparse/Context.h>
|
||||
#include <pddlparse/detail/ASTContext.h>
|
||||
#include <pddlparse/detail/VariableStack.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Fact
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::experimental::optional<ast::Fact> parseFact(Context &context, ASTContext &astContext, VariableStack &variableStack);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -15,7 +15,7 @@ namespace detail
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::InitialState parseInitialState(Context &context, ASTContext &expressionContext);
|
||||
ast::InitialState parseInitialState(Context &context, ASTContext &astContext, VariableStack &variableStack);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
53
lib/pddlparse/src/pddlparse/detail/parsing/Fact.cpp
Normal file
53
lib/pddlparse/src/pddlparse/detail/parsing/Fact.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
#include <pddlparse/detail/parsing/Fact.h>
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/detail/parsing/AtomicFormula.h>
|
||||
#include <pddlparse/detail/parsing/Expressions.h>
|
||||
#include <pddlparse/detail/parsing/Unsupported.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Fact
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
std::experimental::optional<ast::Fact> parseFact(Context &context, ASTContext &astContext, VariableStack &variableStack)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
// Test unsupported expressions first
|
||||
const auto position = tokenizer.position();
|
||||
|
||||
tokenizer.expect<std::string>("(");
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
if (tokenizer.testIdentifierAndReturn("=")
|
||||
|| tokenizer.testIdentifierAndReturn("at"))
|
||||
{
|
||||
tokenizer.seek(position);
|
||||
return parseUnsupported(context);
|
||||
}
|
||||
|
||||
tokenizer.seek(position);
|
||||
|
||||
// Now, test supported expressions
|
||||
std::experimental::optional<ast::Fact> fact;
|
||||
|
||||
if ((fact = parseNot<ast::Fact>(context, astContext, variableStack, parseAtomicFormula))
|
||||
|| (fact = parseAtomicFormula(context, astContext, variableStack)))
|
||||
{
|
||||
return std::move(fact.value());
|
||||
}
|
||||
|
||||
return parseAtomicFormula(context, astContext, variableStack);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <pddlparse/AST.h>
|
||||
#include <pddlparse/ParserException.h>
|
||||
#include <pddlparse/detail/parsing/Fact.h>
|
||||
|
||||
namespace pddl
|
||||
{
|
||||
@ -14,62 +15,25 @@ namespace detail
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ast::InitialState parseInitialState(Context &context, ASTContext &)
|
||||
ast::InitialState parseInitialState(Context &context, ASTContext &astContext, VariableStack &variableStack)
|
||||
{
|
||||
auto &tokenizer = context.tokenizer;
|
||||
|
||||
ast::InitialState initialState;
|
||||
|
||||
context.warningCallback(tokenizer.location(), "initial state parser under construction, section is currently ignored");
|
||||
|
||||
// TODO: reimplement
|
||||
/*const auto parseInitialStateElement =
|
||||
[&]() -> ExpressionPointer
|
||||
{
|
||||
ExpressionPointer expression;
|
||||
|
||||
// TODO: do not allow negative initial state literals
|
||||
if ((expression = parseLiteral(context, expressionContext))
|
||||
|| (expression = expressions::At::parse(context, expressionContext, parseLiteral)))
|
||||
{
|
||||
return expression;
|
||||
}
|
||||
|
||||
const auto position = tokenizer.position();
|
||||
|
||||
tokenizer.expect<std::string>("(");
|
||||
|
||||
const auto expressionIdentifierPosition = tokenizer.position();
|
||||
|
||||
if (tokenizer.testIdentifierAndSkip("="))
|
||||
{
|
||||
tokenizer.seek(expressionIdentifierPosition);
|
||||
const auto expressionIdentifier = tokenizer.getIdentifier();
|
||||
|
||||
tokenizer.seek(position);
|
||||
return expressions::Unsupported::parse(context);
|
||||
}
|
||||
|
||||
tokenizer.seek(expressionIdentifierPosition);
|
||||
const auto expressionIdentifier = tokenizer.getIdentifier();
|
||||
|
||||
tokenizer.seek(position);
|
||||
throw tokenize::TokenizerException(tokenizer.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||
};
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
|
||||
while (tokenizer.currentCharacter() != ')')
|
||||
{
|
||||
ast::Expression expression;
|
||||
auto fact = parseFact(context, astContext, variableStack);
|
||||
|
||||
if ((expression = parseInitialStateElement()))
|
||||
initialState->m_facts.emplace_back(std::move(expression));
|
||||
if (!fact)
|
||||
throw ParserException(tokenizer.location(), "invalid initial state fact");
|
||||
|
||||
initialState.facts.emplace_back(std::move(fact.value()));
|
||||
|
||||
tokenizer.skipWhiteSpace();
|
||||
}*/
|
||||
|
||||
skipSection(tokenizer);
|
||||
}
|
||||
|
||||
return initialState;
|
||||
}
|
||||
|
@ -267,12 +267,10 @@ void ProblemParser::parseInitialStateSection(ast::Problem &problem)
|
||||
tokenizer.expect<std::string>("init");
|
||||
|
||||
ASTContext astContext(problem);
|
||||
VariableStack variableStack;
|
||||
|
||||
m_context.warningCallback(tokenizer.location(), "initial state parser under construction, section is currently ignored");
|
||||
|
||||
// TODO: reimplement
|
||||
//problem.initialState = parseInitialState(m_context, astContext);
|
||||
//tokenizer.expect<std::string>(")");
|
||||
problem.initialState = parseInitialState(m_context, astContext, variableStack);
|
||||
tokenizer.expect<std::string>(")");
|
||||
|
||||
skipSection(tokenizer);
|
||||
}
|
||||
|
Reference in New Issue
Block a user