summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/parser/ParserScope.hpp9
-rw-r--r--src/core/parser/stack/DocumentHandler.cpp47
2 files changed, 48 insertions, 8 deletions
diff --git a/src/core/parser/ParserScope.hpp b/src/core/parser/ParserScope.hpp
index fa78c17..e27c81e 100644
--- a/src/core/parser/ParserScope.hpp
+++ b/src/core/parser/ParserScope.hpp
@@ -286,7 +286,13 @@ enum class ParserFlag {
* Set to the boolean value "true" if the head section of a file has passed.
* This happens once the first non-import tag is reached.
*/
- POST_HEAD
+ POST_HEAD,
+
+ /**
+ * Set to the boolean value "true" if explicit fields may no longer be
+ * defined inside a structure element.
+ */
+ POST_EXPLICIT_FIELDS
};
/**
@@ -797,6 +803,7 @@ public:
bool resolveFieldDescriptor(const std::string &name, Handle<Node> owner,
Logger &logger,
ResolutionResultCallback resultCallback);
+
/**
* Tries to resolve all currently deferred resolution steps. The list of
* pending deferred resolutions is cleared after this function has run.
diff --git a/src/core/parser/stack/DocumentHandler.cpp b/src/core/parser/stack/DocumentHandler.cpp
index e959b9a..1df3cb3 100644
--- a/src/core/parser/stack/DocumentHandler.cpp
+++ b/src/core/parser/stack/DocumentHandler.cpp
@@ -98,6 +98,9 @@ void DocumentChildHandler::createPath(const NodeVector<Node> &path,
manager(), scope().getLeaf(),
parent->getDescriptor()->getFieldDescriptorIndex(), true)};
scope().push(field);
+
+ // Generally allow explicit fields in the new field
+ scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, false);
}
void DocumentChildHandler::createPath(const size_t &firstFieldIdx,
@@ -113,6 +116,9 @@ void DocumentChildHandler::createPath(const size_t &firstFieldIdx,
parent = static_cast<DocumentEntity *>(transparent.get());
createPath(path, parent, 2);
+
+ // Generally allow explicit fields in the new field
+ scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, false);
}
bool DocumentChildHandler::start(Variant::mapType &args)
@@ -170,12 +176,25 @@ bool DocumentChildHandler::start(Variant::mapType &args)
ssize_t newFieldIdx =
parent->getDescriptor()->getFieldDescriptorIndex(name());
if (newFieldIdx != -1) {
- Rooted<DocumentField> field{new DocumentField(
- manager(), parentNode, newFieldIdx, false)};
- field->setLocation(location());
- scope().push(field);
- isExplicitField = true;
- return true;
+ // Check whether explicit fields are allowed here, if not
+ if (scope().getFlag(ParserFlag::POST_EXPLICIT_FIELDS)) {
+ logger().note(
+ std::string(
+ "Data or structure commands have already been "
+ "given, command \"") +
+ name() + std::string(
+ "\" is not interpreted explicit "
+ "field. Move explicit field "
+ "references to the beginning."),
+ location());
+ } else {
+ Rooted<DocumentField> field{new DocumentField(
+ manager(), parentNode, newFieldIdx, false)};
+ field->setLocation(location());
+ scope().push(field);
+ isExplicitField = true;
+ return true;
+ }
}
}
@@ -218,11 +237,17 @@ bool DocumentChildHandler::start(Variant::mapType &args)
parent->getDescriptor()->getFieldDescriptorIndex();
}
// create the entity for the new element at last.
- //TODO: REMOVE
+ // TODO: REMOVE
strct_name = strct->getName();
entity = parent->createChildStructuredEntity(strct, lastFieldIdx,
args, nameAttr);
}
+
+ // We're past the region in which explicit fields can be defined in the
+ // parent structure element
+ scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, true);
+
+ // Bush the entity onto the stack
entity->setLocation(location());
scope().push(entity);
return true;
@@ -271,6 +296,10 @@ bool DocumentChildHandler::fieldStart(bool &isDefault, size_t fieldIdx)
new DocumentField(manager(), parentNode, fieldIdx, false)};
field->setLocation(location());
scope().push(field);
+
+ // Generally allow explicit fields in the new field
+ scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, false);
+
return true;
}
@@ -334,6 +363,10 @@ bool DocumentChildHandler::convertData(Handle<FieldDescriptor> field,
bool DocumentChildHandler::data(Variant &data)
{
+ // We're past the region in which explicit fields can be defined in the
+ // parent structure element
+ scope().setFlag(ParserFlag::POST_EXPLICIT_FIELDS, true);
+
Rooted<Node> parentField = scope().getLeaf();
assert(parentField->isa(&RttiTypes::DocumentField));