summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-15 20:57:27 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-15 20:57:27 +0100
commite2e32eef55406519c744002a404e7e5ca66b29a1 (patch)
tree41069921dd771cd5a308cda0a996bdb5dc1c772a /src/core
parent7907e9407f499354e0c3a0a402217b760fab9ad7 (diff)
Declaring States in the Handler classes
Diffstat (limited to 'src/core')
-rw-r--r--src/core/parser/stack/DocumentHandler.cpp21
-rw-r--r--src/core/parser/stack/DocumentHandler.hpp14
-rw-r--r--src/core/parser/stack/DomainHandler.cpp100
-rw-r--r--src/core/parser/stack/DomainHandler.hpp73
-rw-r--r--src/core/parser/stack/GenericParserStates.cpp53
-rw-r--r--src/core/parser/stack/GenericParserStates.hpp49
-rw-r--r--src/core/parser/stack/ImportIncludeHandler.cpp24
-rw-r--r--src/core/parser/stack/ImportIncludeHandler.hpp13
-rw-r--r--src/core/parser/stack/TypesystemHandler.cpp48
-rw-r--r--src/core/parser/stack/TypesystemHandler.hpp30
10 files changed, 408 insertions, 17 deletions
diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp
index b28f0fb..9fedabb 100644
--- a/src/core/parser/stack/DocumentHandler.cpp
+++ b/src/core/parser/stack/DocumentHandler.cpp
@@ -16,8 +16,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "DocumentHandler.hpp"
-
#include <algorithm>
#include <core/common/RttiBuilder.hpp>
@@ -30,6 +28,9 @@
#include <core/parser/ParserScope.hpp>
#include <core/parser/ParserContext.hpp>
+#include "DocumentHandler.hpp"
+#include "State.hpp"
+
namespace ousia {
namespace parser_stack {
@@ -274,6 +275,22 @@ bool DocumentChildHandler::data(Variant &data)
}
return true;
}
+
+namespace States {
+const State Document = StateBuilder()
+ .parent(&None)
+ .createdNodeType(&RttiTypes::Document)
+ .elementHandler(DocumentHandler::create)
+ .arguments({Argument::String("name", "")});
+
+const State DocumentChild =
+ StateBuilder()
+ .parents({&Document, &DocumentChild})
+ .createdNodeTypes({&RttiTypes::StructureNode,
+ &RttiTypes::AnnotationEntity,
+ &RttiTypes::DocumentField})
+ .elementHandler(DocumentChildHandler::create);
+}
}
namespace RttiTypes {
diff --git a/src/core/parser/stack/DocumentHandler.hpp b/src/core/parser/stack/DocumentHandler.hpp
index 7dc4c86..b339b96 100644
--- a/src/core/parser/stack/DocumentHandler.hpp
+++ b/src/core/parser/stack/DocumentHandler.hpp
@@ -144,6 +144,19 @@ public:
return new DocumentChildHandler{handlerData};
}
};
+
+namespace States {
+/**
+ * State constant representing the "document" tag.
+ */
+extern const State Document;
+
+/**
+ * State contstant representing any user-defined element within a document.
+ */
+extern const State DocumentChild;
+}
+
}
namespace RttiTypes {
@@ -152,6 +165,7 @@ namespace RttiTypes {
*/
extern const Rtti DocumentField;
}
+
}
#endif /* _OUSIA_PARSER_STACK_DOCUMENT_HANDLER_HPP_ */
diff --git a/src/core/parser/stack/DomainHandler.cpp b/src/core/parser/stack/DomainHandler.cpp
index cb12543..24a6f1a 100644
--- a/src/core/parser/stack/DomainHandler.cpp
+++ b/src/core/parser/stack/DomainHandler.cpp
@@ -16,14 +16,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "DomainHandler.hpp"
-
#include <core/common/RttiBuilder.hpp>
+#include <core/model/Document.hpp>
#include <core/model/Domain.hpp>
#include <core/model/Project.hpp>
#include <core/parser/ParserScope.hpp>
#include <core/parser/ParserContext.hpp>
+#include "DocumentHandler.hpp"
+#include "DomainHandler.hpp"
+#include "State.hpp"
+#include "TypesystemHandler.hpp"
+
namespace ousia {
namespace parser_stack {
@@ -278,6 +282,98 @@ bool DomainParentFieldRefHandler::start(Variant::mapType &args)
});
return true;
}
+
+namespace States {
+const State Domain = StateBuilder()
+ .parents({&None, &Document})
+ .createdNodeType(&RttiTypes::Domain)
+ .elementHandler(DomainHandler::create)
+ .arguments({Argument::String("name")});
+
+const State DomainStruct =
+ StateBuilder()
+ .parent(&Domain)
+ .createdNodeType(&RttiTypes::StructuredClass)
+ .elementHandler(DomainStructHandler::create)
+ .arguments({Argument::String("name"),
+ Argument::Cardinality("cardinality", Cardinality::any()),
+ Argument::Bool("isRoot", false),
+ Argument::Bool("transparent", false),
+ Argument::String("isa", "")});
+
+const State DomainAnnotation =
+ StateBuilder()
+ .parent(&Domain)
+ .createdNodeType(&RttiTypes::AnnotationClass)
+ .elementHandler(DomainAnnotationHandler::create)
+ .arguments({Argument::String("name")});
+
+const State DomainAttributes =
+ StateBuilder()
+ .parents({&DomainStruct, &DomainAnnotation})
+ .createdNodeType(&RttiTypes::StructType)
+ .elementHandler(DomainAttributesHandler::create)
+ .arguments({});
+
+const State DomainAttribute =
+ StateBuilder()
+ .parent(&DomainAttributes)
+ .elementHandler(TypesystemStructFieldHandler::create)
+ .arguments({Argument::String("name"), Argument::String("type"),
+ Argument::Any("default", Variant::fromObject(nullptr))});
+
+const State DomainField = StateBuilder()
+ .parents({&DomainStruct, &DomainAnnotation})
+ .createdNodeType(&RttiTypes::FieldDescriptor)
+ .elementHandler(DomainFieldHandler::create)
+ .arguments({Argument::String("name", ""),
+ Argument::Bool("isSubtree", false),
+ Argument::Bool("optional", false)});
+
+const State DomainFieldRef =
+ StateBuilder()
+ .parents({&DomainStruct, &DomainAnnotation})
+ .createdNodeType(&RttiTypes::FieldDescriptor)
+ .elementHandler(DomainFieldRefHandler::create)
+ .arguments({Argument::String("ref", DEFAULT_FIELD_NAME)});
+
+const State DomainStructPrimitive =
+ StateBuilder()
+ .parents({&DomainStruct, &DomainAnnotation})
+ .createdNodeType(&RttiTypes::FieldDescriptor)
+ .elementHandler(DomainPrimitiveHandler::create)
+ .arguments(
+ {Argument::String("name", ""), Argument::Bool("isSubtree", false),
+ Argument::Bool("optional", false), Argument::String("type")});
+
+const State DomainStructChild = StateBuilder()
+ .parent(&DomainField)
+ .elementHandler(DomainChildHandler::create)
+ .arguments({Argument::String("ref")});
+
+const State DomainStructParent =
+ StateBuilder()
+ .parent(&DomainStruct)
+ .createdNodeType(&RttiTypes::DomainParent)
+ .elementHandler(DomainParentHandler::create)
+ .arguments({Argument::String("ref")});
+
+const State DomainStructParentField =
+ StateBuilder()
+ .parent(&DomainStructParent)
+ .createdNodeType(&RttiTypes::FieldDescriptor)
+ .elementHandler(DomainParentFieldHandler::create)
+ .arguments({Argument::String("name", ""),
+ Argument::Bool("isSubtree", false),
+ Argument::Bool("optional", false)});
+
+const State DomainStructParentFieldRef =
+ StateBuilder()
+ .parent(&DomainStructParent)
+ .createdNodeType(&RttiTypes::FieldDescriptor)
+ .elementHandler(DomainParentFieldRefHandler::create)
+ .arguments({Argument::String("ref", DEFAULT_FIELD_NAME)});
+}
}
namespace RttiTypes {
diff --git a/src/core/parser/stack/DomainHandler.hpp b/src/core/parser/stack/DomainHandler.hpp
index 917d65d..76172d6 100644
--- a/src/core/parser/stack/DomainHandler.hpp
+++ b/src/core/parser/stack/DomainHandler.hpp
@@ -34,13 +34,14 @@
#include "Handler.hpp"
namespace ousia {
-namespace parser_stack {
-
-// TODO: Documentation
// Forward declarations
class Rtti;
+namespace parser_stack {
+
+// TODO: Documentation
+
class DomainHandler : public StaticHandler {
public:
using StaticHandler::StaticHandler;
@@ -149,10 +150,6 @@ public:
using Node::Node;
};
-namespace RttiTypes {
-extern const Rtti DomainParent;
-}
-
class DomainParentHandler : public StaticHandler {
public:
using StaticHandler::StaticHandler;
@@ -189,6 +186,68 @@ public:
return new DomainParentFieldRefHandler{handlerData};
}
};
+
+namespace States {
+/**
+ * State representing a "domain" struct.
+ */
+extern const State Domain;
+
+/**
+ * State representing a "struct" tag within a domain description.
+ */
+extern const State DomainStruct;
+
+/**
+ * State representing an "annotation" tag within a domain description.
+ */
+extern const State DomainAnnotation;
+
+/**
+ * State representing an "attributes" tag within a structure or annotation.
+ */
+extern const State DomainAttributes;
+
+/**
+ * State representing an "attribute" tag within the "attributes".
+ */
+extern const State DomainAttribute;
+
+/**
+ * State representing a "field" tag within a structure or annotation.
+ */
+extern const State DomainField;
+
+/**
+ * State representing a "fieldref" tag within a structure or annotation.
+ */
+extern const State DomainFieldRef;
+
+/**
+ * State representing a "primitive" tag within a structure or annotation.
+ */
+extern const State DomainStructPrimitive;
+
+/**
+ * State representing a "child" tag within a structure or annotation.
+ */
+extern const State DomainStructChild;
+
+/**
+ * State representing a "parent" tag within a structure or annotation.
+ */
+extern const State DomainStructParent;
+
+/**
+ * State representing a "field" tag within a "parent" tag.
+ */
+extern const State DomainStructParentField;
+
+/**
+ * State representing a "fieldRef" tag within a "parent" tag.
+ */
+extern const State DomainStructParentFieldRef;
+}
}
namespace RttiTypes {
diff --git a/src/core/parser/stack/GenericParserStates.cpp b/src/core/parser/stack/GenericParserStates.cpp
new file mode 100644
index 0000000..69a6e0e
--- /dev/null
+++ b/src/core/parser/stack/GenericParserStates.cpp
@@ -0,0 +1,53 @@
+/*
+ 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "DocumentHandler.hpp"
+#include "DomainHandler.hpp"
+#include "GenericParserStates.hpp"
+#include "ImportIncludeHandler.hpp"
+#include "TypesystemHandler.hpp"
+
+namespace ousia {
+namespace parser_stack {
+
+const std::multimap<std::string, const State *> GenericParserStates{
+ {"document", &States::Document},
+ {"*", &States::DocumentChild},
+ {"domain", &States::Domain},
+ {"struct", &States::DomainStruct},
+ {"annotation", &States::DomainAnnotation},
+ {"attributes", &States::DomainAttributes},
+ {"attribute", &States::DomainAttribute},
+ {"field", &States::DomainField},
+ {"fieldRef", &States::DomainFieldRef},
+ {"primitive", &States::DomainStructPrimitive},
+ {"childRef", &States::DomainStructChild},
+ {"parentRef", &States::DomainStructParent},
+ {"field", &States::DomainStructParentField},
+ {"fieldRef", &States::DomainStructParentFieldRef},
+ {"typesystem", &States::Typesystem},
+ {"enum", &States::TypesystemEnum},
+ {"entry", &States::TypesystemEnumEntry},
+ {"struct", &States::TypesystemStruct},
+ {"field", &States::TypesystemStructField},
+ {"constant", &States::TypesystemConstant},
+ {"import", &States::Import},
+ {"include", &States::Include}};
+}
+}
+
diff --git a/src/core/parser/stack/GenericParserStates.hpp b/src/core/parser/stack/GenericParserStates.hpp
new file mode 100644
index 0000000..552eee5
--- /dev/null
+++ b/src/core/parser/stack/GenericParserStates.hpp
@@ -0,0 +1,49 @@
+/*
+ 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file GenericParserStates.hpp
+ *
+ * Contains a multimap which maps between tag/command names to the corresponding
+ * state descriptors. This multimap is used to initialize the push down
+ * automaton residing inside the "Stack" class.
+ *
+ * @author Andreas Stöckel (astoecke@techfak.uni-bielefeld.de)
+ */
+
+#ifndef _OUSIA_PARSER_STACK_GENERIC_PARSER_STATES_HPP_
+#define _OUSIA_PARSER_STACK_GENERIC_PARSER_STATES_HPP_
+
+#include <string>
+#include <map>
+
+namespace ousia {
+namespace parser_stack {
+
+// Forward declarations
+class State;
+
+/**
+ * Map between tagnames and references to the corresponding State instances.
+ */
+extern const std::multimap<std::string, const State *> GenericParserStates;
+}
+}
+
+#endif /* _OUSIA_PARSER_STACK_GENERIC_PARSER_STATES_HPP_ */
+
diff --git a/src/core/parser/stack/ImportIncludeHandler.cpp b/src/core/parser/stack/ImportIncludeHandler.cpp
index 797dd8d..d1ea97d 100644
--- a/src/core/parser/stack/ImportIncludeHandler.cpp
+++ b/src/core/parser/stack/ImportIncludeHandler.cpp
@@ -16,12 +16,16 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "ImportIncludeHandler.hpp"
-
#include <core/model/RootNode.hpp>
#include <core/parser/ParserScope.hpp>
#include <core/parser/ParserContext.hpp>
+#include "DomainHandler.hpp"
+#include "DocumentHandler.hpp"
+#include "ImportIncludeHandler.hpp"
+#include "State.hpp"
+#include "TypesystemHandler.hpp"
+
namespace ousia {
namespace parser_stack {
@@ -58,5 +62,21 @@ void IncludeHandler::doHandle(const Variant &fieldData, Variant::mapType &args)
context().include(fieldData.asString(), args["type"].asString(),
args["rel"].asString(), {&RttiTypes::Node});
}
+
+namespace States {
+const State Import =
+ StateBuilder()
+ .parents({&Document, &Typesystem, &Domain})
+ .elementHandler(ImportHandler::create)
+ .arguments({Argument::String("rel", ""), Argument::String("type", ""),
+ Argument::String("src", "")});
+
+const State Include =
+ StateBuilder()
+ .parent(&All)
+ .elementHandler(IncludeHandler::create)
+ .arguments({Argument::String("rel", ""), Argument::String("type", ""),
+ Argument::String("src", "")});
+}
}
}
diff --git a/src/core/parser/stack/ImportIncludeHandler.hpp b/src/core/parser/stack/ImportIncludeHandler.hpp
index 8f3d3d0..6168639 100644
--- a/src/core/parser/stack/ImportIncludeHandler.hpp
+++ b/src/core/parser/stack/ImportIncludeHandler.hpp
@@ -88,6 +88,19 @@ public:
return new IncludeHandler{handlerData, "src"};
}
};
+
+namespace States {
+/**
+ * State representing the "import" command.
+ */
+extern const State Import;
+
+/**
+ * State representing the "include" command.
+ */
+extern const State Include;
+}
+
}
}
#endif
diff --git a/src/core/parser/stack/TypesystemHandler.cpp b/src/core/parser/stack/TypesystemHandler.cpp
index 34f64f9..d053699 100644
--- a/src/core/parser/stack/TypesystemHandler.cpp
+++ b/src/core/parser/stack/TypesystemHandler.cpp
@@ -16,12 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "TypesystemHandler.hpp"
-
#include <core/model/Typesystem.hpp>
+#include <core/model/Domain.hpp>
#include <core/parser/ParserScope.hpp>
#include <core/parser/ParserContext.hpp>
+#include "DomainHandler.hpp"
+#include "State.hpp"
+#include "TypesystemHandler.hpp"
namespace ousia {
namespace parser_stack {
@@ -170,6 +172,48 @@ bool TypesystemConstantHandler::start(Variant::mapType &args)
return true;
}
+
+namespace States {
+const State Typesystem = StateBuilder()
+ .parents({&None, &Domain})
+ .createdNodeType(&RttiTypes::Typesystem)
+ .elementHandler(TypesystemHandler::create)
+ .arguments({Argument::String("name", "")});
+
+const State TypesystemEnum = StateBuilder()
+ .parent(&Typesystem)
+ .createdNodeType(&RttiTypes::EnumType)
+ .elementHandler(TypesystemEnumHandler::create)
+ .arguments({Argument::String("name")});
+
+const State TypesystemEnumEntry =
+ StateBuilder()
+ .parent(&TypesystemEnum)
+ .elementHandler(TypesystemEnumEntryHandler::create)
+ .arguments({});
+
+const State TypesystemStruct =
+ StateBuilder()
+ .parent(&Typesystem)
+ .createdNodeType(&RttiTypes::StructType)
+ .elementHandler(TypesystemStructHandler::create)
+ .arguments({Argument::String("name"), Argument::String("parent", "")});
+
+const State TypesystemStructField =
+ StateBuilder()
+ .parent(&TypesystemStruct)
+ .elementHandler(TypesystemStructFieldHandler::create)
+ .arguments({Argument::String("name"), Argument::String("type"),
+ Argument::Any("default", Variant::fromObject(nullptr))});
+
+const State TypesystemConstant =
+ StateBuilder()
+ .parent(&Typesystem)
+ .createdNodeType(&RttiTypes::Constant)
+ .elementHandler(TypesystemConstantHandler::create)
+ .arguments({Argument::String("name"), Argument::String("type"),
+ Argument::Any("value")});
+}
}
}
diff --git a/src/core/parser/stack/TypesystemHandler.hpp b/src/core/parser/stack/TypesystemHandler.hpp
index 55277a1..85494f1 100644
--- a/src/core/parser/stack/TypesystemHandler.hpp
+++ b/src/core/parser/stack/TypesystemHandler.hpp
@@ -91,8 +91,7 @@ class TypesystemEnumEntryHandler : public StaticFieldHandler {
public:
using StaticFieldHandler::StaticFieldHandler;
- void doHandle(const Variant &fieldData,
- Variant::mapType &args) override;
+ void doHandle(const Variant &fieldData, Variant::mapType &args) override;
/**
* Creates a new instance of the TypesystemEnumEntryHandler.
@@ -177,6 +176,33 @@ public:
return new TypesystemConstantHandler{handlerData};
}
};
+
+namespace States {
+/**
+ * State representing the "typesystem" tag.
+ */
+extern const State Typesystem;
+/**
+ * State representing the "enum" tag within a typesystem.
+ */
+extern const State TypesystemEnum;
+/**
+ * State representing the "entry" tag within an enum.
+ */
+extern const State TypesystemEnumEntry;
+/**
+ * State representing the "struct" tag within a typesystem.
+ */
+extern const State TypesystemStruct;
+/**
+ * State representing the "field" tag within a typesystem structure.
+ */
+extern const State TypesystemStructField;
+/**
+ * State representing the "constant" tag within a typesystem.
+ */
+extern const State TypesystemConstant;
+}
}
}
#endif