Moved basic parsing to a separate module.
This commit is contained in:
parent
386e5356af
commit
27c6b69874
@ -42,5 +42,5 @@ script:
|
|||||||
- git submodule update --recursive --init
|
- git submodule update --recursive --init
|
||||||
- mkdir -p build/debug
|
- mkdir -p build/debug
|
||||||
- cd build/debug
|
- cd build/debug
|
||||||
- cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$_CXX -DPLASP_BUILD_TESTS=ON
|
- cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$_CXX -DPLASP_BUILD_TESTS=ON -DPARSEBASE_BUILD_TESTS=ON
|
||||||
- make -j3 plasp-app && make -j3 run-tests
|
- make -j3 plasp-app && make -j3 run-parsebase-tests && make -j3 run-tests
|
||||||
|
@ -24,6 +24,7 @@ if (CMAKE_GENERATOR STREQUAL "Ninja" AND
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(lib/parsebase)
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
add_subdirectory(app)
|
add_subdirectory(app)
|
||||||
if(PLASP_BUILD_TESTS)
|
if(PLASP_BUILD_TESTS)
|
||||||
|
@ -6,6 +6,7 @@ file(GLOB core_headers "*.h")
|
|||||||
set(includes
|
set(includes
|
||||||
${Boost_INCLUDE_DIRS}
|
${Boost_INCLUDE_DIRS}
|
||||||
${PROJECT_SOURCE_DIR}/include
|
${PROJECT_SOURCE_DIR}/include
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/parsebase/include
|
||||||
)
|
)
|
||||||
|
|
||||||
set(sources
|
set(sources
|
||||||
|
@ -109,7 +109,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plasp::input::Parser<plasp::input::CaseInsensitiveParserPolicy> parser;
|
parsebase::Parser<parsebase::CaseInsensitiveParserPolicy> parser;
|
||||||
|
|
||||||
if (variablesMap.count("input"))
|
if (variablesMap.count("input"))
|
||||||
{
|
{
|
||||||
@ -160,7 +160,7 @@ int main(int argc, char **argv)
|
|||||||
translator.translate();
|
translator.translate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (const plasp::input::ParserException &e)
|
catch (const parsebase::ParserException &e)
|
||||||
{
|
{
|
||||||
logger.log(plasp::output::Priority::Error, e.location(), e.message().c_str());
|
logger.log(plasp::output::Priority::Error, e.location(), e.message().c_str());
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
#define __PLASP__LANGUAGE_DETECTION_H
|
#define __PLASP__LANGUAGE_DETECTION_H
|
||||||
|
|
||||||
#include <plasp/Language.h>
|
#include <plasp/Language.h>
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -13,7 +14,7 @@ namespace plasp
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Language::Type detectLanguage(input::Parser<input::CaseInsensitiveParserPolicy> &parser)
|
Language::Type detectLanguage(parsebase::Parser<parsebase::CaseInsensitiveParserPolicy> &parser)
|
||||||
{
|
{
|
||||||
parser.skipWhiteSpace();
|
parser.skipWhiteSpace();
|
||||||
|
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <plasp/input/Location.h>
|
|
||||||
#include <plasp/output/ColorStream.h>
|
#include <plasp/output/ColorStream.h>
|
||||||
#include <plasp/output/Priority.h>
|
#include <plasp/output/Priority.h>
|
||||||
|
|
||||||
|
#include <parsebase/Location.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace output
|
namespace output
|
||||||
@ -36,8 +37,8 @@ class Logger
|
|||||||
|
|
||||||
void log(Priority priority, const char *message);
|
void log(Priority priority, const char *message);
|
||||||
void log(Priority priority, const std::string &message);
|
void log(Priority priority, const std::string &message);
|
||||||
void log(Priority priority, const input::Location &location, const char *message);
|
void log(Priority priority, const parsebase::Location &location, const char *message);
|
||||||
void log(Priority priority, const input::Location &location, const std::string &message);
|
void log(Priority priority, const parsebase::Location &location, const std::string &message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ColorStream m_outputStream;
|
ColorStream m_outputStream;
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/pddl/Expression.h>
|
#include <plasp/pddl/Expression.h>
|
||||||
#include <plasp/pddl/expressions/Variable.h>
|
#include <plasp/pddl/expressions/Variable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/Problem.h>
|
#include <plasp/pddl/Problem.h>
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -47,9 +48,9 @@ class Description
|
|||||||
|
|
||||||
Context &m_context;
|
Context &m_context;
|
||||||
|
|
||||||
input::Stream::Position m_domainPosition;
|
parsebase::Stream::Position m_domainPosition;
|
||||||
std::unique_ptr<Domain> m_domain;
|
std::unique_ptr<Domain> m_domain;
|
||||||
input::Stream::Position m_problemPosition;
|
parsebase::Stream::Position m_problemPosition;
|
||||||
std::unique_ptr<Problem> m_problem;
|
std::unique_ptr<Problem> m_problem;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -75,19 +75,19 @@ class Domain
|
|||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
input::Stream::Position m_requirementsPosition;
|
parsebase::Stream::Position m_requirementsPosition;
|
||||||
Requirements m_requirements;
|
Requirements m_requirements;
|
||||||
|
|
||||||
input::Stream::Position m_typesPosition;
|
parsebase::Stream::Position m_typesPosition;
|
||||||
expressions::PrimitiveTypes m_types;
|
expressions::PrimitiveTypes m_types;
|
||||||
|
|
||||||
input::Stream::Position m_constantsPosition;
|
parsebase::Stream::Position m_constantsPosition;
|
||||||
expressions::Constants m_constants;
|
expressions::Constants m_constants;
|
||||||
|
|
||||||
input::Stream::Position m_predicatesPosition;
|
parsebase::Stream::Position m_predicatesPosition;
|
||||||
expressions::PredicateDeclarations m_predicates;
|
expressions::PredicateDeclarations m_predicates;
|
||||||
|
|
||||||
std::vector<input::Stream::Position> m_actionPositions;
|
std::vector<parsebase::Stream::Position> m_actionPositions;
|
||||||
std::vector<std::unique_ptr<Action>> m_actions;
|
std::vector<std::unique_ptr<Action>> m_actions;
|
||||||
|
|
||||||
expressions::DerivedPredicates m_derivedPredicates;
|
expressions::DerivedPredicates m_derivedPredicates;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <boost/intrusive_ptr.hpp>
|
#include <boost/intrusive_ptr.hpp>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#ifndef __PLASP__PDDL__PARSER_H
|
#ifndef __PLASP__PDDL__PARSER_H
|
||||||
#define __PLASP__PDDL__PARSER_H
|
#define __PLASP__PDDL__PARSER_H
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ class PDDLParserPolicy
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
using Parser = input::Parser<PDDLParserPolicy>;
|
using Parser = parsebase::Parser<PDDLParserPolicy>;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -64,18 +64,18 @@ class Problem
|
|||||||
|
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
|
||||||
input::Stream::Position m_domainPosition;
|
parsebase::Stream::Position m_domainPosition;
|
||||||
|
|
||||||
input::Stream::Position m_requirementsPosition;
|
parsebase::Stream::Position m_requirementsPosition;
|
||||||
Requirements m_requirements;
|
Requirements m_requirements;
|
||||||
|
|
||||||
input::Stream::Position m_objectsPosition;
|
parsebase::Stream::Position m_objectsPosition;
|
||||||
expressions::Constants m_objects;
|
expressions::Constants m_objects;
|
||||||
|
|
||||||
input::Stream::Position m_initialStatePosition;
|
parsebase::Stream::Position m_initialStatePosition;
|
||||||
std::unique_ptr<InitialState> m_initialState;
|
std::unique_ptr<InitialState> m_initialState;
|
||||||
|
|
||||||
input::Stream::Position m_goalPosition;
|
parsebase::Stream::Position m_goalPosition;
|
||||||
ExpressionPointer m_goal;
|
ExpressionPointer m_goal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,10 +4,11 @@
|
|||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/sas/Value.h>
|
#include <plasp/sas/Value.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -27,8 +28,8 @@ using AssignedVariables = std::vector<AssignedVariable>;
|
|||||||
class AssignedVariable
|
class AssignedVariable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static AssignedVariable fromSAS(input::Parser<> &parser, const Variables &variables);
|
static AssignedVariable fromSAS(parsebase::Parser<> &parser, const Variables &variables);
|
||||||
static AssignedVariable fromSAS(input::Parser<> &parser, const Variable &variable);
|
static AssignedVariable fromSAS(parsebase::Parser<> &parser, const Variable &variable);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AssignedVariable(const Variable &variable, const Value &value);
|
explicit AssignedVariable(const Variable &variable, const Value &value);
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -29,7 +30,7 @@ class AxiomRule
|
|||||||
using Condition = AssignedVariable;
|
using Condition = AssignedVariable;
|
||||||
using Conditions = AssignedVariables;
|
using Conditions = AssignedVariables;
|
||||||
|
|
||||||
static AxiomRule fromSAS(input::Parser<> &parser, const Variables &variables);
|
static AxiomRule fromSAS(parsebase::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Conditions &conditions() const;
|
const Conditions &conditions() const;
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
#ifndef __PLASP__SAS__DESCRIPTION_H
|
#ifndef __PLASP__SAS__DESCRIPTION_H
|
||||||
#define __PLASP__SAS__DESCRIPTION_H
|
#define __PLASP__SAS__DESCRIPTION_H
|
||||||
|
|
||||||
|
#include <experimental/filesystem>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/filesystem/path.hpp>
|
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/sas/AxiomRule.h>
|
#include <plasp/sas/AxiomRule.h>
|
||||||
#include <plasp/sas/Goal.h>
|
#include <plasp/sas/Goal.h>
|
||||||
#include <plasp/sas/InitialState.h>
|
#include <plasp/sas/InitialState.h>
|
||||||
@ -15,6 +14,8 @@
|
|||||||
#include <plasp/sas/Operator.h>
|
#include <plasp/sas/Operator.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -29,9 +30,9 @@ namespace sas
|
|||||||
class Description
|
class Description
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Description fromParser(input::Parser<> &&parser);
|
static Description fromParser(parsebase::Parser<> &&parser);
|
||||||
static Description fromStream(std::istream &istream);
|
static Description fromStream(std::istream &istream);
|
||||||
static Description fromFile(const boost::filesystem::path &path);
|
static Description fromFile(const std::experimental::filesystem::path &path);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool usesActionCosts() const;
|
bool usesActionCosts() const;
|
||||||
@ -50,16 +51,16 @@ class Description
|
|||||||
private:
|
private:
|
||||||
Description();
|
Description();
|
||||||
|
|
||||||
void parseContent(input::Parser<> &parser);
|
void parseContent(parsebase::Parser<> &parser);
|
||||||
|
|
||||||
void parseVersionSection(input::Parser<> &parser) const;
|
void parseVersionSection(parsebase::Parser<> &parser) const;
|
||||||
void parseMetricSection(input::Parser<> &parser);
|
void parseMetricSection(parsebase::Parser<> &parser);
|
||||||
void parseVariablesSection(input::Parser<> &parser);
|
void parseVariablesSection(parsebase::Parser<> &parser);
|
||||||
void parseMutexSection(input::Parser<> &parser);
|
void parseMutexSection(parsebase::Parser<> &parser);
|
||||||
void parseInitialStateSection(input::Parser<> &parser);
|
void parseInitialStateSection(parsebase::Parser<> &parser);
|
||||||
void parseGoalSection(input::Parser<> &parser);
|
void parseGoalSection(parsebase::Parser<> &parser);
|
||||||
void parseOperatorSection(input::Parser<> &parser);
|
void parseOperatorSection(parsebase::Parser<> &parser);
|
||||||
void parseAxiomSection(input::Parser<> &parser);
|
void parseAxiomSection(parsebase::Parser<> &parser);
|
||||||
|
|
||||||
bool m_usesActionCosts;
|
bool m_usesActionCosts;
|
||||||
|
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -29,7 +30,7 @@ class Effect
|
|||||||
using Condition = AssignedVariable;
|
using Condition = AssignedVariable;
|
||||||
using Conditions = AssignedVariables;
|
using Conditions = AssignedVariables;
|
||||||
|
|
||||||
static Effect fromSAS(input::Parser<> &parser, const Variables &variables, Conditions &preconditions);
|
static Effect fromSAS(parsebase::Parser<> &parser, const Variables &variables, Conditions &preconditions);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Conditions &conditions() const;
|
const Conditions &conditions() const;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#ifndef __PLASP__SAS__GOAL_H
|
#ifndef __PLASP__SAS__GOAL_H
|
||||||
#define __PLASP__SAS__GOAL_H
|
#define __PLASP__SAS__GOAL_H
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -21,7 +22,7 @@ class Goal
|
|||||||
using Fact = AssignedVariable;
|
using Fact = AssignedVariable;
|
||||||
using Facts = AssignedVariables;
|
using Facts = AssignedVariables;
|
||||||
|
|
||||||
static Goal fromSAS(input::Parser<> &parser, const Variables &variables);
|
static Goal fromSAS(parsebase::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Facts &facts() const;
|
const Facts &facts() const;
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#ifndef __PLASP__SAS__INITIAL_STATE_H
|
#ifndef __PLASP__SAS__INITIAL_STATE_H
|
||||||
#define __PLASP__SAS__INITIAL_STATE_H
|
#define __PLASP__SAS__INITIAL_STATE_H
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -21,7 +22,7 @@ class InitialState
|
|||||||
using Fact = AssignedVariable;
|
using Fact = AssignedVariable;
|
||||||
using Facts = AssignedVariables;
|
using Facts = AssignedVariables;
|
||||||
|
|
||||||
static InitialState fromSAS(input::Parser<> &parser, const Variables &variables);
|
static InitialState fromSAS(parsebase::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Facts &facts() const;
|
const Facts &facts() const;
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -28,7 +29,7 @@ class MutexGroup
|
|||||||
using Fact = AssignedVariable;
|
using Fact = AssignedVariable;
|
||||||
using Facts = AssignedVariables;
|
using Facts = AssignedVariables;
|
||||||
|
|
||||||
static MutexGroup fromSAS(input::Parser<> &parser, const Variables &variables);
|
static MutexGroup fromSAS(parsebase::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Facts &facts() const;
|
const Facts &facts() const;
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/output/ColorStream.h>
|
#include <plasp/output/ColorStream.h>
|
||||||
#include <plasp/sas/AssignedVariable.h>
|
#include <plasp/sas/AssignedVariable.h>
|
||||||
#include <plasp/sas/Effect.h>
|
#include <plasp/sas/Effect.h>
|
||||||
#include <plasp/sas/Predicate.h>
|
#include <plasp/sas/Predicate.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -33,7 +34,7 @@ class Operator
|
|||||||
using Condition = AssignedVariable;
|
using Condition = AssignedVariable;
|
||||||
using Conditions = AssignedVariables;
|
using Conditions = AssignedVariables;
|
||||||
|
|
||||||
static Operator fromSAS(input::Parser<> &parser, const Variables &variables);
|
static Operator fromSAS(parsebase::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void printPredicateAsASP(output::ColorStream &stream) const;
|
void printPredicateAsASP(output::ColorStream &stream) const;
|
||||||
|
@ -5,9 +5,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/output/ColorStream.h>
|
#include <plasp/output/ColorStream.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -22,7 +23,7 @@ namespace sas
|
|||||||
class Predicate
|
class Predicate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Predicate fromSAS(input::Parser<> &parser);
|
static Predicate fromSAS(parsebase::Parser<> &parser);
|
||||||
|
|
||||||
using Arguments = std::vector<std::string>;
|
using Arguments = std::vector<std::string>;
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#ifndef __PLASP__SAS__TRANSLATOR_ASP_H
|
#ifndef __PLASP__SAS__TRANSLATOR_ASP_H
|
||||||
#define __PLASP__SAS__TRANSLATOR_ASP_H
|
#define __PLASP__SAS__TRANSLATOR_ASP_H
|
||||||
|
|
||||||
|
#include <iosfwd>
|
||||||
|
|
||||||
#include <plasp/output/ColorStream.h>
|
#include <plasp/output/ColorStream.h>
|
||||||
#include <plasp/sas/Description.h>
|
#include <plasp/sas/Description.h>
|
||||||
|
|
||||||
#include <iosfwd>
|
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
|
@ -5,9 +5,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/output/ColorStream.h>
|
#include <plasp/output/ColorStream.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -39,8 +40,8 @@ struct Value
|
|||||||
static const Value Any;
|
static const Value Any;
|
||||||
static const Value None;
|
static const Value None;
|
||||||
|
|
||||||
static Value fromSAS(input::Parser<> &parser);
|
static Value fromSAS(parsebase::Parser<> &parser);
|
||||||
static const Value &referenceFromSAS(input::Parser<> &parser, const Variable &variable);
|
static const Value &referenceFromSAS(parsebase::Parser<> &parser, const Variable &variable);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Value negated() const;
|
Value negated() const;
|
||||||
|
@ -5,10 +5,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/output/ColorStream.h>
|
#include <plasp/output/ColorStream.h>
|
||||||
#include <plasp/sas/Value.h>
|
#include <plasp/sas/Value.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -28,8 +29,8 @@ using Variables = std::vector<Variable>;
|
|||||||
class Variable
|
class Variable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static Variable fromSAS(input::Parser<> &parser);
|
static Variable fromSAS(parsebase::Parser<> &parser);
|
||||||
static const Variable &referenceFromSAS(input::Parser<> &parser, const Variables &variables);
|
static const Variable &referenceFromSAS(parsebase::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void printNameAsASPPredicate(output::ColorStream &outputStream) const;
|
void printNameAsASPPredicate(output::ColorStream &outputStream) const;
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
|
||||||
#include <plasp/sas/Value.h>
|
#include <plasp/sas/Value.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
|
|
||||||
|
#include <parsebase/Parser.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -26,7 +27,7 @@ using VariableTransitions = std::vector<VariableTransition>;
|
|||||||
class VariableTransition
|
class VariableTransition
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static VariableTransition fromSAS(input::Parser<> &parser, const Variables &variables);
|
static VariableTransition fromSAS(parsebase::Parser<> &parser, const Variables &variables);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const Variable &variable() const;
|
const Variable &variable() const;
|
||||||
|
28
lib/parsebase/CMakeLists.txt
Normal file
28
lib/parsebase/CMakeLists.txt
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.6)
|
||||||
|
project(parsebase)
|
||||||
|
|
||||||
|
option(PARSEBASE_BUILD_TESTS "Build unit tests" OFF)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Werror")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "-g")
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||||
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
|
|
||||||
|
if (CMAKE_GENERATOR STREQUAL "Ninja" AND
|
||||||
|
((CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) OR
|
||||||
|
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5)))
|
||||||
|
# Force colored warnings in Ninja's output, if the compiler has -fdiagnostics-color support.
|
||||||
|
# Rationale in https://github.com/ninja-build/ninja/issues/814
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(src)
|
||||||
|
if(PARSEBASE_BUILD_TESTS)
|
||||||
|
add_subdirectory(tests)
|
||||||
|
endif(PARSEBASE_BUILD_TESTS)
|
@ -1,11 +1,9 @@
|
|||||||
#ifndef __PLASP__INPUT__LOCATION_H
|
#ifndef __PARSE_BASE__LOCATION_H
|
||||||
#define __PLASP__INPUT__LOCATION_H
|
#define __PARSE_BASE__LOCATION_H
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace plasp
|
namespace parsebase
|
||||||
{
|
|
||||||
namespace input
|
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -28,7 +26,6 @@ struct Location
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,20 +1,18 @@
|
|||||||
#ifndef __PLASP__INPUT__PARSER_H
|
#ifndef __PARSE_BASE__PARSER_H
|
||||||
#define __PLASP__INPUT__PARSER_H
|
#define __PARSE_BASE__PARSER_H
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <parsebase/ParserException.h>
|
||||||
|
#include <parsebase/ParserPolicy.h>
|
||||||
|
#include <parsebase/Stream.h>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
namespace parsebase
|
||||||
#include <plasp/input/ParserPolicy.h>
|
|
||||||
#include <plasp/input/Stream.h>
|
|
||||||
|
|
||||||
namespace plasp
|
|
||||||
{
|
|
||||||
namespace input
|
|
||||||
{
|
{
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
@ -286,7 +284,7 @@ void Parser<ParserPolicy>::removeComments(const std::string &startSequence, cons
|
|||||||
const auto removeRange =
|
const auto removeRange =
|
||||||
[&](const auto &start, const auto &end)
|
[&](const auto &start, const auto &end)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(start != -1);
|
assert(start != -1);
|
||||||
|
|
||||||
m_stream.clear();
|
m_stream.clear();
|
||||||
m_stream.seekp(start);
|
m_stream.seekp(start);
|
||||||
@ -564,7 +562,6 @@ bool Parser<ParserPolicy>::testImpl(bool expectedValue)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,14 +1,12 @@
|
|||||||
#ifndef __PLASP__INPUT__PARSER_EXCEPTION_H
|
#ifndef __PARSE_BASE__PARSER_EXCEPTION_H
|
||||||
#define __PLASP__INPUT__PARSER_EXCEPTION_H
|
#define __PARSE_BASE__PARSER_EXCEPTION_H
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <plasp/input/Location.h>
|
#include <parsebase/Location.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace parsebase
|
||||||
{
|
|
||||||
namespace input
|
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -20,17 +18,17 @@ namespace input
|
|||||||
class ParserException: public std::exception
|
class ParserException: public std::exception
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ParserException(const input::Location &location)
|
explicit ParserException(const Location &location)
|
||||||
: ParserException(location, "unspecified parser error")
|
: ParserException(location, "unspecified parser error")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit ParserException(const input::Location &location, const char *message)
|
explicit ParserException(const Location &location, const char *message)
|
||||||
: ParserException(location, static_cast<std::string>(message))
|
: ParserException(location, static_cast<std::string>(message))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit ParserException(const input::Location &location, const std::string &message)
|
explicit ParserException(const Location &location, const std::string &message)
|
||||||
: m_location{location},
|
: m_location{location},
|
||||||
m_message{message},
|
m_message{message},
|
||||||
// TODO: refactor
|
// TODO: refactor
|
||||||
@ -48,7 +46,7 @@ class ParserException: public std::exception
|
|||||||
return m_plainMessage.c_str();
|
return m_plainMessage.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const input::Location &location() const
|
const Location &location() const
|
||||||
{
|
{
|
||||||
return m_location;
|
return m_location;
|
||||||
}
|
}
|
||||||
@ -59,14 +57,13 @@ class ParserException: public std::exception
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
input::Location m_location;
|
Location m_location;
|
||||||
std::string m_message;
|
std::string m_message;
|
||||||
std::string m_plainMessage;
|
std::string m_plainMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,11 +1,9 @@
|
|||||||
#ifndef __PLASP__INPUT__PARSER_POLICY_H
|
#ifndef __PARSE_BASE__PARSER_POLICY_H
|
||||||
#define __PLASP__INPUT__PARSER_POLICY_H
|
#define __PARSE_BASE__PARSER_POLICY_H
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace plasp
|
namespace parsebase
|
||||||
{
|
|
||||||
namespace input
|
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -66,7 +64,6 @@ class CaseInsensitiveParserPolicy
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,18 +1,15 @@
|
|||||||
#ifndef __PLASP__INPUT__STREAM_H
|
#ifndef __PARSE_BASE__STREAM_H
|
||||||
#define __PLASP__INPUT__STREAM_H
|
#define __PARSE_BASE__STREAM_H
|
||||||
|
|
||||||
|
#include <experimental/filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <parsebase/Location.h>
|
||||||
|
|
||||||
#include <plasp/input/Location.h>
|
namespace parsebase
|
||||||
|
|
||||||
namespace plasp
|
|
||||||
{
|
|
||||||
namespace input
|
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -56,7 +53,7 @@ class Stream
|
|||||||
~Stream() = default;
|
~Stream() = default;
|
||||||
|
|
||||||
void read(std::string streamName, std::istream &istream);
|
void read(std::string streamName, std::istream &istream);
|
||||||
void read(const boost::filesystem::path &path);
|
void read(const std::experimental::filesystem::path &path);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void seek(Position position);
|
void seek(Position position);
|
||||||
@ -77,7 +74,6 @@ class Stream
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
21
lib/parsebase/src/CMakeLists.txt
Normal file
21
lib/parsebase/src/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
set(target parsebase)
|
||||||
|
|
||||||
|
file(GLOB core_sources "parsebase/*.cpp")
|
||||||
|
file(GLOB core_headers "../include/parsebase/*.h")
|
||||||
|
|
||||||
|
set(includes
|
||||||
|
${PROJECT_SOURCE_DIR}/include
|
||||||
|
)
|
||||||
|
|
||||||
|
set(sources
|
||||||
|
${core_sources}
|
||||||
|
${core_headers}
|
||||||
|
)
|
||||||
|
|
||||||
|
set(libraries
|
||||||
|
stdc++fs
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(${target} ${sources})
|
||||||
|
target_include_directories(${target} PRIVATE ${includes})
|
||||||
|
target_link_libraries(${target} ${libraries})
|
@ -1,12 +1,11 @@
|
|||||||
#include <plasp/input/Stream.h>
|
#include <parsebase/Stream.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace parsebase
|
||||||
{
|
|
||||||
namespace input
|
|
||||||
{
|
{
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -44,9 +43,9 @@ void Stream::read(std::string streamName, std::istream &istream)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Stream::read(const boost::filesystem::path &path)
|
void Stream::read(const std::experimental::filesystem::path &path)
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::is_regular_file(path))
|
if (!std::experimental::filesystem::is_regular_file(path))
|
||||||
throw std::runtime_error("File does not exist: “" + path.string() + "”");
|
throw std::runtime_error("File does not exist: “" + path.string() + "”");
|
||||||
|
|
||||||
std::ifstream fileStream(path.string(), std::ios::in);
|
std::ifstream fileStream(path.string(), std::ios::in);
|
||||||
@ -161,4 +160,3 @@ void Stream::advance()
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
22
lib/parsebase/tests/CMakeLists.txt
Normal file
22
lib/parsebase/tests/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
set(target parsebase-tests)
|
||||||
|
|
||||||
|
file(GLOB core_sources "*.cpp")
|
||||||
|
|
||||||
|
set(includes
|
||||||
|
${Boost_INCLUDE_DIRS}
|
||||||
|
${PROJECT_SOURCE_DIR}/include
|
||||||
|
${PROJECT_SOURCE_DIR}/../../lib/catch/single_include
|
||||||
|
)
|
||||||
|
|
||||||
|
set(libraries
|
||||||
|
parsebase
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(${target} ${core_sources})
|
||||||
|
target_include_directories(${target} PRIVATE ${includes})
|
||||||
|
target_link_libraries(${target} ${libraries})
|
||||||
|
|
||||||
|
add_custom_target(run-parsebase-tests
|
||||||
|
COMMAND ${CMAKE_BINARY_DIR}/bin/parsebase-tests
|
||||||
|
DEPENDS ${target}
|
||||||
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/tests)
|
@ -1,14 +1,14 @@
|
|||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
|
|
||||||
#include <plasp/input/Parser.h>
|
#include <parsebase/Parser.h>
|
||||||
#include <plasp/input/ParserException.h>
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
|
TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
|
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
|
||||||
plasp::input::Parser<> p("input", s);
|
parsebase::Parser<> p("input", s);
|
||||||
|
|
||||||
REQUIRE(p.parse<std::string>() == "identifier");
|
REQUIRE(p.parse<std::string>() == "identifier");
|
||||||
REQUIRE(p.parse<size_t>() == 5u);
|
REQUIRE(p.parse<size_t>() == 5u);
|
||||||
@ -19,7 +19,7 @@ TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
|
|||||||
REQUIRE(p.parse<int>() == 100);
|
REQUIRE(p.parse<int>() == 100);
|
||||||
REQUIRE(p.parse<size_t>() == 200u);
|
REQUIRE(p.parse<size_t>() == 200u);
|
||||||
REQUIRE(p.parse<int>() == -300);
|
REQUIRE(p.parse<int>() == -300);
|
||||||
REQUIRE_THROWS_AS(p.parse<size_t>(), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.parse<size_t>(), parsebase::ParserException);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -27,7 +27,7 @@ TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
|
|||||||
TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
|
TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
|
std::stringstream s(" identifier 5 \n-51\t 0 1 100 200 -300 -400");
|
||||||
plasp::input::Parser<> p("input", s);
|
parsebase::Parser<> p("input", s);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p.expect<std::string>("identifier"));
|
REQUIRE_NOTHROW(p.expect<std::string>("identifier"));
|
||||||
REQUIRE_NOTHROW(p.expect<size_t>(5u));
|
REQUIRE_NOTHROW(p.expect<size_t>(5u));
|
||||||
@ -38,31 +38,31 @@ TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
|
|||||||
REQUIRE_NOTHROW(p.expect<int>(100));
|
REQUIRE_NOTHROW(p.expect<int>(100));
|
||||||
REQUIRE_NOTHROW(p.expect<size_t>(200u));
|
REQUIRE_NOTHROW(p.expect<size_t>(200u));
|
||||||
REQUIRE_NOTHROW(p.expect<int>(-300));
|
REQUIRE_NOTHROW(p.expect<int>(-300));
|
||||||
REQUIRE_THROWS_AS(p.expect<size_t>(-400), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.expect<size_t>(-400), parsebase::ParserException);
|
||||||
|
|
||||||
p.seek(0);
|
p.seek(0);
|
||||||
REQUIRE_THROWS_AS(p.expect<std::string>("error"), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.expect<std::string>("error"), parsebase::ParserException);
|
||||||
|
|
||||||
p.seek(14);
|
p.seek(14);
|
||||||
REQUIRE_THROWS_AS(p.expect<size_t>(6u), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.expect<size_t>(6u), parsebase::ParserException);
|
||||||
|
|
||||||
p.seek(17);
|
p.seek(17);
|
||||||
REQUIRE_THROWS_AS(p.expect<int>(-50), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.expect<int>(-50), parsebase::ParserException);
|
||||||
|
|
||||||
p.seek(24);
|
p.seek(24);
|
||||||
REQUIRE_THROWS_AS(p.expect<bool>(true), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.expect<bool>(true), parsebase::ParserException);
|
||||||
|
|
||||||
p.seek(26);
|
p.seek(26);
|
||||||
REQUIRE_THROWS_AS(p.expect<bool>(false), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.expect<bool>(false), parsebase::ParserException);
|
||||||
|
|
||||||
p.seek(28);
|
p.seek(28);
|
||||||
REQUIRE_THROWS_AS(p.expect<int>(101), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.expect<int>(101), parsebase::ParserException);
|
||||||
|
|
||||||
p.seek(31);
|
p.seek(31);
|
||||||
REQUIRE_THROWS_AS(p.expect<size_t>(201), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.expect<size_t>(201), parsebase::ParserException);
|
||||||
|
|
||||||
p.seek(34);
|
p.seek(34);
|
||||||
REQUIRE_THROWS_AS(p.expect<int>(-299), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p.expect<int>(-299), parsebase::ParserException);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -70,9 +70,9 @@ TEST_CASE("[parser] Parsing exceptions are correctly reported", "[parser]")
|
|||||||
TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser]")
|
TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s(" identifier 5 \n-51\t 0 1");
|
std::stringstream s(" identifier 5 \n-51\t 0 1");
|
||||||
plasp::input::Parser<> p("input", s);
|
parsebase::Parser<> p("input", s);
|
||||||
|
|
||||||
plasp::input::Parser<>::Position pos;
|
parsebase::Parser<>::Position pos;
|
||||||
|
|
||||||
pos = p.position();
|
pos = p.position();
|
||||||
REQUIRE(p.testAndReturn<std::string>("error") == false);
|
REQUIRE(p.testAndReturn<std::string>("error") == false);
|
||||||
@ -130,46 +130,46 @@ TEST_CASE("[parser] While parsing, the cursor position is as expected", "[parser
|
|||||||
TEST_CASE("[parser] The end of the input stream is correctly handled", "[parser]")
|
TEST_CASE("[parser] The end of the input stream is correctly handled", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s1("test");
|
std::stringstream s1("test");
|
||||||
plasp::input::Parser<> p1("input", s1);
|
parsebase::Parser<> p1("input", s1);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p1.expect<std::string>("test"));
|
REQUIRE_NOTHROW(p1.expect<std::string>("test"));
|
||||||
REQUIRE_THROWS_AS(p1.parse<std::string>(), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p1.parse<std::string>(), parsebase::ParserException);
|
||||||
|
|
||||||
std::stringstream s2("test1 test2 test3");
|
std::stringstream s2("test1 test2 test3");
|
||||||
plasp::input::Parser<> p2("input", s2);
|
parsebase::Parser<> p2("input", s2);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p2.expect<std::string>("test1"));
|
REQUIRE_NOTHROW(p2.expect<std::string>("test1"));
|
||||||
REQUIRE_NOTHROW(p2.expect<std::string>("test2"));
|
REQUIRE_NOTHROW(p2.expect<std::string>("test2"));
|
||||||
REQUIRE_NOTHROW(p2.expect<std::string>("test3"));
|
REQUIRE_NOTHROW(p2.expect<std::string>("test3"));
|
||||||
REQUIRE_THROWS_AS(p2.parse<std::string>(), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p2.parse<std::string>(), parsebase::ParserException);
|
||||||
|
|
||||||
std::stringstream s3("-127");
|
std::stringstream s3("-127");
|
||||||
plasp::input::Parser<> p3("input", s3);
|
parsebase::Parser<> p3("input", s3);
|
||||||
|
|
||||||
p3.expect<int>(-127);
|
p3.expect<int>(-127);
|
||||||
REQUIRE_THROWS_AS(p3.parse<int>(), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p3.parse<int>(), parsebase::ParserException);
|
||||||
|
|
||||||
std::stringstream s4("128 -1023 -4095");
|
std::stringstream s4("128 -1023 -4095");
|
||||||
plasp::input::Parser<> p4("input", s4);
|
parsebase::Parser<> p4("input", s4);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p4.expect<size_t>(128));
|
REQUIRE_NOTHROW(p4.expect<size_t>(128));
|
||||||
REQUIRE_NOTHROW(p4.expect<int>(-1023));
|
REQUIRE_NOTHROW(p4.expect<int>(-1023));
|
||||||
REQUIRE_NOTHROW(p4.expect<int>(-4095));
|
REQUIRE_NOTHROW(p4.expect<int>(-4095));
|
||||||
REQUIRE_THROWS_AS(p4.parse<int>(), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p4.parse<int>(), parsebase::ParserException);
|
||||||
|
|
||||||
std::stringstream s5("0");
|
std::stringstream s5("0");
|
||||||
plasp::input::Parser<> p5("input", s5);
|
parsebase::Parser<> p5("input", s5);
|
||||||
|
|
||||||
p5.expect<bool>(false);
|
p5.expect<bool>(false);
|
||||||
REQUIRE_THROWS_AS(p5.parse<bool>(), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p5.parse<bool>(), parsebase::ParserException);
|
||||||
|
|
||||||
std::stringstream s6("0 1 0");
|
std::stringstream s6("0 1 0");
|
||||||
plasp::input::Parser<> p6("input", s6);
|
parsebase::Parser<> p6("input", s6);
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p6.expect<bool>(false));
|
REQUIRE_NOTHROW(p6.expect<bool>(false));
|
||||||
REQUIRE_NOTHROW(p6.expect<bool>(true));
|
REQUIRE_NOTHROW(p6.expect<bool>(true));
|
||||||
REQUIRE_NOTHROW(p6.expect<bool>(false));
|
REQUIRE_NOTHROW(p6.expect<bool>(false));
|
||||||
REQUIRE_THROWS_AS(p6.parse<bool>(), plasp::input::ParserException);
|
REQUIRE_THROWS_AS(p6.parse<bool>(), parsebase::ParserException);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -177,11 +177,11 @@ TEST_CASE("[parser] The end of the input stream is correctly handled", "[parser]
|
|||||||
TEST_CASE("[parser] While parsing, the cursor location is as expcected", "[parser]")
|
TEST_CASE("[parser] While parsing, the cursor location is as expcected", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s("123 \n4\ntest1\n test2\ntest3 \ntest4\n\n\n\n");
|
std::stringstream s("123 \n4\ntest1\n test2\ntest3 \ntest4\n\n\n\n");
|
||||||
plasp::input::Parser<> p("input", s);
|
parsebase::Parser<> p("input", s);
|
||||||
|
|
||||||
const auto startPosition = p.position();
|
const auto startPosition = p.position();
|
||||||
|
|
||||||
plasp::input::Location l;
|
parsebase::Location l;
|
||||||
|
|
||||||
l = p.location();
|
l = p.location();
|
||||||
REQUIRE(l.rowStart == 1u);
|
REQUIRE(l.rowStart == 1u);
|
||||||
@ -285,11 +285,11 @@ TEST_CASE("[parser] While parsing, the cursor location is as expcected", "[parse
|
|||||||
TEST_CASE("[parser] Comments are correctly removed", "[parser]")
|
TEST_CASE("[parser] Comments are correctly removed", "[parser]")
|
||||||
{
|
{
|
||||||
std::stringstream s1("; comment at beginning\ntest1; comment in between\ntest2; comment at end");
|
std::stringstream s1("; comment at beginning\ntest1; comment in between\ntest2; comment at end");
|
||||||
plasp::input::Parser<> p1("input", s1);
|
parsebase::Parser<> p1("input", s1);
|
||||||
|
|
||||||
p1.removeComments(";", "\n", false);
|
p1.removeComments(";", "\n", false);
|
||||||
|
|
||||||
plasp::input::Location l;
|
parsebase::Location l;
|
||||||
|
|
||||||
REQUIRE_NOTHROW(p1.expect<std::string>("test1"));
|
REQUIRE_NOTHROW(p1.expect<std::string>("test1"));
|
||||||
|
|
||||||
@ -308,7 +308,7 @@ TEST_CASE("[parser] Comments are correctly removed", "[parser]")
|
|||||||
REQUIRE(p1.atEnd());
|
REQUIRE(p1.atEnd());
|
||||||
|
|
||||||
std::stringstream s2("test;");
|
std::stringstream s2("test;");
|
||||||
plasp::input::Parser<> p2("input", s2);
|
parsebase::Parser<> p2("input", s2);
|
||||||
|
|
||||||
p2.removeComments(";", "\n", false);
|
p2.removeComments(";", "\n", false);
|
||||||
|
|
||||||
@ -319,7 +319,7 @@ TEST_CASE("[parser] Comments are correctly removed", "[parser]")
|
|||||||
REQUIRE(p2.atEnd());
|
REQUIRE(p2.atEnd());
|
||||||
|
|
||||||
std::stringstream s3("/* comment at start */ test1 /* comment in between */ test2 /*");
|
std::stringstream s3("/* comment at start */ test1 /* comment in between */ test2 /*");
|
||||||
plasp::input::Parser<> p3("input", s3);
|
parsebase::Parser<> p3("input", s3);
|
||||||
|
|
||||||
p3.removeComments("/*", "*/", true);
|
p3.removeComments("/*", "*/", true);
|
||||||
|
|
2
lib/parsebase/tests/main.cpp
Normal file
2
lib/parsebase/tests/main.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include <catch.hpp>
|
@ -27,6 +27,7 @@ file(GLOB utils_headers "../include/plasp/utils/*.h")
|
|||||||
set(includes
|
set(includes
|
||||||
${Boost_INCLUDE_DIRS}
|
${Boost_INCLUDE_DIRS}
|
||||||
${PROJECT_SOURCE_DIR}/include
|
${PROJECT_SOURCE_DIR}/include
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/parsebase/include
|
||||||
)
|
)
|
||||||
|
|
||||||
set(sources
|
set(sources
|
||||||
@ -57,6 +58,7 @@ set(sources
|
|||||||
|
|
||||||
set(libraries
|
set(libraries
|
||||||
${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
|
parsebase
|
||||||
pthread
|
pthread
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ void Logger::log(Priority priority, const std::string &message)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Logger::log(Priority priority, const input::Location &location, const char *message)
|
void Logger::log(Priority priority, const parsebase::Location &location, const char *message)
|
||||||
{
|
{
|
||||||
const auto priorityID = static_cast<int>(priority);
|
const auto priorityID = static_cast<int>(priority);
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ void Logger::log(Priority priority, const input::Location &location, const char
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Logger::log(Priority priority, const input::Location &location, const std::string &message)
|
void Logger::log(Priority priority, const parsebase::Location &location, const std::string &message)
|
||||||
{
|
{
|
||||||
log(priority, location, message.c_str());
|
log(priority, location, message.c_str());
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,11 @@
|
|||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/pddl/ConsistencyException.h>
|
#include <plasp/pddl/ConsistencyException.h>
|
||||||
#include <plasp/pddl/IO.h>
|
#include <plasp/pddl/IO.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
@ -168,7 +169,7 @@ void Description::findSections()
|
|||||||
if (parser.testAndSkip<std::string>("domain"))
|
if (parser.testAndSkip<std::string>("domain"))
|
||||||
{
|
{
|
||||||
if (m_domainPosition != -1)
|
if (m_domainPosition != -1)
|
||||||
throw input::ParserException(parser.location(), "PDDL description may not contain two domains");
|
throw parsebase::ParserException(parser.location(), "PDDL description may not contain two domains");
|
||||||
|
|
||||||
m_domainPosition = position;
|
m_domainPosition = position;
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ void Description::findSections()
|
|||||||
else if (m_context.parser.testAndSkip<std::string>("problem"))
|
else if (m_context.parser.testAndSkip<std::string>("problem"))
|
||||||
{
|
{
|
||||||
if (m_problemPosition != -1)
|
if (m_problemPosition != -1)
|
||||||
throw input::ParserException(parser.location(), "PDDL description may currently not contain two problems");
|
throw parsebase::ParserException(parser.location(), "PDDL description may currently not contain two problems");
|
||||||
|
|
||||||
m_problem = std::make_unique<Problem>(Problem(m_context, *m_domain));
|
m_problem = std::make_unique<Problem>(Problem(m_context, *m_domain));
|
||||||
|
|
||||||
@ -190,7 +191,7 @@ void Description::findSections()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto sectionIdentifier = parser.parse<std::string>();
|
const auto sectionIdentifier = parser.parse<std::string>();
|
||||||
throw input::ParserException(parser.location(), "unknown PDDL section “" + sectionIdentifier + "”");
|
throw parsebase::ParserException(parser.location(), "unknown PDDL section “" + sectionIdentifier + "”");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_context.parser.skipWhiteSpace();
|
m_context.parser.skipWhiteSpace();
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/pddl/ConsistencyException.h>
|
#include <plasp/pddl/ConsistencyException.h>
|
||||||
#include <plasp/pddl/IO.h>
|
#include <plasp/pddl/IO.h>
|
||||||
#include <plasp/pddl/expressions/Constant.h>
|
#include <plasp/pddl/expressions/Constant.h>
|
||||||
@ -10,6 +9,8 @@
|
|||||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||||
#include <plasp/pddl/expressions/Variable.h>
|
#include <plasp/pddl/expressions/Variable.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
@ -51,7 +52,7 @@ void Domain::findSections()
|
|||||||
if (unique && sectionPosition != -1)
|
if (unique && sectionPosition != -1)
|
||||||
{
|
{
|
||||||
parser.seek(value);
|
parser.seek(value);
|
||||||
throw input::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
|
throw parsebase::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
sectionPosition = value;
|
sectionPosition = value;
|
||||||
@ -101,7 +102,7 @@ void Domain::findSections()
|
|||||||
const auto sectionIdentifier = parser.parseIdentifier();
|
const auto sectionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
parser.seek(position);
|
||||||
throw input::ParserException(parser.location(), "unknown domain section “" + sectionIdentifier + "”");
|
throw parsebase::ParserException(parser.location(), "unknown domain section “" + sectionIdentifier + "”");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip section for now and parse it later
|
// Skip section for now and parse it later
|
||||||
@ -354,7 +355,7 @@ void Domain::parseTypeSection()
|
|||||||
while (parser.currentCharacter() != ')')
|
while (parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
if (parser.currentCharacter() == '(')
|
if (parser.currentCharacter() == '(')
|
||||||
throw input::ParserException(parser.location(), "only primitive types are allowed in type section");
|
throw parsebase::ParserException(parser.location(), "only primitive types are allowed in type section");
|
||||||
|
|
||||||
expressions::PrimitiveType::parseTypedDeclaration(m_context, *this);
|
expressions::PrimitiveType::parseTypedDeclaration(m_context, *this);
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include <plasp/pddl/Expression.h>
|
#include <plasp/pddl/Expression.h>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/output/TranslatorException.h>
|
#include <plasp/output/TranslatorException.h>
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
@ -17,6 +16,8 @@
|
|||||||
#include <plasp/pddl/expressions/Unsupported.h>
|
#include <plasp/pddl/expressions/Unsupported.h>
|
||||||
#include <plasp/pddl/expressions/When.h>
|
#include <plasp/pddl/expressions/When.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
@ -181,7 +182,7 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio
|
|||||||
const auto expressionIdentifier = parser.parseIdentifier();
|
const auto expressionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
parser.seek(position);
|
||||||
throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
throw parsebase::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -256,7 +257,7 @@ ExpressionPointer parseEffectBodyExpression(Context &context, ExpressionContext
|
|||||||
const auto expressionIdentifier = parser.parseIdentifier();
|
const auto expressionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
parser.seek(position);
|
||||||
throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
throw parsebase::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -282,7 +283,7 @@ ExpressionPointer parsePredicate(Context &context, ExpressionContext &expression
|
|||||||
if ((expression = expressions::Predicate::parse(context, expressionContext)))
|
if ((expression = expressions::Predicate::parse(context, expressionContext)))
|
||||||
return expression;
|
return expression;
|
||||||
|
|
||||||
throw input::ParserException(parser.location(), "expected predicate");
|
throw parsebase::ParserException(parser.location(), "expected predicate");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include <plasp/pddl/InitialState.h>
|
#include <plasp/pddl/InitialState.h>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
#include <plasp/pddl/IO.h>
|
#include <plasp/pddl/IO.h>
|
||||||
@ -9,6 +8,8 @@
|
|||||||
#include <plasp/pddl/expressions/Predicate.h>
|
#include <plasp/pddl/expressions/Predicate.h>
|
||||||
#include <plasp/pddl/expressions/Unsupported.h>
|
#include <plasp/pddl/expressions/Unsupported.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
@ -58,7 +59,7 @@ std::unique_ptr<InitialState> InitialState::parseDeclaration(Context &context,
|
|||||||
const auto expressionIdentifier = parser.parseIdentifier();
|
const auto expressionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
parser.seek(position);
|
||||||
throw input::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
throw parsebase::ParserException(parser.location(), "expression type “" + expressionIdentifier + "” unknown or not allowed in this context");
|
||||||
};
|
};
|
||||||
|
|
||||||
parser.skipWhiteSpace();
|
parser.skipWhiteSpace();
|
||||||
|
@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/pddl/ConsistencyException.h>
|
#include <plasp/pddl/ConsistencyException.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
#include <plasp/pddl/IO.h>
|
#include <plasp/pddl/IO.h>
|
||||||
#include <plasp/pddl/expressions/Constant.h>
|
#include <plasp/pddl/expressions/Constant.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
@ -52,7 +53,7 @@ void Problem::findSections()
|
|||||||
if (unique && sectionPosition != -1)
|
if (unique && sectionPosition != -1)
|
||||||
{
|
{
|
||||||
parser.seek(value);
|
parser.seek(value);
|
||||||
throw input::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
|
throw parsebase::ParserException(parser.location(), "only one “:" + sectionName + "” section allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
sectionPosition = value;
|
sectionPosition = value;
|
||||||
@ -97,7 +98,7 @@ void Problem::findSections()
|
|||||||
const auto sectionIdentifier = parser.parseIdentifier();
|
const auto sectionIdentifier = parser.parseIdentifier();
|
||||||
|
|
||||||
parser.seek(position);
|
parser.seek(position);
|
||||||
throw input::ParserException(parser.location(), "unknown problem section “" + sectionIdentifier + "”");
|
throw parsebase::ParserException(parser.location(), "unknown problem section “" + sectionIdentifier + "”");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip section for now and parse it later
|
// Skip section for now and parse it later
|
||||||
@ -203,7 +204,7 @@ void Problem::parseDomainSection()
|
|||||||
const auto domainName = parser.parseIdentifier();
|
const auto domainName = parser.parseIdentifier();
|
||||||
|
|
||||||
if (m_domain.name() != domainName)
|
if (m_domain.name() != domainName)
|
||||||
throw input::ParserException(parser.location(), "domains do not match (“" + m_domain.name() + "” and “" + domainName + "”)");
|
throw parsebase::ParserException(parser.location(), "domains do not match (“" + m_domain.name() + "” and “" + domainName + "”)");
|
||||||
|
|
||||||
parser.expect<std::string>(")");
|
parser.expect<std::string>(")");
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <boost/assign.hpp>
|
#include <boost/assign.hpp>
|
||||||
#include <boost/bimap.hpp>
|
#include <boost/bimap.hpp>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -89,7 +89,7 @@ Requirement Requirement::parse(Context &context)
|
|||||||
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 input::ParserException(parser.location(), "unknown PDDL requirement “" + requirementName + "”");
|
throw parsebase::ParserException(parser.location(), "unknown PDDL requirement “" + requirementName + "”");
|
||||||
|
|
||||||
const auto requirementType = match->second;
|
const auto requirementType = match->second;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ expressions::VariablePointer VariableStack::parseAndFind(plasp::pddl::Context &c
|
|||||||
return match->get();
|
return match->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw input::ParserException(parser.location(), "variable “" + variableName + "” used but never declared");
|
throw parsebase::ParserException(parser.location(), "variable “" + variableName + "” used but never declared");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
#include <plasp/pddl/Problem.h>
|
#include <plasp/pddl/Problem.h>
|
||||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
@ -114,7 +115,7 @@ void Constant::parseTypedDeclarations(Context &context, Domain &domain)
|
|||||||
domain.checkRequirement(Requirement::Type::Typing);
|
domain.checkRequirement(Requirement::Type::Typing);
|
||||||
// If no types are given, check that typing is not a requirement
|
// If no types are given, check that typing is not a requirement
|
||||||
else if (domain.hasRequirement(Requirement::Type::Typing))
|
else if (domain.hasRequirement(Requirement::Type::Typing))
|
||||||
throw input::ParserException(parser.location(), "constant has undeclared type");
|
throw parsebase::ParserException(parser.location(), "constant has undeclared type");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -141,7 +142,7 @@ void Constant::parseTypedDeclarations(Context &context, Problem &problem)
|
|||||||
problem.checkRequirement(Requirement::Type::Typing);
|
problem.checkRequirement(Requirement::Type::Typing);
|
||||||
// If no types are given, check that typing is not a requirement
|
// If no types are given, check that typing is not a requirement
|
||||||
else if (problem.hasRequirement(Requirement::Type::Typing))
|
else if (problem.hasRequirement(Requirement::Type::Typing))
|
||||||
throw input::ParserException(parser.location(), "constant has undeclared type");
|
throw parsebase::ParserException(parser.location(), "constant has undeclared type");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -159,7 +160,7 @@ ConstantPointer Constant::parseAndFind(Context &context, const Domain &domain)
|
|||||||
if (constant != nullptr)
|
if (constant != nullptr)
|
||||||
return constant;
|
return constant;
|
||||||
|
|
||||||
throw input::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
|
throw parsebase::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -182,7 +183,7 @@ ConstantPointer Constant::parseAndFind(Context &context, const Problem &problem)
|
|||||||
if (constant)
|
if (constant)
|
||||||
return constant;
|
return constant;
|
||||||
|
|
||||||
throw input::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
|
throw parsebase::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -126,7 +126,7 @@ PredicatePointer Predicate::parse(Context &context, const Problem &problem)
|
|||||||
while (parser.currentCharacter() != ')')
|
while (parser.currentCharacter() != ')')
|
||||||
{
|
{
|
||||||
if (parser.currentCharacter() == '?')
|
if (parser.currentCharacter() == '?')
|
||||||
throw input::ParserException(parser.location(), "variables not allowed in this context");
|
throw parsebase::ParserException(parser.location(), "variables not allowed in this context");
|
||||||
|
|
||||||
// Parse objects and constants
|
// Parse objects and constants
|
||||||
const auto constant = Constant::parseAndFind(context, problem);
|
const auto constant = Constant::parseAndFind(context, problem);
|
||||||
|
@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
@ -112,7 +113,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
|
|||||||
const auto typeName = parser.parseIdentifier();
|
const auto typeName = parser.parseIdentifier();
|
||||||
|
|
||||||
if (typeName.empty())
|
if (typeName.empty())
|
||||||
throw input::ParserException(parser.location(), "no type supplied");
|
throw parsebase::ParserException(parser.location(), "no type supplied");
|
||||||
|
|
||||||
const auto match = std::find_if(types.cbegin(), types.cend(),
|
const auto match = std::find_if(types.cbegin(), types.cend(),
|
||||||
[&](const auto &primitiveType)
|
[&](const auto &primitiveType)
|
||||||
@ -129,7 +130,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
|
|||||||
types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
|
types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw input::ParserException(parser.location(), "type “" + typeName + "” used but never declared");
|
throw parsebase::ParserException(parser.location(), "type “" + typeName + "” used but never declared");
|
||||||
|
|
||||||
return types.back().get();
|
return types.back().get();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/pddl/Context.h>
|
#include <plasp/pddl/Context.h>
|
||||||
#include <plasp/pddl/Domain.h>
|
#include <plasp/pddl/Domain.h>
|
||||||
#include <plasp/pddl/ExpressionContext.h>
|
#include <plasp/pddl/ExpressionContext.h>
|
||||||
@ -12,6 +11,8 @@
|
|||||||
#include <plasp/pddl/expressions/PrimitiveType.h>
|
#include <plasp/pddl/expressions/PrimitiveType.h>
|
||||||
#include <plasp/pddl/expressions/Type.h>
|
#include <plasp/pddl/expressions/Type.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace pddl
|
namespace pddl
|
||||||
@ -60,7 +61,7 @@ void Variable::parseDeclaration(Context &context, Variables ¶meters)
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (match != parameters.cend())
|
if (match != parameters.cend())
|
||||||
throw input::ParserException(parser.location(), "variable “" + variable->m_name + "” already declared in this scope");
|
throw parsebase::ParserException(parser.location(), "variable “" + variable->m_name + "” already declared in this scope");
|
||||||
|
|
||||||
// Flag variable for potentially upcoming type declaration
|
// Flag variable for potentially upcoming type declaration
|
||||||
variable->setDirty();
|
variable->setDirty();
|
||||||
@ -137,7 +138,7 @@ void Variable::parseTypedDeclarations(Context &context, ExpressionContext &expre
|
|||||||
expressionContext.checkRequirement(Requirement::Type::Typing);
|
expressionContext.checkRequirement(Requirement::Type::Typing);
|
||||||
// If no types are given, check that typing is not a requirement
|
// If no types are given, check that typing is not a requirement
|
||||||
else if (expressionContext.hasRequirement(Requirement::Type::Typing))
|
else if (expressionContext.hasRequirement(Requirement::Type::Typing))
|
||||||
throw input::ParserException(parser.location(), "variable has undeclared type");
|
throw parsebase::ParserException(parser.location(), "variable has undeclared type");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -31,7 +31,7 @@ AssignedVariable::AssignedVariable(const Variable &variable, const Value &value)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variables &variables)
|
AssignedVariable AssignedVariable::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
|
||||||
{
|
{
|
||||||
AssignedVariable assignedVariable;
|
AssignedVariable assignedVariable;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variab
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AssignedVariable AssignedVariable::fromSAS(input::Parser<> &parser, const Variable &variable)
|
AssignedVariable AssignedVariable::fromSAS(parsebase::Parser<> &parser, const Variable &variable)
|
||||||
{
|
{
|
||||||
AssignedVariable assignedVariable;
|
AssignedVariable assignedVariable;
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ AxiomRule::AxiomRule(AxiomRule::Conditions conditions, AxiomRule::Condition post
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
AxiomRule AxiomRule::fromSAS(input::Parser<> &parser, const Variables &variables)
|
AxiomRule AxiomRule::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("begin_rule");
|
parser.expect<std::string>("begin_rule");
|
||||||
|
|
||||||
|
@ -5,11 +5,10 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/sas/VariableTransition.h>
|
#include <plasp/sas/VariableTransition.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -28,7 +27,7 @@ Description::Description()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Description Description::fromParser(input::Parser<> &&parser)
|
Description Description::fromParser(parsebase::Parser<> &&parser)
|
||||||
{
|
{
|
||||||
Description description;
|
Description description;
|
||||||
description.parseContent(parser);
|
description.parseContent(parser);
|
||||||
@ -40,7 +39,7 @@ Description Description::fromParser(input::Parser<> &&parser)
|
|||||||
|
|
||||||
Description Description::fromStream(std::istream &istream)
|
Description Description::fromStream(std::istream &istream)
|
||||||
{
|
{
|
||||||
input::Parser<> parser;
|
parsebase::Parser<> parser;
|
||||||
parser.read("std::cin", istream);
|
parser.read("std::cin", istream);
|
||||||
|
|
||||||
Description description;
|
Description description;
|
||||||
@ -51,12 +50,12 @@ Description Description::fromStream(std::istream &istream)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Description Description::fromFile(const boost::filesystem::path &path)
|
Description Description::fromFile(const std::experimental::filesystem::path &path)
|
||||||
{
|
{
|
||||||
if (!boost::filesystem::is_regular_file(path))
|
if (!std::experimental::filesystem::is_regular_file(path))
|
||||||
throw std::runtime_error("File does not exist: “" + path.string() + "”");
|
throw std::runtime_error("File does not exist: “" + path.string() + "”");
|
||||||
|
|
||||||
input::Parser<> parser;
|
parsebase::Parser<> parser;
|
||||||
parser.read(path);
|
parser.read(path);
|
||||||
|
|
||||||
Description description;
|
Description description;
|
||||||
@ -160,7 +159,7 @@ bool Description::hasRequirements() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseContent(input::Parser<> &parser)
|
void Description::parseContent(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
parseVersionSection(parser);
|
parseVersionSection(parser);
|
||||||
parseMetricSection(parser);
|
parseMetricSection(parser);
|
||||||
@ -174,26 +173,26 @@ void Description::parseContent(input::Parser<> &parser)
|
|||||||
parser.skipWhiteSpace();
|
parser.skipWhiteSpace();
|
||||||
|
|
||||||
if (!parser.atEnd())
|
if (!parser.atEnd())
|
||||||
throw input::ParserException(parser.location(), "expected end of SAS description (perhaps, input contains two SAS descriptions?)");
|
throw parsebase::ParserException(parser.location(), "expected end of SAS description (perhaps, input contains two SAS descriptions?)");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseVersionSection(input::Parser<> &parser) const
|
void Description::parseVersionSection(parsebase::Parser<> &parser) const
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("begin_version");
|
parser.expect<std::string>("begin_version");
|
||||||
|
|
||||||
const auto formatVersion = parser.parse<size_t>();
|
const auto formatVersion = parser.parse<size_t>();
|
||||||
|
|
||||||
if (formatVersion != 3)
|
if (formatVersion != 3)
|
||||||
throw input::ParserException(parser.location(), "unsupported SAS format version (" + std::to_string(formatVersion) + ")");
|
throw parsebase::ParserException(parser.location(), "unsupported SAS format version (" + std::to_string(formatVersion) + ")");
|
||||||
|
|
||||||
parser.expect<std::string>("end_version");
|
parser.expect<std::string>("end_version");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseMetricSection(input::Parser<> &parser)
|
void Description::parseMetricSection(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
parser.expect<std::string>("begin_metric");
|
parser.expect<std::string>("begin_metric");
|
||||||
|
|
||||||
@ -204,7 +203,7 @@ void Description::parseMetricSection(input::Parser<> &parser)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseVariablesSection(input::Parser<> &parser)
|
void Description::parseVariablesSection(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
const auto numberOfVariables = parser.parse<size_t>();
|
const auto numberOfVariables = parser.parse<size_t>();
|
||||||
m_variables.reserve(numberOfVariables);
|
m_variables.reserve(numberOfVariables);
|
||||||
@ -215,7 +214,7 @@ void Description::parseVariablesSection(input::Parser<> &parser)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseMutexSection(input::Parser<> &parser)
|
void Description::parseMutexSection(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
const auto numberOfMutexGroups = parser.parse<size_t>();
|
const auto numberOfMutexGroups = parser.parse<size_t>();
|
||||||
m_mutexGroups.reserve(numberOfMutexGroups);
|
m_mutexGroups.reserve(numberOfMutexGroups);
|
||||||
@ -226,21 +225,21 @@ void Description::parseMutexSection(input::Parser<> &parser)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseInitialStateSection(input::Parser<> &parser)
|
void Description::parseInitialStateSection(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
m_initialState = std::make_unique<InitialState>(InitialState::fromSAS(parser, m_variables));
|
m_initialState = std::make_unique<InitialState>(InitialState::fromSAS(parser, m_variables));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseGoalSection(input::Parser<> &parser)
|
void Description::parseGoalSection(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
m_goal = std::make_unique<Goal>(Goal::fromSAS(parser, m_variables));
|
m_goal = std::make_unique<Goal>(Goal::fromSAS(parser, m_variables));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseOperatorSection(input::Parser<> &parser)
|
void Description::parseOperatorSection(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
const auto numberOfOperators = parser.parse<size_t>();
|
const auto numberOfOperators = parser.parse<size_t>();
|
||||||
m_operators.reserve(numberOfOperators);
|
m_operators.reserve(numberOfOperators);
|
||||||
@ -251,7 +250,7 @@ void Description::parseOperatorSection(input::Parser<> &parser)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void Description::parseAxiomSection(input::Parser<> &parser)
|
void Description::parseAxiomSection(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
const auto numberOfAxiomRules = parser.parse<size_t>();
|
const auto numberOfAxiomRules = parser.parse<size_t>();
|
||||||
m_axiomRules.reserve(numberOfAxiomRules);
|
m_axiomRules.reserve(numberOfAxiomRules);
|
||||||
|
@ -23,7 +23,7 @@ Effect::Effect(Conditions conditions, Condition postcondition)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Effect Effect::fromSAS(input::Parser<> &parser, const Variables &variables, Conditions &preconditions)
|
Effect Effect::fromSAS(parsebase::Parser<> &parser, const Variables &variables, Conditions &preconditions)
|
||||||
{
|
{
|
||||||
Effect::Conditions conditions;
|
Effect::Conditions conditions;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Goal Goal::fromSAS(input::Parser<> &parser, const Variables &variables)
|
Goal Goal::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
|
||||||
{
|
{
|
||||||
Goal goal;
|
Goal goal;
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
InitialState InitialState::fromSAS(input::Parser<> &parser, const Variables &variables)
|
InitialState InitialState::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
|
||||||
{
|
{
|
||||||
InitialState initialState;
|
InitialState initialState;
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
@ -15,7 +15,7 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
MutexGroup MutexGroup::fromSAS(input::Parser<> &parser, const Variables &variables)
|
MutexGroup MutexGroup::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
|
||||||
{
|
{
|
||||||
MutexGroup mutexGroup;
|
MutexGroup mutexGroup;
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ MutexGroup MutexGroup::fromSAS(input::Parser<> &parser, const Variables &variabl
|
|||||||
mutexGroup.m_facts.emplace_back(Fact::fromSAS(parser, variables));
|
mutexGroup.m_facts.emplace_back(Fact::fromSAS(parser, variables));
|
||||||
|
|
||||||
if (mutexGroup.m_facts[j].value() == Value::None)
|
if (mutexGroup.m_facts[j].value() == Value::None)
|
||||||
throw input::ParserException(parser.location(), "mutex groups must not contain <none of those> values");
|
throw parsebase::ParserException(parser.location(), "mutex groups must not contain <none of those> values");
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.expect<std::string>("end_mutex_group");
|
parser.expect<std::string>("end_mutex_group");
|
||||||
|
@ -17,7 +17,7 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Operator Operator::fromSAS(input::Parser<> &parser, const Variables &variables)
|
Operator Operator::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
|
||||||
{
|
{
|
||||||
Operator operator_;
|
Operator operator_;
|
||||||
|
|
||||||
|
@ -4,9 +4,10 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/output/Formatting.h>
|
#include <plasp/output/Formatting.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -18,7 +19,7 @@ namespace sas
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Predicate Predicate::fromSAS(input::Parser<> &parser)
|
Predicate Predicate::fromSAS(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
Predicate predicate;
|
Predicate predicate;
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ Predicate Predicate::fromSAS(input::Parser<> &parser)
|
|||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
throw input::ParserException(parser.location(), "could not parse operator predicate");
|
throw parsebase::ParserException(parser.location(), "could not parse operator predicate");
|
||||||
}
|
}
|
||||||
|
|
||||||
return predicate;
|
return predicate;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include <plasp/sas/TranslatorASP.h>
|
#include <plasp/sas/TranslatorASP.h>
|
||||||
|
|
||||||
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
#include <plasp/output/Formatting.h>
|
#include <plasp/output/Formatting.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
|
@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/output/Formatting.h>
|
#include <plasp/output/Formatting.h>
|
||||||
#include <plasp/sas/Variable.h>
|
#include <plasp/sas/Variable.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -54,7 +55,7 @@ Value Value::negated() const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Value Value::fromSAS(input::Parser<> &parser)
|
Value Value::fromSAS(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
const auto sasSign = parser.parse<std::string>();
|
const auto sasSign = parser.parse<std::string>();
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ Value Value::fromSAS(input::Parser<> &parser)
|
|||||||
else if (sasSign == "NegatedAtom")
|
else if (sasSign == "NegatedAtom")
|
||||||
value.m_sign = Value::Sign::Negative;
|
value.m_sign = Value::Sign::Negative;
|
||||||
else
|
else
|
||||||
throw input::ParserException(parser.location(), "invalid value sign “" + sasSign + "”");
|
throw parsebase::ParserException(parser.location(), "invalid value sign “" + sasSign + "”");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -90,7 +91,7 @@ Value Value::fromSAS(input::Parser<> &parser)
|
|||||||
}
|
}
|
||||||
catch (const std::exception &e)
|
catch (const std::exception &e)
|
||||||
{
|
{
|
||||||
throw input::ParserException(parser.location(), std::string("could not parse variable value (") + e.what() + ")");
|
throw parsebase::ParserException(parser.location(), std::string("could not parse variable value (") + e.what() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
@ -98,7 +99,7 @@ Value Value::fromSAS(input::Parser<> &parser)
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const Value &Value::referenceFromSAS(input::Parser<> &parser, const Variable &variable)
|
const Value &Value::referenceFromSAS(parsebase::Parser<> &parser, const Variable &variable)
|
||||||
{
|
{
|
||||||
const auto valueID = parser.parse<int>();
|
const auto valueID = parser.parse<int>();
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ const Value &Value::referenceFromSAS(input::Parser<> &parser, const Variable &va
|
|||||||
return Value::Any;
|
return Value::Any;
|
||||||
|
|
||||||
if (valueID < 0 || static_cast<size_t>(valueID) >= variable.values().size())
|
if (valueID < 0 || static_cast<size_t>(valueID) >= variable.values().size())
|
||||||
throw input::ParserException(parser.location(), "value index out of range (variable " + variable.name() + ", index " + std::to_string(valueID) + ")");
|
throw parsebase::ParserException(parser.location(), "value index out of range (variable " + variable.name() + ", index " + std::to_string(valueID) + ")");
|
||||||
|
|
||||||
return variable.values()[valueID];
|
return variable.values()[valueID];
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <plasp/input/ParserException.h>
|
|
||||||
#include <plasp/output/Formatting.h>
|
#include <plasp/output/Formatting.h>
|
||||||
|
|
||||||
|
#include <parsebase/ParserException.h>
|
||||||
|
|
||||||
namespace plasp
|
namespace plasp
|
||||||
{
|
{
|
||||||
namespace sas
|
namespace sas
|
||||||
@ -23,7 +24,7 @@ Variable::Variable()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Variable Variable::fromSAS(input::Parser<> &parser)
|
Variable Variable::fromSAS(parsebase::Parser<> &parser)
|
||||||
{
|
{
|
||||||
Variable variable;
|
Variable variable;
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ Variable Variable::fromSAS(input::Parser<> &parser)
|
|||||||
|
|
||||||
// <none of those> values are only allowed at the end
|
// <none of those> values are only allowed at the end
|
||||||
if (j < numberOfValues - 1 && variable.m_values[j] == Value::None)
|
if (j < numberOfValues - 1 && variable.m_values[j] == Value::None)
|
||||||
throw input::ParserException(parser.location(), "<none of those> value must be the last value of a variable");
|
throw parsebase::ParserException(parser.location(), "<none of those> value must be the last value of a variable");
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.expect<std::string>("end_variable");
|
parser.expect<std::string>("end_variable");
|
||||||
@ -60,12 +61,12 @@ void Variable::printNameAsASPPredicate(output::ColorStream &stream) const
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
const Variable &Variable::referenceFromSAS(input::Parser<> &parser, const Variables &variables)
|
const Variable &Variable::referenceFromSAS(parsebase::Parser<> &parser, const Variables &variables)
|
||||||
{
|
{
|
||||||
const auto variableID = parser.parse<size_t>();
|
const auto variableID = parser.parse<size_t>();
|
||||||
|
|
||||||
if (variableID >= variables.size())
|
if (variableID >= variables.size())
|
||||||
throw input::ParserException(parser.location(), "variable index out of range (index " + std::to_string(variableID) + ")");
|
throw parsebase::ParserException(parser.location(), "variable index out of range (index " + std::to_string(variableID) + ")");
|
||||||
|
|
||||||
return variables[variableID];
|
return variables[variableID];
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ VariableTransition::VariableTransition()
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
VariableTransition VariableTransition::fromSAS(input::Parser<> &parser, const Variables &variables)
|
VariableTransition VariableTransition::fromSAS(parsebase::Parser<> &parser, const Variables &variables)
|
||||||
{
|
{
|
||||||
VariableTransition variableTransition;
|
VariableTransition variableTransition;
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ set(includes
|
|||||||
${Boost_INCLUDE_DIRS}
|
${Boost_INCLUDE_DIRS}
|
||||||
${PROJECT_SOURCE_DIR}/include
|
${PROJECT_SOURCE_DIR}/include
|
||||||
${PROJECT_SOURCE_DIR}/lib/catch/single_include
|
${PROJECT_SOURCE_DIR}/lib/catch/single_include
|
||||||
|
${PROJECT_SOURCE_DIR}/lib/parsebase/include
|
||||||
)
|
)
|
||||||
|
|
||||||
set(libraries
|
set(libraries
|
||||||
|
@ -373,7 +373,7 @@ TEST_CASE("[PDDL parser] Missing or unmatching domain descriptions are detected"
|
|||||||
}
|
}
|
||||||
SECTION("")
|
SECTION("")
|
||||||
{
|
{
|
||||||
CHECK_THROWS_AS(Description::fromFiles({"data/blocksworld-problem.pddl", "data/storage-domain.pddl"}, context), plasp::input::ParserException);
|
CHECK_THROWS_AS(Description::fromFiles({"data/blocksworld-problem.pddl", "data/storage-domain.pddl"}, context), parsebase::ParserException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user