diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-04-12 17:40:32 +0200 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:24:16 +0200 |
commit | bed013e617130f7afd1f90ba57afc160b43c71df (patch) | |
tree | bb5d335132a522e24351e5a3239355f7a9ca2070 /src/core/parser/stack/DocumentHandler.cpp | |
parent | 84ab3caa172fc3f4ec7085135964173c8eed5f84 (diff) |
Implement non-greedy behaviour for short tokens
Diffstat (limited to 'src/core/parser/stack/DocumentHandler.cpp')
-rw-r--r-- | src/core/parser/stack/DocumentHandler.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
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<SyntaxDescriptor> 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<Node> &stack = scope().getStack(); @@ -157,6 +162,10 @@ void DocumentChildHandler::pushScopeTokens() if (nd->isa(&RttiTypes::DocumentField)) { Rooted<DocumentField> field = nd.cast<DocumentField>(); 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<StructuredEntity> entity = nd.cast<StructuredEntity>(); if (!entity->isTransparent()) { + if (explicitSkipCount > 0) { + explicitSkipCount--; + continue; + } descrs = entity->getDescriptor()->getPermittedTokens(); break; } @@ -591,12 +604,13 @@ bool DocumentChildHandler::startToken(Handle<Node> node, bool greedy) } } -EndTokenResult DocumentChildHandler::endToken(Handle<Node> node, size_t maxStackDepth) +EndTokenResult DocumentChildHandler::endToken(Handle<Node> node, + size_t maxStackDepth) { // Fetch the current scope stack const ManagedVector<Node> &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 |