Implemented automatic language detection for plasp application.

This commit is contained in:
2016-06-10 01:23:41 +02:00
parent 8ef874eb22
commit 2e1a011dcf
6 changed files with 154 additions and 6 deletions

36
include/plasp/Language.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef __PLASP__LANGUAGE_H
#define __PLASP__LANGUAGE_H
#include <plasp/utils/Parser.h>
namespace plasp
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Language
//
////////////////////////////////////////////////////////////////////////////////////////////////////
class Language
{
public:
enum class Type
{
Unknown,
PDDL,
SAS
};
static std::string toString(Type language);
static Language::Type fromString(const std::string &languageName);
public:
Language() = delete;
};
////////////////////////////////////////////////////////////////////////////////////////////////////
}
#endif

View File

@@ -0,0 +1,40 @@
#ifndef __PLASP__LANGUAGE_DETECTION_H
#define __PLASP__LANGUAGE_DETECTION_H
#include <plasp/Language.h>
#include <plasp/utils/Parser.h>
namespace plasp
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// LanguageDetection
//
////////////////////////////////////////////////////////////////////////////////////////////////////
Language::Type detectLanguage(utils::Parser &parser)
{
// PDDL contains sections starting with "(define"
if (parser.probe<std::string>("(") && parser.probe<std::string>("define"))
{
parser.seek(std::ios::beg);
return Language::Type::PDDL;
}
// SAS begins with "begin_version"
if (parser.probe<std::string>("begin"))
{
parser.seek(std::ios::beg);
return Language::Type::SAS;
}
parser.seek(std::ios::beg);
return Language::Type::Unknown;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
#endif