summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-02 14:59:44 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2014-12-02 14:59:44 +0100
commit35554e6d32a5e66819f8a7bf869f1853e0d6fede (patch)
treea76ec73e76b644a1d20a31960947bd776044b19d
parent0c26390e71193947a67bdd0536915523da38f00f (diff)
continued working on the xml parser class
-rw-r--r--src/core/parser/ParserStack.cpp3
-rw-r--r--src/core/parser/ParserStack.hpp3
-rw-r--r--src/plugins/xml/XmlParser.cpp43
-rw-r--r--test/core/BufferedCharReaderTest.cpp4
-rw-r--r--test/core/parser/ParserStackTest.cpp9
5 files changed, 54 insertions, 8 deletions
diff --git a/src/core/parser/ParserStack.cpp b/src/core/parser/ParserStack.cpp
index 01fce3f..7bc7af3 100644
--- a/src/core/parser/ParserStack.cpp
+++ b/src/core/parser/ParserStack.cpp
@@ -100,7 +100,8 @@ void ParserStack::start(std::string name, char **attrs)
const HandlerDescriptor *descr = nullptr;
auto range = handlers.equal_range(name);
for (auto it = range.first; it != range.second; it++) {
- if (it->second.parentStates.count(curState)) {
+ const std::set<State> &parentStates = it->second.parentStates;
+ if (parentStates.count(curState) || parentStates.count(STATE_ALL)) {
descr = &(it->second);
break;
}
diff --git a/src/core/parser/ParserStack.hpp b/src/core/parser/ParserStack.hpp
index a777b1e..18fc8d9 100644
--- a/src/core/parser/ParserStack.hpp
+++ b/src/core/parser/ParserStack.hpp
@@ -45,7 +45,7 @@ namespace parser {
/**
* The State type alias is used to
*/
-using State = int8_t;
+using State = int16_t;
static const State STATE_ALL = -2;
static const State STATE_NONE = -1;
@@ -140,6 +140,7 @@ public:
* Handler instance.
*
* TODO: Replace with std::string?
+ * TODO: Per default: Allow no data except for whitespace characters!
*
* @param data is a pointer at the character data that is available for the
* Handler instance.
diff --git a/src/plugins/xml/XmlParser.cpp b/src/plugins/xml/XmlParser.cpp
index f6891a8..42e0dd4 100644
--- a/src/plugins/xml/XmlParser.cpp
+++ b/src/plugins/xml/XmlParser.cpp
@@ -20,12 +20,55 @@
#include <expat.h>
+#include <core/parser/ParserStack.hpp>
+
#include "XmlParser.hpp"
namespace ousia {
namespace parser {
namespace xml {
+/* Document structure */
+static const State STATE_DOCUMENT = 0;
+static const State STATE_HEAD = 1;
+static const State STATE_BODY = 2;
+
+/* Special commands */
+static const State STATE_USE = 100;
+static const State STATE_INCLUDE = 101;
+static const State STATE_INLINE = 102;
+
+/* Type system definitions */
+static const State STATE_TYPES = 200;
+static const State STATE_CONSTANT = 201;
+static const State STATE_ENUM = 202;
+static const State STATE_STRUCT = 203;
+
+static Handler* createTestHandler(const ParserContext &ctx,
+ std::string name, State state,
+ State parentState, bool isChild)
+{
+ return nullptr;
+}
+
+static const std::multimap<std::string, HandlerDescriptor> XML_HANDLERS{
+ /* Documents */
+ {"document", {{STATE_NONE}, createTestHandler, STATE_DOCUMENT}},
+ {"head", {{STATE_DOCUMENT}, createTestHandler, STATE_HEAD}},
+ {"body", {{STATE_DOCUMENT}, createTestHandler, STATE_BODY, true}},
+
+ /* Special commands */
+ {"use", {{STATE_HEAD}, createTestHandler, STATE_USE}},
+ {"include", {{STATE_ALL}, createTestHandler, STATE_INCLUDE}},
+ {"inline", {{STATE_ALL}, createTestHandler, STATE_INLINE}},
+
+ /* Typesystem definitions */
+ {"types", {{STATE_NONE, STATE_HEAD}, createTestHandler, STATE_TYPES}},
+ {"enum", {{STATE_TYPES}, createTestHandler, STATE_ENUM}},
+ {"struct", {{STATE_TYPES}, createTestHandler, STATE_STRUCT}},
+ {"constant", {{STATE_TYPES}, createTestHandler, STATE_CONSTANT}}
+};
+
/**
* Wrapper class around the XML_Parser pointer which safely frees it whenever
* the scope is left (e.g. because an exception was thrown).
diff --git a/test/core/BufferedCharReaderTest.cpp b/test/core/BufferedCharReaderTest.cpp
index b0955c2..b3498f7 100644
--- a/test/core/BufferedCharReaderTest.cpp
+++ b/test/core/BufferedCharReaderTest.cpp
@@ -1,6 +1,6 @@
/*
- SCAENEA IDL Compiler (scidlc)
- Copyright (C) 2014 Andreas Stöckel
+ Ousía
+ Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
diff --git a/test/core/parser/ParserStackTest.cpp b/test/core/parser/ParserStackTest.cpp
index 92249ff..1f4a4e2 100644
--- a/test/core/parser/ParserStackTest.cpp
+++ b/test/core/parser/ParserStackTest.cpp
@@ -1,6 +1,6 @@
/*
- SCAENEA IDL Compiler (scidlc)
- Copyright (C) 2014 Andreas Stöckel
+ Ousía
+ Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -72,14 +72,13 @@ static Handler* createTestHandler(const ParserContext &ctx,
return new TestHandler(ctx, name, state, parentState, isChild);
}
-// Two nested elements used for testing
static const std::multimap<std::string, HandlerDescriptor> TEST_HANDLERS{
{"document", {{STATE_NONE}, createTestHandler, STATE_DOCUMENT}},
{"body", {{STATE_DOCUMENT}, createTestHandler, STATE_BODY, true}},
{"empty", {{STATE_DOCUMENT}, createTestHandler, STATE_EMPTY}},
+ {"special", {{STATE_ALL}, createTestHandler, STATE_EMPTY}},
};
-
TEST(ParserStack, simpleTest)
{
StandaloneParserContext ctx;
@@ -153,6 +152,8 @@ TEST(ParserStack, errorHandling)
ASSERT_THROW(s.start("document", nullptr), OusiaException);
s.start("empty", nullptr);
ASSERT_THROW(s.start("body", nullptr), OusiaException);
+ s.start("special", nullptr);
+ s.end();
s.end();
s.end();
ASSERT_EQ(STATE_NONE, s.currentState());