This repository has been archived on 2023-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
plasp/include/plasp/LanguageDetection.h

51 lines
1.2 KiB
C
Raw Normal View History

#ifndef __PLASP__LANGUAGE_DETECTION_H
#define __PLASP__LANGUAGE_DETECTION_H
#include <plasp/Language.h>
2017-05-12 14:17:57 +02:00
#include <tokenize/Tokenizer.h>
namespace plasp
{
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// LanguageDetection
//
////////////////////////////////////////////////////////////////////////////////////////////////////
2017-05-12 14:17:57 +02:00
Language::Type detectLanguage(tokenize::Tokenizer<tokenize::CaseInsensitiveTokenizerPolicy> &tokenizer)
{
2017-05-12 14:17:57 +02:00
tokenizer.skipWhiteSpace();
// SAS begins with "begin_version"
2017-05-12 14:17:57 +02:00
if (tokenizer.testAndSkip<std::string>("begin"))
{
2017-05-12 14:17:57 +02:00
tokenizer.seek(0);
return Language::Type::SAS;
}
// Skip potential PDDL comments
2017-05-12 14:17:57 +02:00
while (tokenizer.currentCharacter() == ';')
{
2017-05-12 14:17:57 +02:00
tokenizer.skipLine();
tokenizer.skipWhiteSpace();
}
// PDDL contains sections starting with "(define"
2017-05-12 14:17:57 +02:00
if (tokenizer.testAndSkip<std::string>("(") && tokenizer.testAndSkip<std::string>("define"))
{
2017-05-12 14:17:57 +02:00
tokenizer.seek(std::ios::beg);
return Language::Type::PDDL;
}
2017-05-12 14:17:57 +02:00
tokenizer.seek(std::ios::beg);
return Language::Type::Unknown;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
}
#endif