Implemented recognition of comments in PDDL.

This commit is contained in:
2016-06-10 16:40:43 +02:00
parent 168fcc874e
commit 9f0e784a4a
5 changed files with 153 additions and 12 deletions

View File

@@ -26,17 +26,17 @@ Description::Description()
m_problemPosition{-1},
m_problem{std::make_unique<Problem>(Problem(m_context, *m_domain))}
{
m_parser.setCaseSensitive(false);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
Description Description::fromParser(utils::Parser &&parser)
{
parser.setCaseSensitive(false);
Description description;
parser.setCaseSensitive(false);
parser.removeComments(";", "\n", false);
description.m_parser = std::move(parser);
description.parseContent();
@@ -53,6 +53,9 @@ Description Description::fromStream(std::istream &istream)
description.m_parser.readStream("std::cin", istream);
description.m_parser.setCaseSensitive(false);
description.m_parser.removeComments(";", "\n", false);
description.parseContent();
description.checkConsistency();
@@ -67,6 +70,9 @@ Description Description::fromFile(const std::string &path)
description.m_parser.readFile(path);
description.m_parser.setCaseSensitive(false);
description.m_parser.removeComments(";", "\n", false);
description.parseContent();
description.checkConsistency();
@@ -87,6 +93,9 @@ Description Description::fromFiles(const std::vector<std::string> &paths)
description.m_parser.readFile(path);
});
description.m_parser.setCaseSensitive(false);
description.m_parser.removeComments(";", "\n", false);
description.parseContent();
description.checkConsistency();

View File

@@ -276,11 +276,10 @@ std::string Parser::parse<std::string>()
template<>
bool Parser::probe<std::string>(const std::string &expectedValue)
{
BOOST_ASSERT(!std::isspace(expectedValue[0]));
const auto previousPosition = position();
skipWhiteSpace();
if (!std::iswspace(expectedValue.front()))
skipWhiteSpace();
const auto match = std::find_if(expectedValue.cbegin(), expectedValue.cend(),
[&](const auto &expectedCharacter)
@@ -529,5 +528,75 @@ void Parser::expect<bool>(const bool &expectedValue)
////////////////////////////////////////////////////////////////////////////////////////////////////
void Parser::removeComments(const std::string &startSequence, const std::string &endSequence, bool removeEnd)
{
const auto inPosition = m_stream.tellg();
const auto outPosition = m_stream.tellp();
m_stream.seekg(0);
const auto removeRange =
[&](const auto &start, const auto &end)
{
BOOST_ASSERT(start != -1);
m_stream.clear();
m_stream.seekp(start);
m_stream.seekg(start);
auto position = start;
while (end == -1 || position < end)
{
m_stream.ignore(1);
if (atEndOfStream())
return;
m_stream.put(' ');
position += static_cast<std::streamoff>(1);
}
};
while (!atEndOfStream())
{
Position startPosition = m_stream.tellg();
while (!atEndOfStream())
{
startPosition = m_stream.tellg();
if (probe(startSequence))
break;
advance();
}
Position endPosition = m_stream.tellg();
while (!atEndOfStream())
{
endPosition = m_stream.tellg();
if (probe(endSequence))
break;
advance();
}
if (removeEnd)
endPosition = m_stream.tellg();
removeRange(startPosition, endPosition);
}
m_stream.clear();
m_stream.seekg(inPosition);
m_stream.seekp(outPosition);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
}