patrick
/
plasp
Archived
1
0
Fork 0

Moved basic parsing to a separate module.

This commit is contained in:
Patrick Lühne 2017-05-09 15:05:59 +02:00
parent 386e5356af
commit 27c6b69874
No known key found for this signature in database
GPG Key ID: 05F3611E97A70ABF
64 changed files with 322 additions and 234 deletions

View File

@ -42,5 +42,5 @@ script:
- git submodule update --recursive --init
- mkdir -p build/debug
- cd build/debug
- cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$_CXX -DPLASP_BUILD_TESTS=ON
- make -j3 plasp-app && make -j3 run-tests
- cmake ../.. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=$_CXX -DPLASP_BUILD_TESTS=ON -DPARSEBASE_BUILD_TESTS=ON
- make -j3 plasp-app && make -j3 run-parsebase-tests && make -j3 run-tests

View File

@ -24,6 +24,7 @@ if (CMAKE_GENERATOR STREQUAL "Ninja" AND
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
endif()
add_subdirectory(lib/parsebase)
add_subdirectory(src)
add_subdirectory(app)
if(PLASP_BUILD_TESTS)

View File

@ -6,6 +6,7 @@ file(GLOB core_headers "*.h")
set(includes
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/lib/parsebase/include
)
set(sources

View File

@ -109,7 +109,7 @@ int main(int argc, char **argv)
try
{
plasp::input::Parser<plasp::input::CaseInsensitiveParserPolicy> parser;
parsebase::Parser<parsebase::CaseInsensitiveParserPolicy> parser;
if (variablesMap.count("input"))
{
@ -160,7 +160,7 @@ int main(int argc, char **argv)
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());
return EXIT_FAILURE;

View File

@ -2,7 +2,8 @@
#define __PLASP__LANGUAGE_DETECTION_H
#include <plasp/Language.h>
#include <plasp/input/Parser.h>
#include <parsebase/Parser.h>
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();

View File

@ -3,10 +3,11 @@
#include <string>
#include <plasp/input/Location.h>
#include <plasp/output/ColorStream.h>
#include <plasp/output/Priority.h>
#include <parsebase/Location.h>
namespace plasp
{
namespace output
@ -36,8 +37,8 @@ class Logger
void log(Priority priority, const char *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 input::Location &location, const std::string &message);
void log(Priority priority, const parsebase::Location &location, const char *message);
void log(Priority priority, const parsebase::Location &location, const std::string &message);
private:
ColorStream m_outputStream;

View File

@ -3,10 +3,11 @@
#include <vector>
#include <plasp/input/Parser.h>
#include <plasp/pddl/Expression.h>
#include <plasp/pddl/expressions/Variable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace pddl

View File

@ -5,7 +5,8 @@
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/Problem.h>
#include <plasp/input/Parser.h>
#include <parsebase/Parser.h>
namespace plasp
{
@ -47,9 +48,9 @@ class Description
Context &m_context;
input::Stream::Position m_domainPosition;
parsebase::Stream::Position m_domainPosition;
std::unique_ptr<Domain> m_domain;
input::Stream::Position m_problemPosition;
parsebase::Stream::Position m_problemPosition;
std::unique_ptr<Problem> m_problem;
};

View File

@ -75,19 +75,19 @@ class Domain
std::string m_name;
input::Stream::Position m_requirementsPosition;
parsebase::Stream::Position m_requirementsPosition;
Requirements m_requirements;
input::Stream::Position m_typesPosition;
parsebase::Stream::Position m_typesPosition;
expressions::PrimitiveTypes m_types;
input::Stream::Position m_constantsPosition;
parsebase::Stream::Position m_constantsPosition;
expressions::Constants m_constants;
input::Stream::Position m_predicatesPosition;
parsebase::Stream::Position m_predicatesPosition;
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;
expressions::DerivedPredicates m_derivedPredicates;

View File

@ -6,7 +6,7 @@
#include <boost/intrusive_ptr.hpp>
#include <plasp/input/Parser.h>
#include <parsebase/Parser.h>
namespace plasp
{

View File

@ -1,7 +1,7 @@
#ifndef __PLASP__PDDL__PARSER_H
#define __PLASP__PDDL__PARSER_H
#include <plasp/input/Parser.h>
#include <parsebase/Parser.h>
namespace plasp
{
@ -44,7 +44,7 @@ class PDDLParserPolicy
////////////////////////////////////////////////////////////////////////////////////////////////////
using Parser = input::Parser<PDDLParserPolicy>;
using Parser = parsebase::Parser<PDDLParserPolicy>;
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -64,18 +64,18 @@ class Problem
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;
input::Stream::Position m_objectsPosition;
parsebase::Stream::Position m_objectsPosition;
expressions::Constants m_objects;
input::Stream::Position m_initialStatePosition;
parsebase::Stream::Position m_initialStatePosition;
std::unique_ptr<InitialState> m_initialState;
input::Stream::Position m_goalPosition;
parsebase::Stream::Position m_goalPosition;
ExpressionPointer m_goal;
};

View File

@ -4,10 +4,11 @@
#include <iosfwd>
#include <vector>
#include <plasp/input/Parser.h>
#include <plasp/sas/Value.h>
#include <plasp/sas/Variable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -27,8 +28,8 @@ using AssignedVariables = std::vector<AssignedVariable>;
class AssignedVariable
{
public:
static AssignedVariable fromSAS(input::Parser<> &parser, const Variables &variables);
static AssignedVariable fromSAS(input::Parser<> &parser, const Variable &variable);
static AssignedVariable fromSAS(parsebase::Parser<> &parser, const Variables &variables);
static AssignedVariable fromSAS(parsebase::Parser<> &parser, const Variable &variable);
public:
explicit AssignedVariable(const Variable &variable, const Value &value);

View File

@ -3,10 +3,11 @@
#include <vector>
#include <plasp/input/Parser.h>
#include <plasp/sas/AssignedVariable.h>
#include <plasp/sas/Variable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -29,7 +30,7 @@ class AxiomRule
using Condition = AssignedVariable;
using Conditions = AssignedVariables;
static AxiomRule fromSAS(input::Parser<> &parser, const Variables &variables);
static AxiomRule fromSAS(parsebase::Parser<> &parser, const Variables &variables);
public:
const Conditions &conditions() const;

View File

@ -1,13 +1,12 @@
#ifndef __PLASP__SAS__DESCRIPTION_H
#define __PLASP__SAS__DESCRIPTION_H
#include <experimental/filesystem>
#include <iosfwd>
#include <memory>
#include <vector>
#include <boost/filesystem/path.hpp>
#include <plasp/input/Parser.h>
#include <plasp/sas/AxiomRule.h>
#include <plasp/sas/Goal.h>
#include <plasp/sas/InitialState.h>
@ -15,6 +14,8 @@
#include <plasp/sas/Operator.h>
#include <plasp/sas/Variable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -29,9 +30,9 @@ namespace sas
class Description
{
public:
static Description fromParser(input::Parser<> &&parser);
static Description fromParser(parsebase::Parser<> &&parser);
static Description fromStream(std::istream &istream);
static Description fromFile(const boost::filesystem::path &path);
static Description fromFile(const std::experimental::filesystem::path &path);
public:
bool usesActionCosts() const;
@ -50,16 +51,16 @@ class Description
private:
Description();
void parseContent(input::Parser<> &parser);
void parseContent(parsebase::Parser<> &parser);
void parseVersionSection(input::Parser<> &parser) const;
void parseMetricSection(input::Parser<> &parser);
void parseVariablesSection(input::Parser<> &parser);
void parseMutexSection(input::Parser<> &parser);
void parseInitialStateSection(input::Parser<> &parser);
void parseGoalSection(input::Parser<> &parser);
void parseOperatorSection(input::Parser<> &parser);
void parseAxiomSection(input::Parser<> &parser);
void parseVersionSection(parsebase::Parser<> &parser) const;
void parseMetricSection(parsebase::Parser<> &parser);
void parseVariablesSection(parsebase::Parser<> &parser);
void parseMutexSection(parsebase::Parser<> &parser);
void parseInitialStateSection(parsebase::Parser<> &parser);
void parseGoalSection(parsebase::Parser<> &parser);
void parseOperatorSection(parsebase::Parser<> &parser);
void parseAxiomSection(parsebase::Parser<> &parser);
bool m_usesActionCosts;

View File

@ -3,10 +3,11 @@
#include <vector>
#include <plasp/input/Parser.h>
#include <plasp/sas/AssignedVariable.h>
#include <plasp/sas/Variable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -29,7 +30,7 @@ class Effect
using Condition = AssignedVariable;
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:
const Conditions &conditions() const;

View File

@ -1,9 +1,10 @@
#ifndef __PLASP__SAS__GOAL_H
#define __PLASP__SAS__GOAL_H
#include <plasp/input/Parser.h>
#include <plasp/sas/AssignedVariable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -21,7 +22,7 @@ class Goal
using Fact = AssignedVariable;
using Facts = AssignedVariables;
static Goal fromSAS(input::Parser<> &parser, const Variables &variables);
static Goal fromSAS(parsebase::Parser<> &parser, const Variables &variables);
public:
const Facts &facts() const;

View File

@ -1,9 +1,10 @@
#ifndef __PLASP__SAS__INITIAL_STATE_H
#define __PLASP__SAS__INITIAL_STATE_H
#include <plasp/input/Parser.h>
#include <plasp/sas/AssignedVariable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -21,7 +22,7 @@ class InitialState
using Fact = AssignedVariable;
using Facts = AssignedVariables;
static InitialState fromSAS(input::Parser<> &parser, const Variables &variables);
static InitialState fromSAS(parsebase::Parser<> &parser, const Variables &variables);
public:
const Facts &facts() const;

View File

@ -3,9 +3,10 @@
#include <vector>
#include <plasp/input/Parser.h>
#include <plasp/sas/AssignedVariable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -28,7 +29,7 @@ class MutexGroup
using Fact = AssignedVariable;
using Facts = AssignedVariables;
static MutexGroup fromSAS(input::Parser<> &parser, const Variables &variables);
static MutexGroup fromSAS(parsebase::Parser<> &parser, const Variables &variables);
public:
const Facts &facts() const;

View File

@ -4,13 +4,14 @@
#include <string>
#include <vector>
#include <plasp/input/Parser.h>
#include <plasp/output/ColorStream.h>
#include <plasp/sas/AssignedVariable.h>
#include <plasp/sas/Effect.h>
#include <plasp/sas/Predicate.h>
#include <plasp/sas/Variable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -33,7 +34,7 @@ class Operator
using Condition = AssignedVariable;
using Conditions = AssignedVariables;
static Operator fromSAS(input::Parser<> &parser, const Variables &variables);
static Operator fromSAS(parsebase::Parser<> &parser, const Variables &variables);
public:
void printPredicateAsASP(output::ColorStream &stream) const;

View File

@ -5,9 +5,10 @@
#include <string>
#include <vector>
#include <plasp/input/Parser.h>
#include <plasp/output/ColorStream.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -22,7 +23,7 @@ namespace sas
class Predicate
{
public:
static Predicate fromSAS(input::Parser<> &parser);
static Predicate fromSAS(parsebase::Parser<> &parser);
using Arguments = std::vector<std::string>;

View File

@ -1,11 +1,11 @@
#ifndef __PLASP__SAS__TRANSLATOR_ASP_H
#define __PLASP__SAS__TRANSLATOR_ASP_H
#include <iosfwd>
#include <plasp/output/ColorStream.h>
#include <plasp/sas/Description.h>
#include <iosfwd>
namespace plasp
{
namespace sas

View File

@ -5,9 +5,10 @@
#include <string>
#include <vector>
#include <plasp/input/Parser.h>
#include <plasp/output/ColorStream.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -39,8 +40,8 @@ struct Value
static const Value Any;
static const Value None;
static Value fromSAS(input::Parser<> &parser);
static const Value &referenceFromSAS(input::Parser<> &parser, const Variable &variable);
static Value fromSAS(parsebase::Parser<> &parser);
static const Value &referenceFromSAS(parsebase::Parser<> &parser, const Variable &variable);
public:
Value negated() const;

View File

@ -5,10 +5,11 @@
#include <string>
#include <vector>
#include <plasp/input/Parser.h>
#include <plasp/output/ColorStream.h>
#include <plasp/sas/Value.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -28,8 +29,8 @@ using Variables = std::vector<Variable>;
class Variable
{
public:
static Variable fromSAS(input::Parser<> &parser);
static const Variable &referenceFromSAS(input::Parser<> &parser, const Variables &variables);
static Variable fromSAS(parsebase::Parser<> &parser);
static const Variable &referenceFromSAS(parsebase::Parser<> &parser, const Variables &variables);
public:
void printNameAsASPPredicate(output::ColorStream &outputStream) const;

View File

@ -3,10 +3,11 @@
#include <iosfwd>
#include <plasp/input/Parser.h>
#include <plasp/sas/Value.h>
#include <plasp/sas/Variable.h>
#include <parsebase/Parser.h>
namespace plasp
{
namespace sas
@ -26,7 +27,7 @@ using VariableTransitions = std::vector<VariableTransition>;
class VariableTransition
{
public:
static VariableTransition fromSAS(input::Parser<> &parser, const Variables &variables);
static VariableTransition fromSAS(parsebase::Parser<> &parser, const Variables &variables);
public:
const Variable &variable() const;

View 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)

View File

@ -1,11 +1,9 @@
#ifndef __PLASP__INPUT__LOCATION_H
#define __PLASP__INPUT__LOCATION_H
#ifndef __PARSE_BASE__LOCATION_H
#define __PARSE_BASE__LOCATION_H
#include <cstdlib>
namespace plasp
{
namespace input
namespace parsebase
{
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -28,7 +26,6 @@ struct Location
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -1,20 +1,18 @@
#ifndef __PLASP__INPUT__PARSER_H
#define __PLASP__INPUT__PARSER_H
#ifndef __PARSE_BASE__PARSER_H
#define __PARSE_BASE__PARSER_H
#include <algorithm>
#include <cassert>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>
#include <boost/filesystem.hpp>
#include <parsebase/ParserException.h>
#include <parsebase/ParserPolicy.h>
#include <parsebase/Stream.h>
#include <plasp/input/ParserException.h>
#include <plasp/input/ParserPolicy.h>
#include <plasp/input/Stream.h>
namespace plasp
{
namespace input
namespace parsebase
{
template<typename Type>
@ -286,7 +284,7 @@ void Parser<ParserPolicy>::removeComments(const std::string &startSequence, cons
const auto removeRange =
[&](const auto &start, const auto &end)
{
BOOST_ASSERT(start != -1);
assert(start != -1);
m_stream.clear();
m_stream.seekp(start);
@ -564,7 +562,6 @@ bool Parser<ParserPolicy>::testImpl(bool expectedValue)
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -1,14 +1,12 @@
#ifndef __PLASP__INPUT__PARSER_EXCEPTION_H
#define __PLASP__INPUT__PARSER_EXCEPTION_H
#ifndef __PARSE_BASE__PARSER_EXCEPTION_H
#define __PARSE_BASE__PARSER_EXCEPTION_H
#include <exception>
#include <string>
#include <plasp/input/Location.h>
#include <parsebase/Location.h>
namespace plasp
{
namespace input
namespace parsebase
{
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -20,17 +18,17 @@ namespace input
class ParserException: public std::exception
{
public:
explicit ParserException(const input::Location &location)
explicit ParserException(const Location &location)
: 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))
{
}
explicit ParserException(const input::Location &location, const std::string &message)
explicit ParserException(const Location &location, const std::string &message)
: m_location{location},
m_message{message},
// TODO: refactor
@ -48,7 +46,7 @@ class ParserException: public std::exception
return m_plainMessage.c_str();
}
const input::Location &location() const
const Location &location() const
{
return m_location;
}
@ -59,14 +57,13 @@ class ParserException: public std::exception
}
private:
input::Location m_location;
Location m_location;
std::string m_message;
std::string m_plainMessage;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -1,11 +1,9 @@
#ifndef __PLASP__INPUT__PARSER_POLICY_H
#define __PLASP__INPUT__PARSER_POLICY_H
#ifndef __PARSE_BASE__PARSER_POLICY_H
#define __PARSE_BASE__PARSER_POLICY_H
#include <iostream>
namespace plasp
{
namespace input
namespace parsebase
{
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -66,7 +64,6 @@ class CaseInsensitiveParserPolicy
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View File

@ -1,18 +1,15 @@
#ifndef __PLASP__INPUT__STREAM_H
#define __PLASP__INPUT__STREAM_H
#ifndef __PARSE_BASE__STREAM_H
#define __PARSE_BASE__STREAM_H
#include <experimental/filesystem>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>
#include <boost/filesystem.hpp>
#include <parsebase/Location.h>
#include <plasp/input/Location.h>
namespace plasp
{
namespace input
namespace parsebase
{
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -56,7 +53,7 @@ class Stream
~Stream() = default;
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 seek(Position position);
@ -77,7 +74,6 @@ class Stream
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
#endif

View 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})

View File

@ -1,12 +1,11 @@
#include <plasp/input/Stream.h>
#include <parsebase/Stream.h>
#include <algorithm>
#include <fstream>
#include <plasp/input/ParserException.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace input
namespace parsebase
{
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -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() + "");
std::ifstream fileStream(path.string(), std::ios::in);
@ -161,4 +160,3 @@ void Stream::advance()
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}

View 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)

View File

@ -1,14 +1,14 @@
#include <catch.hpp>
#include <plasp/input/Parser.h>
#include <plasp/input/ParserException.h>
#include <parsebase/Parser.h>
#include <parsebase/ParserException.h>
////////////////////////////////////////////////////////////////////////////////////////////////////
TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
{
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<size_t>() == 5u);
@ -19,7 +19,7 @@ TEST_CASE("[parser] Simple strings are parsed correctly", "[parser]")
REQUIRE(p.parse<int>() == 100);
REQUIRE(p.parse<size_t>() == 200u);
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]")
{
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<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<size_t>(200u));
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);
REQUIRE_THROWS_AS(p.expect<std::string>("error"), plasp::input::ParserException);
REQUIRE_THROWS_AS(p.expect<std::string>("error"), parsebase::ParserException);
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);
REQUIRE_THROWS_AS(p.expect<int>(-50), plasp::input::ParserException);
REQUIRE_THROWS_AS(p.expect<int>(-50), parsebase::ParserException);
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);
REQUIRE_THROWS_AS(p.expect<bool>(false), plasp::input::ParserException);
REQUIRE_THROWS_AS(p.expect<bool>(false), parsebase::ParserException);
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);
REQUIRE_THROWS_AS(p.expect<size_t>(201), plasp::input::ParserException);
REQUIRE_THROWS_AS(p.expect<size_t>(201), parsebase::ParserException);
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]")
{
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();
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]")
{
std::stringstream s1("test");
plasp::input::Parser<> p1("input", s1);
parsebase::Parser<> p1("input", s1);
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");
plasp::input::Parser<> p2("input", s2);
parsebase::Parser<> p2("input", s2);
REQUIRE_NOTHROW(p2.expect<std::string>("test1"));
REQUIRE_NOTHROW(p2.expect<std::string>("test2"));
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");
plasp::input::Parser<> p3("input", s3);
parsebase::Parser<> p3("input", s3);
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");
plasp::input::Parser<> p4("input", s4);
parsebase::Parser<> p4("input", s4);
REQUIRE_NOTHROW(p4.expect<size_t>(128));
REQUIRE_NOTHROW(p4.expect<int>(-1023));
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");
plasp::input::Parser<> p5("input", s5);
parsebase::Parser<> p5("input", s5);
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");
plasp::input::Parser<> p6("input", s6);
parsebase::Parser<> p6("input", s6);
REQUIRE_NOTHROW(p6.expect<bool>(false));
REQUIRE_NOTHROW(p6.expect<bool>(true));
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]")
{
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();
plasp::input::Location l;
parsebase::Location l;
l = p.location();
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]")
{
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);
plasp::input::Location l;
parsebase::Location l;
REQUIRE_NOTHROW(p1.expect<std::string>("test1"));
@ -308,7 +308,7 @@ TEST_CASE("[parser] Comments are correctly removed", "[parser]")
REQUIRE(p1.atEnd());
std::stringstream s2("test;");
plasp::input::Parser<> p2("input", s2);
parsebase::Parser<> p2("input", s2);
p2.removeComments(";", "\n", false);
@ -319,7 +319,7 @@ TEST_CASE("[parser] Comments are correctly removed", "[parser]")
REQUIRE(p2.atEnd());
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);

View File

@ -0,0 +1,2 @@
#define CATCH_CONFIG_MAIN
#include <catch.hpp>

View File

@ -27,6 +27,7 @@ file(GLOB utils_headers "../include/plasp/utils/*.h")
set(includes
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/lib/parsebase/include
)
set(sources
@ -57,6 +58,7 @@ set(sources
set(libraries
${Boost_LIBRARIES}
parsebase
pthread
)

View File

@ -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);
@ -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());
}

View File

@ -5,10 +5,11 @@
#include <boost/filesystem.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/IO.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@ -168,7 +169,7 @@ void Description::findSections()
if (parser.testAndSkip<std::string>("domain"))
{
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;
@ -178,7 +179,7 @@ void Description::findSections()
else if (m_context.parser.testAndSkip<std::string>("problem"))
{
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));
@ -190,7 +191,7 @@ void Description::findSections()
else
{
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();

View File

@ -2,7 +2,6 @@
#include <algorithm>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/IO.h>
#include <plasp/pddl/expressions/Constant.h>
@ -10,6 +9,8 @@
#include <plasp/pddl/expressions/PrimitiveType.h>
#include <plasp/pddl/expressions/Variable.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@ -51,7 +52,7 @@ void Domain::findSections()
if (unique && sectionPosition != -1)
{
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;
@ -101,7 +102,7 @@ void Domain::findSections()
const auto sectionIdentifier = parser.parseIdentifier();
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
@ -354,7 +355,7 @@ void Domain::parseTypeSection()
while (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);

View File

@ -1,6 +1,5 @@
#include <plasp/pddl/Expression.h>
#include <plasp/input/ParserException.h>
#include <plasp/output/TranslatorException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Domain.h>
@ -17,6 +16,8 @@
#include <plasp/pddl/expressions/Unsupported.h>
#include <plasp/pddl/expressions/When.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@ -181,7 +182,7 @@ ExpressionPointer parseExpression(Context &context, ExpressionContext &expressio
const auto expressionIdentifier = parser.parseIdentifier();
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();
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)))
return expression;
throw input::ParserException(parser.location(), "expected predicate");
throw parsebase::ParserException(parser.location(), "expected predicate");
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -1,6 +1,5 @@
#include <plasp/pddl/InitialState.h>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/ExpressionContext.h>
#include <plasp/pddl/IO.h>
@ -9,6 +8,8 @@
#include <plasp/pddl/expressions/Predicate.h>
#include <plasp/pddl/expressions/Unsupported.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@ -58,7 +59,7 @@ std::unique_ptr<InitialState> InitialState::parseDeclaration(Context &context,
const auto expressionIdentifier = parser.parseIdentifier();
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();

View File

@ -2,13 +2,14 @@
#include <algorithm>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/ConsistencyException.h>
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/ExpressionContext.h>
#include <plasp/pddl/IO.h>
#include <plasp/pddl/expressions/Constant.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@ -52,7 +53,7 @@ void Problem::findSections()
if (unique && sectionPosition != -1)
{
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;
@ -97,7 +98,7 @@ void Problem::findSections()
const auto sectionIdentifier = parser.parseIdentifier();
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
@ -203,7 +204,7 @@ void Problem::parseDomainSection()
const auto domainName = parser.parseIdentifier();
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>(")");
}

View File

@ -4,7 +4,7 @@
#include <boost/assign.hpp>
#include <boost/bimap.hpp>
#include <plasp/input/ParserException.h>
#include <parsebase/ParserException.h>
namespace plasp
{
@ -89,7 +89,7 @@ Requirement Requirement::parse(Context &context)
const auto match = requirementTypesToPDDL.right.find(requirementName);
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;

View File

@ -53,7 +53,7 @@ expressions::VariablePointer VariableStack::parseAndFind(plasp::pddl::Context &c
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");
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -4,13 +4,14 @@
#include <boost/assert.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/ExpressionContext.h>
#include <plasp/pddl/Problem.h>
#include <plasp/pddl/expressions/PrimitiveType.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@ -114,7 +115,7 @@ void Constant::parseTypedDeclarations(Context &context, Domain &domain)
domain.checkRequirement(Requirement::Type::Typing);
// If no types are given, check that typing is not a requirement
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);
// If no types are given, check that typing is not a requirement
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)
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)
return constant;
throw input::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
throw parsebase::ParserException(parser.location(), "constant “" + constantName + "” used but never declared");
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -126,7 +126,7 @@ PredicatePointer Predicate::parse(Context &context, const Problem &problem)
while (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
const auto constant = Constant::parseAndFind(context, problem);

View File

@ -4,11 +4,12 @@
#include <boost/assert.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/ExpressionContext.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@ -112,7 +113,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
const auto typeName = parser.parseIdentifier();
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 &primitiveType)
@ -129,7 +130,7 @@ PrimitiveTypePointer PrimitiveType::parseAndFind(Context &context, Domain &domai
types.emplace_back(PrimitiveTypePointer(new PrimitiveType(typeName)));
}
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();
}

View File

@ -4,7 +4,6 @@
#include <boost/assert.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/pddl/Context.h>
#include <plasp/pddl/Domain.h>
#include <plasp/pddl/ExpressionContext.h>
@ -12,6 +11,8 @@
#include <plasp/pddl/expressions/PrimitiveType.h>
#include <plasp/pddl/expressions/Type.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace pddl
@ -60,7 +61,7 @@ void Variable::parseDeclaration(Context &context, Variables &parameters)
});
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
variable->setDirty();
@ -137,7 +138,7 @@ void Variable::parseTypedDeclarations(Context &context, ExpressionContext &expre
expressionContext.checkRequirement(Requirement::Type::Typing);
// If no types are given, check that typing is not a requirement
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");
}
////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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;
@ -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;

View File

@ -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");

View File

@ -5,11 +5,10 @@
#include <fstream>
#include <sstream>
#include <boost/filesystem.hpp>
#include <plasp/input/ParserException.h>
#include <plasp/sas/VariableTransition.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace sas
@ -28,7 +27,7 @@ Description::Description()
////////////////////////////////////////////////////////////////////////////////////////////////////
Description Description::fromParser(input::Parser<> &&parser)
Description Description::fromParser(parsebase::Parser<> &&parser)
{
Description description;
description.parseContent(parser);
@ -40,7 +39,7 @@ Description Description::fromParser(input::Parser<> &&parser)
Description Description::fromStream(std::istream &istream)
{
input::Parser<> parser;
parsebase::Parser<> parser;
parser.read("std::cin", istream);
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() + "");
input::Parser<> parser;
parsebase::Parser<> parser;
parser.read(path);
Description description;
@ -160,7 +159,7 @@ bool Description::hasRequirements() const
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseContent(input::Parser<> &parser)
void Description::parseContent(parsebase::Parser<> &parser)
{
parseVersionSection(parser);
parseMetricSection(parser);
@ -174,26 +173,26 @@ void Description::parseContent(input::Parser<> &parser)
parser.skipWhiteSpace();
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");
const auto formatVersion = parser.parse<size_t>();
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");
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseMetricSection(input::Parser<> &parser)
void Description::parseMetricSection(parsebase::Parser<> &parser)
{
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>();
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>();
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));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void Description::parseGoalSection(input::Parser<> &parser)
void Description::parseGoalSection(parsebase::Parser<> &parser)
{
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>();
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>();
m_axiomRules.reserve(numberOfAxiomRules);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -2,7 +2,7 @@
#include <iostream>
#include <plasp/input/ParserException.h>
#include <parsebase/ParserException.h>
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;
@ -29,7 +29,7 @@ MutexGroup MutexGroup::fromSAS(input::Parser<> &parser, const Variables &variabl
mutexGroup.m_facts.emplace_back(Fact::fromSAS(parser, variables));
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");

View File

@ -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_;

View File

@ -4,9 +4,10 @@
#include <limits>
#include <sstream>
#include <plasp/input/ParserException.h>
#include <plasp/output/Formatting.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace sas
@ -18,7 +19,7 @@ namespace sas
//
////////////////////////////////////////////////////////////////////////////////////////////////////
Predicate Predicate::fromSAS(input::Parser<> &parser)
Predicate Predicate::fromSAS(parsebase::Parser<> &parser)
{
Predicate predicate;
@ -43,7 +44,7 @@ Predicate Predicate::fromSAS(input::Parser<> &parser)
}
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;

View File

@ -1,5 +1,7 @@
#include <plasp/sas/TranslatorASP.h>
#include <boost/assert.hpp>
#include <plasp/output/Formatting.h>
namespace plasp

View File

@ -2,10 +2,11 @@
#include <iostream>
#include <plasp/input/ParserException.h>
#include <plasp/output/Formatting.h>
#include <plasp/sas/Variable.h>
#include <parsebase/ParserException.h>
namespace plasp
{
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>();
@ -74,7 +75,7 @@ Value Value::fromSAS(input::Parser<> &parser)
else if (sasSign == "NegatedAtom")
value.m_sign = Value::Sign::Negative;
else
throw input::ParserException(parser.location(), "invalid value sign “" + sasSign + "");
throw parsebase::ParserException(parser.location(), "invalid value sign “" + sasSign + "");
try
{
@ -90,7 +91,7 @@ Value Value::fromSAS(input::Parser<> &parser)
}
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;
@ -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>();
@ -106,7 +107,7 @@ const Value &Value::referenceFromSAS(input::Parser<> &parser, const Variable &va
return Value::Any;
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];
}

View File

@ -2,9 +2,10 @@
#include <iostream>
#include <plasp/input/ParserException.h>
#include <plasp/output/Formatting.h>
#include <parsebase/ParserException.h>
namespace plasp
{
namespace sas
@ -23,7 +24,7 @@ Variable::Variable()
////////////////////////////////////////////////////////////////////////////////////////////////////
Variable Variable::fromSAS(input::Parser<> &parser)
Variable Variable::fromSAS(parsebase::Parser<> &parser)
{
Variable variable;
@ -42,7 +43,7 @@ Variable Variable::fromSAS(input::Parser<> &parser)
// <none of those> values are only allowed at the end
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");
@ -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>();
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];
}

View File

@ -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;

View File

@ -6,6 +6,7 @@ set(includes
${Boost_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/lib/catch/single_include
${PROJECT_SOURCE_DIR}/lib/parsebase/include
)
set(libraries

View File

@ -373,7 +373,7 @@ TEST_CASE("[PDDL parser] Missing or unmatching domain descriptions are detected"
}
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);
}
}