summaryrefslogtreecommitdiff
path: root/src/core/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/parser')
-rw-r--r--src/core/parser/ParserContext.cpp29
-rw-r--r--src/core/parser/ParserContext.hpp114
-rw-r--r--src/core/parser/ParserScope.hpp1
-rw-r--r--src/core/parser/ParserStack.cpp3
-rw-r--r--src/core/parser/ParserStack.hpp27
5 files changed, 118 insertions, 56 deletions
diff --git a/src/core/parser/ParserContext.cpp b/src/core/parser/ParserContext.cpp
index fa26c59..0a75fdf 100644
--- a/src/core/parser/ParserContext.cpp
+++ b/src/core/parser/ParserContext.cpp
@@ -22,15 +22,28 @@ namespace ousia {
/* Class ParserContext */
-ParserContext::ParserContext(ParserScope &scope, Registry &registry,
- Logger &logger, Manager &manager,
- Handle<model::Project> project)
- : scope(scope),
- registry(registry),
- logger(logger),
- manager(manager),
- project(project)
+ParserContext::ParserContext(Handle<Project> project, ParserScope &scope,
+ SourceId sourceId, Logger &logger)
+ : project(project), scope(scope), sourceId(sourceId), logger(logger)
{
}
+
+ParserContext::ParserContext(Handle<Project> project, ParserScope &scope,
+ Logger &logger)
+ : project(project), scope(scope), sourceId(InvalidSourceId), logger(logger)
+{
+}
+
+ParserContext ParserContext::clone(ParserScope &scope, SourceId sourceId) const
+{
+ return ParserContext{project, scope, sourceId, logger};
+}
+
+ParserContext ParserContext::clone(SourceId sourceId) const
+{
+ return ParserContext{project, scope, sourceId, logger};
+}
+
+Manager &ParserContext::getManager() const { return project->getManager(); }
}
diff --git a/src/core/parser/ParserContext.hpp b/src/core/parser/ParserContext.hpp
index bb64600..c44222f 100644
--- a/src/core/parser/ParserContext.hpp
+++ b/src/core/parser/ParserContext.hpp
@@ -28,64 +28,128 @@
#ifndef _OUSIA_PARSER_CONTEXT_HPP_
#define _OUSIA_PARSER_CONTEXT_HPP_
+#include <core/common/Location.hpp>
#include <core/managed/Managed.hpp>
-#include <core/model/Node.hpp>
#include <core/model/Project.hpp>
+#include "ParserScope.hpp"
+
namespace ousia {
// Forward declaration
class Logger;
-class ParserScope;
-class Registry;
/**
- * Struct containing the objects that are passed to a parser instance.
+ * Class containing the objects that are passed to a parser instance.
*/
-struct ParserContext {
+class ParserContext {
+private:
/**
- * Reference to the ParserScope instance that should be used within the parser.
+ * Project instance into which the new content should be parsed.
*/
- ParserScope &scope;
+ Rooted<Project> project;
/**
- * Reference to the Registry instance that should be used within the parser.
+ * Reference to the ParserScope instance that should be used within the
+ * parser.
*/
- Registry &registry;
+ ParserScope &scope;
/**
- * Reference to the Logger the parser should log any messages to.
+ * SourceId is the ID of the resource that is currently being processed.
*/
- Logger &logger;
+ SourceId sourceId;
/**
- * Reference to the Manager the parser should append nodes to.
+ * Reference to the Logger the parser should log any messages to.
*/
- Manager &manager;
+ Logger &logger;
+public:
/**
- * Project instance into which the new content should be parsed.
+ * Constructor of the ParserContext class.
+ *
+ * @param project is the project into which the content should be parsed.
+ * @param scope is a reference to the ParserScope instance that should be
+ * used to lookup names.
+ * @param sourceId is a SourceId instance specifying the source the parser
+ * is reading from.
+ * @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.
*/
- Rooted<model::Project> project;
+ ParserContext(Handle<Project> project, ParserScope &scope,
+ SourceId sourceId, Logger &logger);
/**
- * Constructor of the ParserContext class.
+ * Constructor of the ParserContext class with the sourceId being set
+ * to the InvalidSourceId value.
*
+ * @param project is the project into which the content should be parsed.
* @param scope is a reference to the ParserScope instance that should be
* used to lookup names.
- * @param registry is a reference at the Registry class, which allows to
- * obtain references at parsers for other formats or script engine
- * implementations.
* @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.
- * @param project is the project into which the content should be parsed.
*/
- ParserContext(ParserScope &scope, Registry &registry, Logger &logger,
- Manager &manager, Handle<model::Project> project);
-};
+ ParserContext(Handle<Project> project, ParserScope &scope,
+ Logger &logger);
+
+ /**
+ * Clones the ParserContext instance but exchanges the ParserScope instance
+ * and the source id.
+ *
+ * @param scope is a reference at the new ParserScope instance.
+ * @param sourceId is the source id the parser is reading from.
+ * @return a copy of this ParserContext with exchanged scope and source id.
+ */
+ ParserContext clone(ParserScope &scope, SourceId sourceId) const;
+ /**
+ * Clones the ParserContext instance but exchanges the source id.
+ *
+ * @param sourceId is the source id the parser is reading from.
+ * @return a copy of this ParserContext with exchanged source id.
+ */
+ ParserContext clone(SourceId sourceId) const;
+
+ /**
+ * Returns a handle pointing at the Project node.
+ *
+ * @return a project node handle.
+ */
+ Rooted<Project> getProject() const { return project; }
+
+ /**
+ * Returns a reference pointing at the current ParserScope instance.
+ *
+ * @return a reference at the parser scope object that should be used during
+ * the parsing process.
+ */
+ ParserScope &getScope() const { return scope; }
+
+ /**
+ * Returns a reference pointing at the current LoggerInstance.
+ *
+ * @return a reference at LoggerInstance to which all error messages should
+ * be logged.
+ */
+ Logger &getLogger() const { return logger; }
+
+ /**
+ * Returns a reference pointing at the manager instance that should be used
+ * when creating new Managed objects.
+ *
+ * @return a reference pointing at the underlying Manager instance.
+ */
+ Manager &getManager() const;
+
+ /**
+ * Returns the SourceId instance which specifies the source file the parser
+ * is currently reading from.
+ *
+ * @return the current source id.
+ */
+ SourceId getSourceId() const { return sourceId; }
+};
}
#endif /* _OUSIA_PARSER_CONTEXT_HPP_ */
diff --git a/src/core/parser/ParserScope.hpp b/src/core/parser/ParserScope.hpp
index a759738..c1369dd 100644
--- a/src/core/parser/ParserScope.hpp
+++ b/src/core/parser/ParserScope.hpp
@@ -41,7 +41,6 @@ namespace ousia {
// Forward declaration
class CharReader;
-class Registry;
class Logger;
class ParserScope;
diff --git a/src/core/parser/ParserStack.cpp b/src/core/parser/ParserStack.cpp
index 3792ee8..02b142a 100644
--- a/src/core/parser/ParserStack.cpp
+++ b/src/core/parser/ParserStack.cpp
@@ -22,6 +22,7 @@
#include <core/common/Utils.hpp>
#include <core/common/Exceptions.hpp>
+#include <core/model/Project.hpp>
namespace ousia {
@@ -74,7 +75,7 @@ HandlerInstance HandlerDescriptor::create(const ParserContext &ctx,
}
// Canonicalize the arguments
- arguments.validateMap(args, ctx.logger, true);
+ arguments.validateMap(args, ctx.getLogger(), true);
h->start(args);
return HandlerInstance(h, this);
diff --git a/src/core/parser/ParserStack.hpp b/src/core/parser/ParserStack.hpp
index 6296dff..031ce68 100644
--- a/src/core/parser/ParserStack.hpp
+++ b/src/core/parser/ParserStack.hpp
@@ -139,15 +139,13 @@ public:
const std::string &name() { return handlerData.name; }
- ParserScope &scope() { return handlerData.ctx.scope; }
+ ParserScope &scope() { return handlerData.ctx.getScope(); }
- Registry &registry() { return handlerData.ctx.registry; }
+ Manager &manager() { return handlerData.ctx.getManager(); }
- Manager &manager() { return handlerData.ctx.manager; }
+ Logger &logger() { return handlerData.ctx.getLogger(); }
- Logger &logger() { return handlerData.ctx.logger; }
-
- Rooted<model::Project> project() { return handlerData.ctx.project; }
+ Rooted<Project> project() { return handlerData.ctx.getProject(); }
State state() { return handlerData.state; }
@@ -322,11 +320,6 @@ private:
std::stack<HandlerInstance> stack;
/**
- * Reference at some user defined data.
- */
- void *userData;
-
- /**
* Used internally to get all expected command names for the given state
* (does not work if the current Handler instance allows arbitrary
* children). This function is used to build error messages.
@@ -345,9 +338,8 @@ public:
* corresponding HandlerDescriptor instances.
*/
ParserStack(ParserContext &ctx,
- const std::multimap<std::string, HandlerDescriptor> &handlers,
- void *userData = nullptr)
- : ctx(ctx), handlers(handlers), userData(userData){};
+ const std::multimap<std::string, HandlerDescriptor> &handlers)
+ : ctx(ctx), handlers(handlers){};
/**
* Returns the state the ParserStack instance currently is in.
@@ -425,13 +417,6 @@ public:
* @return a reference to the parser context.
*/
ParserContext &getContext() { return ctx; }
-
- /**
- * Returns the user defined data.
- *
- * @return the userData pointer that was given in the constructor.
- */
- void *getUserData() { return userData; }
};
}