summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/parser/stack/DocumentHandler.cpp30
-rw-r--r--test/formats/osml/OsmlParserTest.cpp27
-rw-r--r--testdata/osmlparser/include_child.osml4
-rw-r--r--testdata/osmlparser/include_recursive.osml1
-rw-r--r--testdata/osmlparser/include_recursive_root.osml10
-rw-r--r--testdata/osmlparser/include_root.osml20
-rw-r--r--testdata/osmlparser/simple_book.osml31
7 files changed, 81 insertions, 42 deletions
diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp
index 4038a42..e928a54 100644
--- a/src/core/parser/stack/DocumentHandler.cpp
+++ b/src/core/parser/stack/DocumentHandler.cpp
@@ -428,16 +428,24 @@ bool DocumentChildHandler::data(Variant &data)
}
// No field was found that might take the data -- dump the error messages
- // from the loggers
- logger().error("Could not read data with any of the possible fields:",
- SourceLocation{}, MessageMode::NO_CONTEXT);
- size_t f = 0;
- for (auto field : defaultFields) {
- logger().note(std::string("Field ") + Utils::join(field->path(), ".") +
- std::string(":"),
- SourceLocation{}, MessageMode::NO_CONTEXT);
- forks[f].commit();
- f++;
+ // from the loggers -- or, if there were no primitive fields, clearly state
+ // this fact
+ if (defaultFields.empty()) {
+ logger().error("Got data, but structure \"" + name() +
+ "\" does not have any primitive field",
+ data);
+ } else {
+ logger().error("Could not read data with any of the possible fields:",
+ data);
+ size_t f = 0;
+ for (auto field : defaultFields) {
+ logger().note(std::string("Field ") +
+ Utils::join(field->path(), ".") +
+ std::string(":"),
+ SourceLocation{}, MessageMode::NO_CONTEXT);
+ forks[f].commit();
+ f++;
+ }
}
return false;
}
@@ -462,4 +470,4 @@ namespace RttiTypes {
const Rtti DocumentField = RttiBuilder<ousia::parser_stack::DocumentField>(
"DocumentField").parent(&Node);
}
-} \ No newline at end of file
+}
diff --git a/test/formats/osml/OsmlParserTest.cpp b/test/formats/osml/OsmlParserTest.cpp
index d12721e..50e0dcb 100644
--- a/test/formats/osml/OsmlParserTest.cpp
+++ b/test/formats/osml/OsmlParserTest.cpp
@@ -120,5 +120,32 @@ TEST(OsmlParser, inlineDomain)
ASSERT_TRUE(node->isa(&RttiTypes::Document));
}
+TEST(OsmlParser, include)
+{
+ OsmlStandaloneEnvironment env(logger);
+ logger.reset();
+
+ ASSERT_FALSE(logger.hasError());
+ Rooted<Node> node =
+ env.parse("include_root.osml", "", "", RttiSet{&RttiTypes::Node});
+ ASSERT_FALSE(logger.hasError());
+
+ ASSERT_TRUE(node != nullptr);
+ ASSERT_TRUE(node->isa(&RttiTypes::Document));
+}
+
+TEST(OsmlParser, includeRecursive)
+{
+ OsmlStandaloneEnvironment env(logger);
+ logger.reset();
+
+ ASSERT_FALSE(logger.hasError());
+ Rooted<Node> node = env.parse("include_recursive_root.osml", "", "",
+ RttiSet{&RttiTypes::Node});
+ ASSERT_TRUE(logger.hasError());
+
+ ASSERT_TRUE(node != nullptr);
+ ASSERT_TRUE(node->isa(&RttiTypes::Document));
+}
}
diff --git a/testdata/osmlparser/include_child.osml b/testdata/osmlparser/include_child.osml
new file mode 100644
index 0000000..1a47dc9
--- /dev/null
+++ b/testdata/osmlparser/include_child.osml
@@ -0,0 +1,4 @@
+Test
+\b
+Test
+
diff --git a/testdata/osmlparser/include_recursive.osml b/testdata/osmlparser/include_recursive.osml
new file mode 100644
index 0000000..27eabe0
--- /dev/null
+++ b/testdata/osmlparser/include_recursive.osml
@@ -0,0 +1 @@
+\include{include_recursive.osml}
diff --git a/testdata/osmlparser/include_recursive_root.osml b/testdata/osmlparser/include_recursive_root.osml
new file mode 100644
index 0000000..b3e433f
--- /dev/null
+++ b/testdata/osmlparser/include_recursive_root.osml
@@ -0,0 +1,10 @@
+\begin{document}
+
+\domain#testDomain
+ \struct#test[isRoot=true]
+
+\begin{test}
+\include{./include_recursive.osml}
+\end{test}
+\end{document}
+
diff --git a/testdata/osmlparser/include_root.osml b/testdata/osmlparser/include_root.osml
new file mode 100644
index 0000000..1d1d660
--- /dev/null
+++ b/testdata/osmlparser/include_root.osml
@@ -0,0 +1,20 @@
+\begin{document}
+
+\domain#testDomain
+ \struct#test[isRoot=true]
+ \field
+ \childRef[ref=a]
+ \childRef[ref=b]
+ \struct#a
+ \field
+ \childRef[ref=b]
+ \struct#b[transparent=true]
+ \primitive[type=string,optional=true]
+
+\begin{test}
+\a
+\include{./include_child.osml}
+\b
+Test
+\end{test}
+\end{document}
diff --git a/testdata/osmlparser/simple_book.osml b/testdata/osmlparser/simple_book.osml
deleted file mode 100644
index 21751b9..0000000
--- a/testdata/osmlparser/simple_book.osml
+++ /dev/null
@@ -1,31 +0,0 @@
-\import[domain]{../osxmlparser/book_domain.osxml}
-\import[domain]{../osxmlparser/headings_domain.osxml}
-
-%\domain#stuff
-% \import[typesystem]{../osxmlparser/color.osxml}
-% \struct#fancy
-% \primitive#bla[type=color]
-% \parentRef[ref=book]
-% \fieldRef[ref=$default]
-
-\begin{book}
-This might be some introductory text or a dedication.
-
-\chapter#myFirstChapter{My first chapter}
-Here we might have an introduction to the chapter.
-
-\section#myFirstSection
-\heading{A rather curious experiment}
-\paragraph{!Here we might find the actual section content.
-\heading{test}}
-
-\section#mySndSection
-Here we might find the actual section content.
-
-
-bla
-
-%\fancy{aquamarine}
-
-\end{book}
-