diff --git a/include/plasp/sas/Variable.h b/include/plasp/sas/Variable.h index 09049ce..18ccd15 100644 --- a/include/plasp/sas/Variable.h +++ b/include/plasp/sas/Variable.h @@ -1,6 +1,7 @@ #ifndef __SAS__VARIABLE_H #define __SAS__VARIABLE_H +#include #include #include @@ -19,6 +20,8 @@ namespace sas struct Variable { + static Variable fromSAS(std::istream &istream); + using Values = std::vector; std::string name; diff --git a/src/plasp/sas/Description.cpp b/src/plasp/sas/Description.cpp index a825126..a15b9c3 100644 --- a/src/plasp/sas/Description.cpp +++ b/src/plasp/sas/Description.cpp @@ -304,44 +304,7 @@ void Description::parseVariablesSection(std::istream &istream) m_variables.resize(numberOfVariables); for (size_t i = 0; i < numberOfVariables; i++) - { - auto &variable = m_variables[i]; - - utils::parseExpected(istream, "begin_variable"); - - variable.name = utils::parse(istream); - variable.axiomLayer = utils::parse(istream); - - const auto numberOfValues = utils::parse(istream); - variable.values.resize(numberOfValues); - - try - { - for (size_t j = 0; j < numberOfValues; j++) - { - auto &value = variable.values[j]; - - const auto sasSign = utils::parse(istream); - - if (sasSign == "Atom") - value.sign = Value::Sign::Positive; - else if (sasSign == "NegatedAtom") - value.sign = Value::Sign::Negative; - else - throw utils::ParserException("Invalid value sign \"" + sasSign + "\""); - - istream.ignore(1); - - std::getline(istream, value.name); - } - } - catch (const std::exception &e) - { - throw utils::ParserException("Could not parse variable " + variable.name + " (" + e.what() + ")"); - } - - utils::parseExpected(istream, "end_variable"); - } + m_variables[i] = Variable::fromSAS(istream); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/plasp/sas/Variable.cpp b/src/plasp/sas/Variable.cpp new file mode 100644 index 0000000..97a95f8 --- /dev/null +++ b/src/plasp/sas/Variable.cpp @@ -0,0 +1,63 @@ +#include + +#include + +#include + +namespace plasp +{ +namespace sas +{ + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// +// Variable +// +//////////////////////////////////////////////////////////////////////////////////////////////////// + +Variable Variable::fromSAS(std::istream &istream) +{ + Variable variable; + + utils::parseExpected(istream, "begin_variable"); + + variable.name = utils::parse(istream); + variable.axiomLayer = utils::parse(istream); + + const auto numberOfValues = utils::parse(istream); + variable.values.resize(numberOfValues); + + try + { + for (size_t j = 0; j < numberOfValues; j++) + { + auto &value = variable.values[j]; + + const auto sasSign = utils::parse(istream); + + if (sasSign == "Atom") + value.sign = Value::Sign::Positive; + else if (sasSign == "NegatedAtom") + value.sign = Value::Sign::Negative; + else + throw utils::ParserException("Invalid value sign \"" + sasSign + "\""); + + istream.ignore(1); + + std::getline(istream, value.name); + } + } + catch (const std::exception &e) + { + throw utils::ParserException("Could not parse variable " + variable.name + " (" + e.what() + ")"); + } + + utils::parseExpected(istream, "end_variable"); + + return variable; +} + +//////////////////////////////////////////////////////////////////////////////////////////////////// + +} +}