From 6decad0b8e7e369bd8215f31a45dd3eae982d2a9 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 21 Jan 2015 01:17:49 +0100 Subject: Some further refactoring -- renamed Scope to ParserScope, got rid of parser namespace, added new functionality to RegistryClass, wrote documentation, added function for extracting file extensions to Utils --- src/core/parser/Parser.hpp | 101 +++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 72 deletions(-) (limited to 'src/core/parser/Parser.hpp') diff --git a/src/core/parser/Parser.hpp b/src/core/parser/Parser.hpp index 049ee4e..e4419f5 100644 --- a/src/core/parser/Parser.hpp +++ b/src/core/parser/Parser.hpp @@ -32,94 +32,52 @@ #include #include -#include -#include -#include -#include +#include #include -#include - -#include "Scope.hpp" namespace ousia { -namespace parser { -// TODO: Implement a proper Mimetype class +// Forward declarations +class CharReader; +class ParserContext; /** - * Struct containing the objects that are passed to a parser instance. + * Abstract parser class. This class builds the basic interface that should be + * used by any parser which reads data from an input stream and transforms it + * into an Ousía node graph. */ -struct ParserContext { - /** - * Reference to the Scope instance that should be used within the parser. - */ - Scope &scope; - - /** - * Reference to the Registry instance that should be used within the parser. - */ - Registry ®istry; - - /** - * Reference to the Logger the parser should log any messages to. - */ - Logger &logger; - +class Parser { +protected: /** - * Reference to the Manager the parser should append nodes to. + * Parses the given input stream and returns a corresponding node for + * inclusion in the document graph. This method should be overridden by + * derived classes. + * + * @param reader is a reference to the CharReader that should be used. + * @param ctx is a reference to the context that should be used while + * parsing the document. + * @return a reference to the node representing the subgraph that has been + * created. The resulting node may point at not yet resolved entities, the + * calling code will try to resolve these. If no valid node can be produced, + * a corresponding LoggableException must be thrown by the parser. */ - Manager &manager; + virtual Rooted doParse(CharReader &reader, ParserContext &ctx) = 0; +public: /** - * Project instance into which the new content should be parsed. + * Default constructor. */ - Rooted project; + Parser() {} /** - * Constructor of the ParserContext class. - * - * @param scope is a reference to the Scope 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. + * No copy construction. */ - ParserContext(Scope &scope, Registry ®istry, Logger &logger, - Manager &manager, Handle project) - : scope(scope), - registry(registry), - logger(logger), - manager(manager), - project(project){}; -}; - -/** - * Abstract parser class. This class builds the basic interface that should be - * used by any parser which reads data from an input stream and transforms it - * into an Ousía node graph. - */ -class Parser { -public: - Parser(){}; Parser(const Parser &) = delete; /** - * Returns a set containing all mime types supported by the parser. The mime - * types are used to describe the type of the document that is read by the - * parser. The default implementation returns an empty set. This method - * should be overridden by derived classes. - * - * @return a set containing the string value of the supported mime types. + * Virtual destructor. */ - virtual std::set mimetypes() - { - return std::set{}; - }; + virtual ~Parser(){}; /** * Parses the given input stream and returns a corresponding node for @@ -132,9 +90,9 @@ public: * @return a reference to the node representing the subgraph that has been * created. The resulting node may point at not yet resolved entities, the * calling code will try to resolve these. If no valid node can be produced, - * a corresponding LoggableException must be thrown by the parser. + * a corresponding ParserException must be thrown by the parser. */ - virtual Rooted parse(CharReader &reader, ParserContext &ctx) = 0; + Rooted parse(CharReader &reader, ParserContext &ctx); /** * Parses the given string and returns a corresponding node for @@ -152,7 +110,6 @@ public: Rooted parse(const std::string &str, ParserContext &ctx); }; } -} #endif /* _OUSIA_PARSER_HPP_ */ -- cgit v1.2.3