summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-18 21:42:49 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-18 21:42:49 +0100
commit2eec59a47ec36e5e4f921ca91284942b4d7d521b (patch)
tree8847623e9b9b1571150142c236b5ab2d8413ce77
parent677d6830a0252e7478c2f5d6f75cfb845d33ad23 (diff)
Fixed bugs in definition of Project, added reference to Project to ParserContext
-rw-r--r--src/core/model/Project.cpp11
-rw-r--r--src/core/model/Project.hpp15
-rw-r--r--src/core/parser/Parser.hpp17
-rw-r--r--src/core/parser/ParserStack.hpp2
-rw-r--r--test/core/parser/ParserStackTest.cpp6
-rw-r--r--test/core/parser/StandaloneParserContext.hpp23
-rw-r--r--test/plugins/css/CSSParserTest.cpp12
-rw-r--r--test/plugins/xml/XmlParserTest.cpp4
8 files changed, 61 insertions, 29 deletions
diff --git a/src/core/model/Project.cpp b/src/core/model/Project.cpp
index 6b6eef6..c491d4f 100644
--- a/src/core/model/Project.cpp
+++ b/src/core/model/Project.cpp
@@ -43,6 +43,11 @@ bool Project::doValidate(Logger &logger) const
continueValidation(typesystems, logger);
}
+Rooted<SystemTypesystem> Project::getSystemTypesystem()
+{
+ return systemTypesystem;
+}
+
Rooted<Typesystem> Project::createTypesystem(const std::string &name)
{
Rooted<Typesystem> typesystem{
@@ -82,6 +87,12 @@ void Project::addDomain(Handle<Domain> domain)
invalidate();
domains.push_back(domain);
}
+
+const NodeVector<Document> &Project::getDocuments() { return documents; }
+
+const NodeVector<Domain> &Project::getDomains() { return domains; }
+
+const NodeVector<Typesystem> &Project::getTypesystems() { return typesystems; }
}
namespace RttiTypes {
diff --git a/src/core/model/Project.hpp b/src/core/model/Project.hpp
index 7f0672a..576bd60 100644
--- a/src/core/model/Project.hpp
+++ b/src/core/model/Project.hpp
@@ -35,11 +35,14 @@ namespace ousia {
// Forward declarations
class Logger;
class Rtti;
-class SystemTypesystem;
-class Typesystem;
namespace model {
+class SystemTypesystem;
+class Typesystem;
+class Document;
+class Domain;
+
/**
* The Project class constitutes the top-level node in which documents, domains,
* typesystems and other resources are embedded.
@@ -88,7 +91,7 @@ public:
*
* @return a reference to the system typesystem.
*/
- Rooted<SystemTypesystem> getSystemTypesystem() { return systemTypesystem; }
+ Rooted<SystemTypesystem> getSystemTypesystem();
/**
* Returns a new typesystem with the given name adds it to the list of
@@ -141,21 +144,21 @@ public:
*
* @return a reference pointing at the document list.
*/
- const NodeVector<Document> &getDocuments() { return documents; }
+ const NodeVector<Document> &getDocuments();
/**
* Returns all domains of this project.
*
* @return a reference pointing at the domain list.
*/
- const NodeVector<Domain> &getDomains() { return domains; }
+ const NodeVector<Domain> &getDomains();
/**
* Returns all typesystems of this project.
*
* @return a reference pointing at the typesystem list.
*/
- const NodeVector<Typesystem> &getTypesystems() { return typesystems; }
+ const NodeVector<Typesystem> &getTypesystems();
};
}
diff --git a/src/core/parser/Parser.hpp b/src/core/parser/Parser.hpp
index 63c57c3..049ee4e 100644
--- a/src/core/parser/Parser.hpp
+++ b/src/core/parser/Parser.hpp
@@ -37,6 +37,7 @@
#include <core/common/Exceptions.hpp>
#include <core/common/Logger.hpp>
#include <core/model/Node.hpp>
+#include <core/model/Project.hpp>
#include "Scope.hpp"
@@ -70,6 +71,11 @@ struct ParserContext {
Manager &manager;
/**
+ * Project instance into which the new content should be parsed.
+ */
+ Rooted<model::Project> project;
+
+ /**
* Constructor of the ParserContext class.
*
* @param scope is a reference to the Scope instance that should be used to
@@ -80,11 +86,16 @@ struct ParserContext {
* @param logger is a reference to the Logger instance that should be used
* to log error messages and warnings that occur while parsing the document.
* @param manager is a Reference to the Manager the parser should append
- *nodes to.
+ * nodes to.
+ * @param project is the project into which the content should be parsed.
*/
ParserContext(Scope &scope, Registry &registry, Logger &logger,
- Manager &manager)
- : scope(scope), registry(registry), logger(logger), manager(manager){};
+ Manager &manager, Handle<model::Project> project)
+ : scope(scope),
+ registry(registry),
+ logger(logger),
+ manager(manager),
+ project(project){};
};
/**
diff --git a/src/core/parser/ParserStack.hpp b/src/core/parser/ParserStack.hpp
index aa196e7..492ab9c 100644
--- a/src/core/parser/ParserStack.hpp
+++ b/src/core/parser/ParserStack.hpp
@@ -147,6 +147,8 @@ public:
Logger &logger() { return handlerData.ctx.logger; }
+ Rooted<model::Project> project() { return handlerData.ctx.project; }
+
State state() { return handlerData.state; }
State parentState() { return handlerData.parentState; }
diff --git a/test/core/parser/ParserStackTest.cpp b/test/core/parser/ParserStackTest.cpp
index ed57260..69978b0 100644
--- a/test/core/parser/ParserStackTest.cpp
+++ b/test/core/parser/ParserStackTest.cpp
@@ -69,7 +69,7 @@ static const std::multimap<std::string, HandlerDescriptor> TEST_HANDLERS{
TEST(ParserStack, simpleTest)
{
StandaloneParserContext ctx;
- ParserStack s{ctx, TEST_HANDLERS};
+ ParserStack s{ctx.context, TEST_HANDLERS};
startCount = 0;
endCount = 0;
@@ -132,7 +132,7 @@ TEST(ParserStack, simpleTest)
TEST(ParserStack, errorHandling)
{
StandaloneParserContext ctx;
- ParserStack s{ctx, TEST_HANDLERS};
+ ParserStack s{ctx.context, TEST_HANDLERS};
ASSERT_THROW(s.start("body", {}), OusiaException);
s.start("document", {});
@@ -152,7 +152,7 @@ TEST(ParserStack, validation)
{
ConcreteLogger logger;
StandaloneParserContext ctx(logger);
- ParserStack s{ctx, TEST_HANDLERS};
+ ParserStack s{ctx.context, TEST_HANDLERS};
s.start("arguments", {});
ASSERT_TRUE(logger.hasError());
diff --git a/test/core/parser/StandaloneParserContext.hpp b/test/core/parser/StandaloneParserContext.hpp
index 78d148d..aca056e 100644
--- a/test/core/parser/StandaloneParserContext.hpp
+++ b/test/core/parser/StandaloneParserContext.hpp
@@ -19,28 +19,35 @@
#ifndef _OUSIA_STANDALONE_PARSER_CONTEXT_
#define _OUSIA_STANDALONE_PARSER_CONTEXT_
+#include <memory>
+
+#include <core/model/Project.hpp>
#include <core/parser/Parser.hpp>
namespace ousia {
namespace parser {
-struct StandaloneParserContext : public ParserContext {
-private:
+struct StandaloneParserContext {
+public:
Manager manager;
Logger logger;
Scope scope;
Registry registry;
+ Rooted<model::Project> project;
+ ParserContext context;
-public:
StandaloneParserContext()
- : ParserContext(scope, registry, logger, manager),
- registry(logger){};
+ : registry(logger),
+ project(new model::Project(manager)),
+ context(scope, registry, logger, manager, project)
+ {
+ }
StandaloneParserContext(Logger &externalLogger)
- : ParserContext(scope, registry, externalLogger, manager),
- registry(externalLogger){};
+ : registry(externalLogger),
+ project(new model::Project(manager)),
+ context(scope, registry, externalLogger, manager, project){};
};
-
}
}
diff --git a/test/plugins/css/CSSParserTest.cpp b/test/plugins/css/CSSParserTest.cpp
index 54c359b..84522b3 100644
--- a/test/plugins/css/CSSParserTest.cpp
+++ b/test/plugins/css/CSSParserTest.cpp
@@ -45,7 +45,8 @@ TEST(CSSParser, testParseSelectors)
// parse the data.
CSSParser instance;
- Rooted<SelectorNode> root = instance.parse(data, ctx).cast<SelectorNode>();
+ Rooted<SelectorNode> root =
+ instance.parse(data, ctx.context).cast<SelectorNode>();
// we expect three children of the root node overall.
ASSERT_EQ(3U, root->getEdges().size());
@@ -156,7 +157,7 @@ TEST(CSSParser, testParseCSS)
CSSParser instance;
CharReader reader{input};
Rooted<SelectorNode> root =
- instance.parse(reader, ctx).cast<SelectorNode>();
+ instance.parse(reader, ctx.context).cast<SelectorNode>();
// we expect three children of the root node overall.
ASSERT_EQ(3U, root->getEdges().size());
@@ -269,14 +270,11 @@ void assertException(std::string css)
{
ScopedLogger sl(logger, "test.css", SourceLocation{},
CharReader::contextCallback, &reader);
- Scope scope;
- Registry registry(logger);
- Manager manager;
- ParserContext ctx{scope, registry, logger, manager};
+ StandaloneParserContext ctx(sl);
CSSParser instance;
try {
- instance.parse(reader, ctx).cast<SelectorNode>();
+ instance.parse(reader, ctx.context).cast<SelectorNode>();
}
catch (LoggableException ex) {
logger.log(ex);
diff --git a/test/plugins/xml/XmlParserTest.cpp b/test/plugins/xml/XmlParserTest.cpp
index 2046940..6ac2fc1 100644
--- a/test/plugins/xml/XmlParserTest.cpp
+++ b/test/plugins/xml/XmlParserTest.cpp
@@ -38,7 +38,7 @@ TEST(XmlParser, mismatchedTagException)
bool hadException = false;
try {
- p.parse("<document>\n</document2>", ctx);
+ p.parse("<document>\n</document2>", ctx.context);
}
catch (LoggableException ex) {
ASSERT_EQ(2, ex.loc.line);
@@ -81,7 +81,7 @@ TEST(XmlParser, namespaces)
ScopedLogger sl(logger, "test.oxd", SourceLocation{},
CharReader::contextCallback, &reader);
try {
- p.parse(TEST_DATA, ctx);
+ p.parse(TEST_DATA, ctx.context);
}
catch (LoggableException ex) {
logger.log(ex);