diff options
| author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-04-12 17:38:36 +0200 | 
|---|---|---|
| committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:24:15 +0200 | 
| commit | 2416462060ef54cb737688f648d150313b82e5f4 (patch) | |
| tree | 3de90284b12531c98ac1b5058d8d788348a3b9f3 /src | |
| parent | 8bfc7878a725d8f1c2754893bc8b660ff78f89bf (diff) | |
Pass "greedy" flag to Handler::startToken
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/parser/stack/DocumentHandler.cpp | 8 | ||||
| -rw-r--r-- | src/core/parser/stack/DocumentHandler.hpp | 8 | ||||
| -rw-r--r-- | src/core/parser/stack/Handler.cpp | 4 | ||||
| -rw-r--r-- | src/core/parser/stack/Handler.hpp | 8 | ||||
| -rw-r--r-- | src/core/parser/stack/Stack.cpp | 15 | 
5 files changed, 33 insertions, 10 deletions
| diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp index 0912eb6..aa9a28f 100644 --- a/src/core/parser/stack/DocumentHandler.cpp +++ b/src/core/parser/stack/DocumentHandler.cpp @@ -89,6 +89,7 @@ Rooted<FieldDescriptor> DocumentField::getDescriptor()  DocumentChildHandler::DocumentChildHandler(const HandlerData &handlerData)      : Handler(handlerData),        isExplicitField(false), +      isGreedy(true),        inImplicitDefaultField(false)  {  	// Register all user defined tokens if this has not yet been done @@ -508,8 +509,13 @@ bool DocumentChildHandler::startAnnotation(Variant::mapType &args)  	return true;  } -bool DocumentChildHandler::startToken(Handle<Node> node) +bool DocumentChildHandler::startToken(Handle<Node> node, bool greedy)  { +	// Copy the "greedy" flag. If not greedy, set the inImplicitDefaultField +	// flag to true, in order to push the tokens of the previous command. +	isGreedy = greedy; +	inImplicitDefaultField = !greedy; +  	bool isStruct = node->isa(&RttiTypes::StructuredClass);  	//	bool isField = node->isa(&RttiTypes::FieldDescriptor);  	//	bool isAnnotation = node->isa(&RttiTypes::AnnotationClass); diff --git a/src/core/parser/stack/DocumentHandler.hpp b/src/core/parser/stack/DocumentHandler.hpp index d047666..216b2fe 100644 --- a/src/core/parser/stack/DocumentHandler.hpp +++ b/src/core/parser/stack/DocumentHandler.hpp @@ -115,6 +115,12 @@ private:  	bool isExplicitField : 1;  	/** +	 * Set to false, if this handler was started from a token and is not greedy. +	 * True otherwise. +	 */ +	bool isGreedy : 1; + +	/**  	 * Set to true if the handler currently is in an implicit field.  	 */  	bool inImplicitDefaultField : 1; @@ -226,7 +232,7 @@ public:  	bool startCommand(Variant::mapType &args) override;  	bool startAnnotation(Variant::mapType &args) override; -	bool startToken(Handle<Node> node) override; +	bool startToken(Handle<Node> node, bool greedy) override;  	EndTokenResult endToken(Handle<Node> node, size_t maxStackDepth) override;  	void end() override;  	bool data() override; diff --git a/src/core/parser/stack/Handler.cpp b/src/core/parser/stack/Handler.cpp index 850da74..49c06ba 100644 --- a/src/core/parser/stack/Handler.cpp +++ b/src/core/parser/stack/Handler.cpp @@ -129,7 +129,7 @@ bool EmptyHandler::startAnnotation(Variant::mapType &args)  	return false;  } -bool EmptyHandler::startToken(Handle<Node> node) +bool EmptyHandler::startToken(Handle<Node> node, bool greedy)  {  	// EmptyHandler does not support tokens.  	return false; @@ -179,7 +179,7 @@ bool StaticHandler::startCommand(Variant::mapType &args)  bool StaticHandler::startAnnotation(Variant::mapType &args) { return false; } -bool StaticHandler::startToken(Handle<Node> node) { return false; } +bool StaticHandler::startToken(Handle<Node> node, bool greedy) { return false; }  EndTokenResult StaticHandler::endToken(Handle<Node> node, size_t maxStackDepth)  { diff --git a/src/core/parser/stack/Handler.hpp b/src/core/parser/stack/Handler.hpp index 40b4fba..1ae4547 100644 --- a/src/core/parser/stack/Handler.hpp +++ b/src/core/parser/stack/Handler.hpp @@ -393,8 +393,10 @@ public:  	 * tokenId() method.  	 *  	 * @param node is the node for which this token was registered. +	 * @param greedy is set to false if the token should not behave in a greedy +	 * fashion.  	 */ -	virtual bool startToken(Handle<Node> node) = 0; +	virtual bool startToken(Handle<Node> node, bool greedy) = 0;  	/**  	 * Called whenever a token is marked as "end" token and this handler happens @@ -470,7 +472,7 @@ protected:  public:  	bool startCommand(Variant::mapType &args) override;  	bool startAnnotation(Variant::mapType &args) override; -	bool startToken(Handle<Node> node) override; +	bool startToken(Handle<Node> node, bool greedy) override;  	EndTokenResult endToken(Handle<Node> node, size_t maxStackDepth) override;  	void end() override;  	bool fieldStart(bool &isDefault, bool isImplicit, size_t fieldIdx) override; @@ -495,7 +497,7 @@ protected:  public:  	bool startCommand(Variant::mapType &args) override;  	bool startAnnotation(Variant::mapType &args) override; -	bool startToken(Handle<Node> node) override; +	bool startToken(Handle<Node> node, bool greedy) override;  	EndTokenResult endToken(Handle<Node> node, size_t maxStackDepth) override;  	void end() override;  	bool fieldStart(bool &isDefault, bool isImplicit, size_t fieldIdx) override; diff --git a/src/core/parser/stack/Stack.cpp b/src/core/parser/stack/Stack.cpp index 2fe4a8f..c67f43c 100644 --- a/src/core/parser/stack/Stack.cpp +++ b/src/core/parser/stack/Stack.cpp @@ -117,6 +117,12 @@ public:  	bool hadDefaultField : 1;  	/** +	 * Set to false, if the handler is not greedy (true is the default value). +	 * If false, the handler will only be passed one piece of "data" at most. +	 */ +	bool greedy : 1; + +	/**  	 * Default constructor of the HandlerInfo class.  	 */  	HandlerInfo(); @@ -187,7 +193,8 @@ HandlerInfo::HandlerInfo(std::shared_ptr<Handler> handler)        inDefaultField(false),        inImplicitDefaultField(false),        inValidField(false), -      hadDefaultField(false) +      hadDefaultField(false), +      greedy(true)  {  } @@ -203,7 +210,8 @@ HandlerInfo::HandlerInfo(bool implicit, bool inField, bool inDefaultField,        inDefaultField(inDefaultField),        inImplicitDefaultField(inImplicitDefaultField),        inValidField(true), -      hadDefaultField(false) +      hadDefaultField(false), +      greedy(true)  {  } @@ -1073,8 +1081,9 @@ bool StackImpl::handleOpenTokens(Logger &logger, const Token &token,  		// the valid flag  		HandlerInfo &info = currentInfo();  		info.valid = false; +		info.greedy = (!shortForm) || descr.greedyShortForm;  		try { -			info.valid = handler->startToken(descr.descriptor); +			info.valid = handler->startToken(descr.descriptor, info.greedy);  		}  		catch (LoggableException ex) {  			logger.log(ex); | 
