summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/parser/stack/DocumentHandler.cpp8
-rw-r--r--src/core/parser/stack/DocumentHandler.hpp8
-rw-r--r--src/core/parser/stack/Handler.cpp4
-rw-r--r--src/core/parser/stack/Handler.hpp8
-rw-r--r--src/core/parser/stack/Stack.cpp15
-rw-r--r--test/core/parser/stack/StackTest.cpp2
6 files changed, 34 insertions, 11 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);
diff --git a/test/core/parser/stack/StackTest.cpp b/test/core/parser/stack/StackTest.cpp
index 739bc99..3ed18d0 100644
--- a/test/core/parser/stack/StackTest.cpp
+++ b/test/core/parser/stack/StackTest.cpp
@@ -153,7 +153,7 @@ public:
return tracker.startAnnotationResult;
}
- bool startToken(Handle<Node> node) override
+ bool startToken(Handle<Node> node, bool greedy) override
{
tracker.startTokenCount++;
return tracker.startTokenResult;