Implemented automatic language detection for plasp application.
This commit is contained in:
36
include/plasp/Language.h
Normal file
36
include/plasp/Language.h
Normal 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
|
40
include/plasp/LanguageDetection.h
Normal file
40
include/plasp/LanguageDetection.h
Normal 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
|
Reference in New Issue
Block a user