summaryrefslogtreecommitdiff
path: root/src/core/parser/ParserStack.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-03 02:28:30 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-03 02:28:30 +0100
commit7060df78f37f0d75e32212f24e2327069f5dea94 (patch)
treee3cd3748c5b98f20330a50a35addd7199e84334b /src/core/parser/ParserStack.cpp
parent4284cda04b3a1b1f4c5d4368cc8663d01b6925c6 (diff)
Added "deduceState" function
Diffstat (limited to 'src/core/parser/ParserStack.cpp')
-rw-r--r--src/core/parser/ParserStack.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/core/parser/ParserStack.cpp b/src/core/parser/ParserStack.cpp
index 51a7a13..cc875cb 100644
--- a/src/core/parser/ParserStack.cpp
+++ b/src/core/parser/ParserStack.cpp
@@ -18,12 +18,13 @@
#include <sstream>
-#include "ParserStack.hpp"
-
#include <core/common/Utils.hpp>
#include <core/common/Exceptions.hpp>
#include <core/model/Project.hpp>
+#include "ParserScope.hpp"
+#include "ParserStack.hpp"
+
namespace ousia {
/* A default handler */
@@ -88,6 +89,33 @@ ParserStack::ParserStack(
{
}
+bool ParserStack::deduceState()
+{
+ // Assemble all states
+ std::vector<const ParserState *> states;
+ for (const auto &e : this->states) {
+ states.push_back(e.second);
+ }
+
+ // Fetch the type signature of the scope and derive all possible states,
+ // abort if no unique parser state was found
+ std::vector<const ParserState *> possibleStates =
+ ParserStateDeductor(ctx.getScope().getStackTypeSignature(), states)
+ .deduce();
+ if (possibleStates.size() != 1) {
+ ctx.getLogger().error(
+ "Error while including file: Cannot deduce parser state.");
+ return false;
+ }
+
+ // Switch to this state by creating a dummy handler
+ const ParserState *state = possibleStates[0];
+ Handler *handler =
+ DefaultHandler::create({ctx, "", *state, *state, SourceLocation{}});
+ stack.emplace(handler);
+ return true;
+}
+
std::set<std::string> ParserStack::expectedCommands(const ParserState &state)
{
std::set<std::string> res;