From bed013e617130f7afd1f90ba57afc160b43c71df Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 12 Apr 2015 17:40:32 +0200 Subject: Implement non-greedy behaviour for short tokens --- src/core/parser/stack/DocumentHandler.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/core/parser/stack/DocumentHandler.cpp') diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp index aa9a28f..7564fad 100644 --- a/src/core/parser/stack/DocumentHandler.cpp +++ b/src/core/parser/stack/DocumentHandler.cpp @@ -145,6 +145,11 @@ void DocumentChildHandler::pushScopeTokens() // List containing the unfiltered syntax descriptors std::vector descrs; + // Skip the DocumentField and the curresponding StructuredEntity + // if we're currently in the implicit default field of a non-greedy + // structure. + size_t explicitSkipCount = (!isGreedy && inImplicitDefaultField) ? 2 : 0; + // Fetch the current scope stack and search the first non-transparent field // or structure const ManagedVector &stack = scope().getStack(); @@ -157,6 +162,10 @@ void DocumentChildHandler::pushScopeTokens() if (nd->isa(&RttiTypes::DocumentField)) { Rooted field = nd.cast(); if (!field->transparent) { + if (explicitSkipCount > 0) { + explicitSkipCount--; + continue; + } descrs = field->getDescriptor()->getPermittedTokens(); break; } @@ -166,6 +175,10 @@ void DocumentChildHandler::pushScopeTokens() if (nd->isa(&RttiTypes::StructuredEntity)) { Rooted entity = nd.cast(); if (!entity->isTransparent()) { + if (explicitSkipCount > 0) { + explicitSkipCount--; + continue; + } descrs = entity->getDescriptor()->getPermittedTokens(); break; } @@ -591,12 +604,13 @@ bool DocumentChildHandler::startToken(Handle node, bool greedy) } } -EndTokenResult DocumentChildHandler::endToken(Handle node, size_t maxStackDepth) +EndTokenResult DocumentChildHandler::endToken(Handle node, + size_t maxStackDepth) { // Fetch the current scope stack const ManagedVector &stack = scope().getStack(); - bool found = false; // true once the given node has been found + bool found = false; // true once the given node has been found bool repeat = false; size_t scopeStackDepth = 0; // # of elems on the scope stack size_t currentStackDepth = 0; // # of "explicit" elems on the parser stack -- cgit v1.2.3