summaryrefslogtreecommitdiff
path: root/src/core/parser/generic/GenericParser.hpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-14 23:44:16 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-14 23:44:16 +0100
commitc04111da83612e942e3b6c0d624812c37228006a (patch)
tree2867dd7d00be7aa809ccdd1a3ab25756994e907e /src/core/parser/generic/GenericParser.hpp
parentce4fd84a714d80859aa01bbca32a81302b93c4d7 (diff)
Introduced "GenericParser" class for common code shared between parsers
Diffstat (limited to 'src/core/parser/generic/GenericParser.hpp')
-rw-r--r--src/core/parser/generic/GenericParser.hpp93
1 files changed, 91 insertions, 2 deletions
diff --git a/src/core/parser/generic/GenericParser.hpp b/src/core/parser/generic/GenericParser.hpp
index 4f29f94..53cb982 100644
--- a/src/core/parser/generic/GenericParser.hpp
+++ b/src/core/parser/generic/GenericParser.hpp
@@ -33,14 +33,103 @@
#ifndef _OUSIA_GENERIC_PARSER_HPP_
#define _OUSIA_GENERIC_PARSER_HPP_
-#include <core/parser/Parseer.hpp>
+#include <core/parser/Parser.hpp>
+
+#include "ParserStateStack.hpp"
+#include "ParserStateHandler.hpp"
+#include "ParserState.hpp"
namespace ousia {
-class GenericParser : public Parser {
+/**
+ * The abstract GenericParser class is merely a convenience class for Parsers
+ * which use the ParserStateStack class. It maintains a ParserStateStack
+ * instance and provides functions which directly forward the given data to the
+ * ParserStateStack. It also implements the ParserStateCallbacks inteface which
+ * is used by ParserStateHandlers to influence the parsing process (such as
+ * setting the whitespace mode or registering new entities).
+ */
+class GenericParser : public Parser, public ParserStateCallbacks {
+
+private:
+ /**
+ * Internal ParserStateStack instance.
+ */
+ ParserStateStack stack;
+
+protected:
+ /**
+ * Forwards the "command" event to the ParserStateStack instance.
+ *
+ * @param name is the name of the command (including the namespace
+ * separator ':') and its corresponding location. Must be a string variant.
+ * @param args is a map variant containing the arguments that were passed to
+ * the command.
+ */
+ void command(Variant name, Variant args)
+ {
+ stack.command(std::move(name), std::move(args));
+ }
+
+ /**
+ * Forwards the "fieldStart" event to the ParserStateStack instance.
+ */
+ void fieldStart()
+ {
+ stack.fieldStart();
+ }
+
+ /**
+ * Forwards the "fieldEnd" event to the ParserStateStack instance.
+ */
+ void fieldEnd()
+ {
+ stack.fieldEnd();
+ }
+
+ /**
+ * Forwards the "data" event to the ParserStateStack instance.
+ *
+ * @param data is a variant of any type containing the data that was parsed
+ * as data.
+ */
+ void data(Variant data)
+ {
+ stack.data(std::move(data));
+ }
+ /**
+ * Forwards the "annotationStart" event to the ParserStateStack instance.
+ *
+ * @param name is the name of the annotation class.
+ * @param args is a map variant containing the arguments that were passed
+ * to the annotation.
+ */
+ void annotationStart(Variant name, Variant args)
+ {
+ stack.annotationStart(std::move(name), std::move(args));
+ }
+ /**
+ * Forwards the "annotationEnd" event to the ParserStateStack instance.
+ *
+ * @param name is the name of the annotation class that was ended.
+ * @param annotationName is the name of the annotation that was ended.
+ */
+ void annotationEnd(Variant name, Variant annotationName)
+ {
+ stack.annotationEnd(std::move(name), std::move(annotationName));
+ }
+ /**
+ * Forwards the "token" call to the ParserStateStack instance.
+ *
+ * @param token is string variant containing the token that was encountered.
+ */
+ void token(Variant token)
+ {
+ stack.token(std::move(token));
+ }
};
}