Better handling for the lexer name
This commit is contained in:
parent
ff815036fb
commit
a6cf6b7372
|
@ -4,15 +4,32 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Filter only valid identifier chars: alphanumeric, and not starting with a digit
|
||||
*/
|
||||
std::string clean(std::string in) {
|
||||
std::string s;
|
||||
for (char c : in) {
|
||||
if ((s.length() && std::isalnum(c)) || std::isalpha(c))
|
||||
s += c;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
namespace lxs {
|
||||
Driver::Driver(std::unique_ptr<BackendManager> backends, std::istream& inputfile, std::string outputdir, std::string language, std::string lexername) :
|
||||
m_backends(std::move(backends)),
|
||||
m_inputfile(inputfile),
|
||||
m_outputdir(outputdir),
|
||||
m_language(language),
|
||||
m_lexername(lexername)
|
||||
m_lexername(clean(lexername))
|
||||
{
|
||||
//TODO clean lexername
|
||||
if (!m_lexername.length()) {
|
||||
std::cerr << "No valid lexer name possible" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Driver::~Driver()
|
||||
|
|
25
src/main.cpp
25
src/main.cpp
|
@ -29,14 +29,35 @@ int main(int argc, char** argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
const char PATHSEP = '\\';
|
||||
#else
|
||||
const char PATHSEP = '/';
|
||||
#endif
|
||||
|
||||
std::string lexername = options["lexername"];
|
||||
//FIXME: this really needs some more work...
|
||||
if (!lexername.length()) {
|
||||
|
||||
if (!lexername.length()) { //The option is empty
|
||||
if (args[0].length() >= 4 && args[0].substr(args[0].length() - 4, 4) == ".lxs") {
|
||||
lexername = args[0].substr(0, args[0].length() - 4); //Drop the .lxs
|
||||
|
||||
} else {
|
||||
lexername = args[0];
|
||||
}
|
||||
|
||||
std::size_t pos;
|
||||
// '/' can be used on most platforms (even windows)
|
||||
pos = lexername.find_last_of('/');
|
||||
if (pos != lexername.npos) {
|
||||
lexername = lexername.substr(pos + 1);
|
||||
}
|
||||
|
||||
// strip platform specific as well
|
||||
pos = lexername.find_last_of(PATHSEP);
|
||||
if (pos != lexername.npos) {
|
||||
lexername = lexername.substr(pos + 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<lxs::BackendManager> backends(new lxs::BackendManager());
|
||||
|
|
Loading…
Reference in New Issue