diff options
| -rw-r--r-- | src/core/parser/ParserScope.cpp | 14 | ||||
| -rw-r--r-- | src/core/parser/stack/DocumentHandler.cpp | 9 | ||||
| -rw-r--r-- | src/core/parser/stack/Stack.cpp | 3 | ||||
| -rw-r--r-- | test/formats/osxml/OsxmlParserTest.cpp | 3 | ||||
| -rw-r--r-- | testdata/integration/basic_functionality/lots_of_empty_elements.in.osml | 9 | ||||
| -rw-r--r-- | testdata/integration/basic_functionality/lots_of_empty_elements.out.osxml | 22 | 
6 files changed, 50 insertions, 10 deletions
| 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 <iostream> +#endif +  namespace ousia {  /* Class ParserScopeBase */ @@ -214,6 +219,10 @@ void ParserScope::push(Handle<Node> 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> 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<Node> 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<FieldDescriptor> 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 <iostream>  #endif -// TODO: Remove -#include <iostream> -  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<Document> doc = book_document_node.cast<Document>();  	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 @@ +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> +<document> +	<ontology name="test"> +		<struct cardinality="{*}" name="a" root="true" transparent="false"> +			<syntax/> +			<field name="afield" optional="false" subtree="true"> +				<syntax/> +				<childRef ref="a"/> +			</field> +		</struct> +	</ontology> +	<test:a> +		<afield> +			<test:a> +				<afield/> +			</test:a> +			<test:a> +				<afield/> +			</test:a> +		</afield> +	</test:a> +</document> | 
