From bc25012753704943808bb8f71d75f27f68c13da9 Mon Sep 17 00:00:00 2001 From: Benjamin Paassen Date: Thu, 9 Apr 2015 14:56:28 +0200 Subject: fixed a bug in the DocumentHandler which lead to problems in case of empty explicit fields. --- src/core/parser/ParserScope.cpp | 14 +++++++++++++- src/core/parser/stack/DocumentHandler.cpp | 9 +++++---- src/core/parser/stack/Stack.cpp | 3 --- test/formats/osxml/OsxmlParserTest.cpp | 3 +-- .../lots_of_empty_elements.in.osml | 9 +++++++++ .../lots_of_empty_elements.out.osxml | 22 ++++++++++++++++++++++ 6 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 testdata/integration/basic_functionality/lots_of_empty_elements.in.osml create mode 100644 testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml diff --git a/src/core/parser/ParserScope.cpp b/src/core/parser/ParserScope.cpp index e5bf6f6..4b0f376 100644 --- a/src/core/parser/ParserScope.cpp +++ b/src/core/parser/ParserScope.cpp @@ -25,6 +25,11 @@ #include "ParserScope.hpp" +#define SCOPE_DEBUG_OUTPUT 0 +#if SCOPE_DEBUG_OUTPUT +#include +#endif + namespace ousia { /* Class ParserScopeBase */ @@ -214,6 +219,10 @@ void ParserScope::push(Handle node) topLevelNodes.push_back(node); } nodes.push_back(node); + +#if SCOPE_DEBUG_OUTPUT + std::cout << "SCOPE: pushed " << node->type()->name << std::endl; +#endif } void ParserScope::pop(Logger &logger) @@ -233,7 +242,6 @@ void ParserScope::pop(Logger &logger) } } flags.resize(newLen); - // Whenever a RootNode is popped from the stack, we have to perform deferred // resolution and validate the subtree Rooted node = nodes.back(); @@ -247,6 +255,10 @@ void ParserScope::pop(Logger &logger) // Remove the element from the stack nodes.pop_back(); + +#if SCOPE_DEBUG_OUTPUT + std::cout << "SCOPE: popped " << node->type()->name << std::endl; +#endif } NodeVector ParserScope::getTopLevelNodes() const { return topLevelNodes; } diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp index ce6267f..04f79fb 100644 --- a/src/core/parser/stack/DocumentHandler.cpp +++ b/src/core/parser/stack/DocumentHandler.cpp @@ -634,11 +634,12 @@ void DocumentChildHandler::end() case HandlerType::COMMAND: case HandlerType::ANNOTATION_START: case HandlerType::TOKEN: - // In case of explicit fields we do not want to pop something from - // the stack. - if (!isExplicitField) { + if(!isExplicitField){ // pop the "main" element. scope().pop(logger()); + } else{ + // in case of explicit fields, roll back. + rollbackPath(); } break; case HandlerType::ANNOTATION_END: @@ -692,8 +693,8 @@ void DocumentChildHandler::fieldEnd() { if (!isExplicitField) { popTokens(); + rollbackPath(); } - rollbackPath(); } bool DocumentChildHandler::convertData(Handle field, diff --git a/src/core/parser/stack/Stack.cpp b/src/core/parser/stack/Stack.cpp index 88ddeee..41ced2a 100644 --- a/src/core/parser/stack/Stack.cpp +++ b/src/core/parser/stack/Stack.cpp @@ -35,9 +35,6 @@ #include #endif -// TODO: Remove -#include - namespace ousia { namespace parser_stack { namespace { diff --git a/test/formats/osxml/OsxmlParserTest.cpp b/test/formats/osxml/OsxmlParserTest.cpp index 7c7f2a8..a4ff3c2 100644 --- a/test/formats/osxml/OsxmlParserTest.cpp +++ b/test/formats/osxml/OsxmlParserTest.cpp @@ -396,9 +396,8 @@ TEST(OsxmlParser, emptyNamedField){ Rooted doc = book_document_node.cast(); ASSERT_TRUE(doc->validate(logger)); checkStructuredEntity(doc->getRoot(), doc, doc, "a"); - ASSERT_EQ(2U, doc->getRoot()->getDescriptor()->getFieldDescriptors().size()); + ASSERT_EQ(1U, doc->getRoot()->getDescriptor()->getFieldDescriptors().size()); ASSERT_TRUE(doc->getRoot()->getField(0).empty()); - ASSERT_TRUE(doc->getRoot()->getField(1).empty()); } } diff --git a/testdata/integration/basic_functionality/lots_of_empty_elements.in.osml b/testdata/integration/basic_functionality/lots_of_empty_elements.in.osml new file mode 100644 index 0000000..aabdfae --- /dev/null +++ b/testdata/integration/basic_functionality/lots_of_empty_elements.in.osml @@ -0,0 +1,9 @@ +\document + \ontology#test + \struct#a[root=true] + \field#afield[subtree=true] + \childRef[ref=a] + +\begin{a} +\afield{\a{}\a{}} +\end{a} diff --git a/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml b/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml new file mode 100644 index 0000000..5a7522e --- /dev/null +++ b/testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3