Changed inputparser: added terminal/variable check and insertion lexesis terminals
This commit is contained in:
parent
7609d07cb9
commit
75fcdeac4c
|
@ -11,6 +11,7 @@ find_package(Threads)
|
|||
include(ExternalProject)
|
||||
find_package(mstch QUIET)
|
||||
|
||||
|
||||
if (NOT mstch_FOUND)
|
||||
ExternalProject_Add(ext-mstch
|
||||
GIT_REPOSITORY https://github.com/no1msd/mstch
|
||||
|
@ -76,15 +77,17 @@ include_directories(${G3LOG_INCLUDE_DIR})
|
|||
|
||||
find_package(Lexesis QUIET)
|
||||
if (NOT LEXESIS_FOUND)
|
||||
#Lexesis
|
||||
ExternalProject_Add(ext-lexesis
|
||||
GIT_REPOSITORY git@gitlab.com:Robin_Jadoul/Lexesis.git
|
||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=.
|
||||
)
|
||||
add_library(templ IMPORTED STATIC GLOBAL)
|
||||
add_library(lxsinput IMPORTED STATIC GLOBAL)
|
||||
add_dependencies(templ ext-lexesis)
|
||||
add_dependencies(lxsinput ext-lexesis)
|
||||
ExternalProject_Get_Property(ext-lexesis binary_dir source_dir)
|
||||
set_target_properties(templ PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/src/${CMAKE_STATIC_LIBRARY_PREFIX}templ${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
set_target_properties(lxsinput PROPERTIES "IMPORTED_LOCATION" "${binary_dir}/src/${CMAKE_STATIC_LIBRARY_PREFIX}lxsinput${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
include_directories(${binary_dir}/include)
|
||||
set(LEXESIS_EXE "${binary_dir}/bin/Lexesis")
|
||||
endif()
|
||||
|
|
|
@ -49,6 +49,7 @@ target_link_libraries(Parsodus
|
|||
# Parsodus-backends
|
||||
templ
|
||||
pds
|
||||
lxsinput
|
||||
mstch::mstch
|
||||
${G3LOG_LIBRARY}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
|
|
|
@ -2,18 +2,46 @@
|
|||
#include "Parsodus/inputparser.h"
|
||||
#include "Parsodus/parser.h"
|
||||
#include "Parsodus/util/parserType.h"
|
||||
#include "Lexesis/inputparser.h"
|
||||
#include <set>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
std::set<std::string> getTerminals(std::string file) {
|
||||
std::set<std::string> terminals;
|
||||
std::fstream f(file);
|
||||
return lxs::input::InputParser::getTokens(f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace pds {
|
||||
|
||||
InputParserException::InputParserException(std::string what): m_what(what) {}
|
||||
InputParserException::InputParserException(std::string what): m_what(what) {}
|
||||
const char* InputParserException::what() const throw() {
|
||||
return m_what.c_str();
|
||||
}
|
||||
Config InputParser::parseInput(std::istream& is) {
|
||||
}
|
||||
Config InputParser::parseInput(std::istream& is) {
|
||||
ParsodusLexer lex(is);
|
||||
Parser parser(lex);
|
||||
//TODO: collect terminals from lexesis (if lexesisFile set)
|
||||
//TODO: check all rules for exisiting terminals/variables
|
||||
return *parser.parse();
|
||||
}
|
||||
}
|
||||
Parser parser(lex);
|
||||
|
||||
Config cnf = *parser.parse();
|
||||
if (!cnf.lexesisFile.empty()) {
|
||||
auto terminals = getTerminals(cnf.lexesisFile);
|
||||
for(auto& terminal : terminals)
|
||||
cnf.grammar.terminals.insert(terminal);
|
||||
}
|
||||
|
||||
for(auto& rule : cnf.grammar.rules) {
|
||||
for(auto& tail_piece : rule->tail) {
|
||||
if (cnf.grammar.terminals.find(tail_piece) == cnf.grammar.terminals.end() &&
|
||||
cnf.grammar.variables.find(tail_piece) == cnf.grammar.variables.end())
|
||||
throw InputParserException("Found '" + tail_piece + "' in rule body while this isn't a variable or terminal");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return cnf;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue