From 7a959de0b1bf890c5deefdc132fe30f20661ca9b Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 27 Jan 2015 19:44:10 +0100 Subject: Introduced notion of "flags" that can be set at a certain level of the ParserScope in order to store data that should be available between parser instances, but cannot be stored in the object graph. --- src/core/parser/ParserScope.hpp | 105 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 10 deletions(-) (limited to 'src/core/parser/ParserScope.hpp') diff --git a/src/core/parser/ParserScope.hpp b/src/core/parser/ParserScope.hpp index 191d08b..2c6093f 100644 --- a/src/core/parser/ParserScope.hpp +++ b/src/core/parser/ParserScope.hpp @@ -165,6 +165,19 @@ public: bool resolve(Logger &logger); }; +/** + * Enum containing all possible parser flags that can be used by parsers to + * signal states that cannot be (explicitly or implicitly) stored in the node + * graph itself. + */ +enum class ParserFlag { + /** + * Set to the boolean value "true" if the head section of a file has passed. + * This happens once the first non-import tag is reached. + */ + POST_HEAD +}; + /** * Provides an interface for document parsers to resolve references based on the * current position in the created document tree. The ParserScope class itself @@ -172,12 +185,56 @@ public: * reference to a Node object attached to it. */ class ParserScope : public ParserScopeBase { +public: + /** + * Struct describing a set parser flag. + */ + struct ParserFlagDescriptor { + /** + * Stack depth at which the flag has been set. + */ + size_t depth; + + /** + * Flag that has been set. + */ + ParserFlag flag; + + /** + * Value of that flag. + */ + bool value; + + /** + * Default constructor. + */ + ParserFlagDescriptor() {} + + /** + * Constructor of the parser flag descriptor class. + * + * @param depth is the depth at which the flag was set. + * @param flag is the flag that has been set. + * @param value is the value that has been set for that flag. + */ + ParserFlagDescriptor(size_t depth, ParserFlag flag, bool value) + : depth(depth), flag(flag), value(value) + { + } + }; + private: /** * List containing all deferred resolution descriptors. */ std::list deferred; + /** + * Vector containing all set flags. The vector contains triples of the + * depth at which the flag was set, the flag itself and the value. + */ + std::vector flags; + /** * Depth of the "nodes" list when the ParserScope was created. */ @@ -192,7 +249,8 @@ private: /** * Private constructor used to create a ParserScope fork. */ - ParserScope(const NodeVector &nodes); + ParserScope(const NodeVector &nodes, + const std::vector &flags); public: /** @@ -273,13 +331,33 @@ public: */ Rooted getLeaf() const; + /** + * Sets a parser flag for the current stack depth. + * + * @param flag is the flag that should be set. + * @param value is the value to which the flag should be set. + */ + void setFlag(ParserFlag flag, bool value); + + /** + * Gets the parser flag for the current stack depth, ascends the stack until + * a set for this flag is found. Returns false if the flag is not set. + * + * @param flag is the flag for which the value should be returned. + * @return the value that was previously set by setParserFlag or false if no + * value has been set. + */ + bool getFlag(ParserFlag flag); + /** * Tries to resolve a node for the given type and path for all nodes * currently on the stack, starting with the topmost node on the stack. - * Calls the "imposterCallback" function for obtaining a temporary result if + * Calls the "imposterCallback" function for obtaining a temporary + *result if * a node cannot be resolved right now. The "resultCallback" is at most * called twice: Once when this method is called (probably with the - * temporary) and another time if the resolution turned out to be successful + * temporary) and another time if the resolution turned out to be + *successful * at a later point in time. * * @param path is the path for which a node should be resolved. @@ -288,17 +366,24 @@ public: * should be logged. * @param imposterCallback is the callback function that is called if * the node cannot be resolved at this moment. It gives the caller the - * possibility to create an imposter (a temporary object) that may be used + * possibility to create an imposter (a temporary object) that may be + *used * later in the resolution process. * @param resultCallback is the callback function to which the result of - * the resolution process is passed. This function is called at least once - * either with the imposter (if the resolution was not successful) or the - * resolved object directly when this function is called. If the resolution - * was not successful the first time, it may be called another time later + * the resolution process is passed. This function is called at least + *once + * either with the imposter (if the resolution was not successful) or + *the + * resolved object directly when this function is called. If the + *resolution + * was not successful the first time, it may be called another time + *later * in the context of the "performDeferredResolution" function. - * @param location is the location in the current source file in which the + * @param location is the location in the current source file in which + *the * resolution was triggered. - * @return true if the resolution was immediately successful. This does not + * @return true if the resolution was immediately successful. This does + *not * mean, that the resolved object does not exist, as it may be resolved * later. */ -- cgit v1.2.3