From d369ff33faa4bf5654db3f1eb105141fccf2270d Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sat, 11 Apr 2015 16:51:38 +0200 Subject: Reimplement closeToken handling Idea: Only start unrolling anything on the parser stack if an element that matches the given close token is found. This requires the endToken method in DocumentChildHandler to search for the given descriptor that might be ended. While performing this search, only a specified number of "explicit" structures/fields opened by the Stack class may be skipped (those with implicit default fields). Added an integration test ("python_code") which requires this new (hopefully sane) behaviour. --- src/core/parser/stack/Handler.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/core/parser/stack/Handler.cpp') diff --git a/src/core/parser/stack/Handler.cpp b/src/core/parser/stack/Handler.cpp index 1399fef..69bfc76 100644 --- a/src/core/parser/stack/Handler.cpp +++ b/src/core/parser/stack/Handler.cpp @@ -47,7 +47,8 @@ Handler::Handler(const HandlerData &handlerData) { } -Handler::~Handler() { +Handler::~Handler() +{ while (tokenStackDepth > 0) { popTokens(); } @@ -90,7 +91,8 @@ void Handler::pushTokens(const std::vector &tokens) handlerData.callbacks.pushTokens(tokens); } -void Handler::popTokens() { +void Handler::popTokens() +{ assert(tokenStackDepth > 0 && "popTokens called too often"); tokenStackDepth--; handlerData.callbacks.popTokens(); @@ -133,11 +135,10 @@ bool EmptyHandler::startToken(Handle node) return false; } -Handler::EndTokenResult EmptyHandler::endToken(const Token &token, - Handle node) +EndTokenResult EmptyHandler::endToken(Handle node, size_t maxStackDepth) { // There are no tokens to end here. - return EndTokenResult::ENDED_NONE; + return EndTokenResult(); } void EmptyHandler::end() @@ -179,10 +180,10 @@ bool StaticHandler::startAnnotation(Variant::mapType &args) { return false; } bool StaticHandler::startToken(Handle node) { return false; } -Handler::EndTokenResult StaticHandler::endToken(const Token &token, - Handle node) +EndTokenResult StaticHandler::endToken(Handle node, size_t maxStackDepth) { - return EndTokenResult::ENDED_NONE; + // There are no tokens to end here. + return EndTokenResult(); } void StaticHandler::end() -- cgit v1.2.3