diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-04-12 15:18:12 +0200 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2016-04-25 22:24:15 +0200 |
commit | b7f89b4fa3dc15dbe0fa12a27b4d9167f41664f2 (patch) | |
tree | c9ccc6131c37c34a368009a9d3a8a1316333832d /src/core/model | |
parent | ae1b41524c89c29b47b189fd6741f3aeefeaeb50 (diff) |
Add greedy flag to TokenDescriptor and SyntaxDescriptor and set it correctly. Shorten Stack "checkTokensAreUnambiguous" method
Diffstat (limited to 'src/core/model')
-rw-r--r-- | src/core/model/Ontology.hpp | 21 | ||||
-rw-r--r-- | src/core/model/Syntax.hpp | 41 |
2 files changed, 44 insertions, 18 deletions
diff --git a/src/core/model/Ontology.hpp b/src/core/model/Ontology.hpp index 2533b9d..014f912 100644 --- a/src/core/model/Ontology.hpp +++ b/src/core/model/Ontology.hpp @@ -555,9 +555,9 @@ public: */ SyntaxDescriptor getSyntaxDescriptor(ssize_t depth = -1) { - SyntaxDescriptor stx{openToken.id, closeToken.id, Tokens::Empty, - const_cast<FieldDescriptor *>(this), depth}; - return stx; + return {openToken.id, closeToken.id, + Tokens::Empty, const_cast<FieldDescriptor *>(this), + depth, true}; } /** @@ -645,7 +645,8 @@ public: */ virtual ManagedVector<FieldDescriptor> getFieldDescriptors() const { - return ManagedVector<FieldDescriptor>(const_cast<Descriptor*>(this), fieldDescriptors.begin(), + return ManagedVector<FieldDescriptor>(const_cast<Descriptor *>(this), + fieldDescriptors.begin(), fieldDescriptors.end()); } @@ -934,9 +935,8 @@ public: */ virtual SyntaxDescriptor getSyntaxDescriptor(ssize_t depth = -1) { - SyntaxDescriptor stx{openToken.id, closeToken.id, Tokens::Empty, - const_cast<Descriptor *>(this), depth}; - return stx; + return {openToken.id, closeToken.id, Tokens::Empty, + const_cast<Descriptor *>(this), depth, true}; } /** @@ -1227,10 +1227,9 @@ public: */ SyntaxDescriptor getSyntaxDescriptor(ssize_t depth = -1) override { - SyntaxDescriptor stx{getOpenToken().id, getCloseToken().id, - shortToken.id, const_cast<StructuredClass *>(this), - depth}; - return stx; + return {getOpenToken().id, getCloseToken().id, + shortToken.id, const_cast<StructuredClass *>(this), + depth, shortToken.greedy}; } }; diff --git a/src/core/model/Syntax.hpp b/src/core/model/Syntax.hpp index e525224..5f360bc 100644 --- a/src/core/model/Syntax.hpp +++ b/src/core/model/Syntax.hpp @@ -41,14 +41,22 @@ struct TokenDescriptor { std::string token; /** + * An id to uniquely identify this token. + */ + TokenId id; + + /** * A flag to be set true if this TokenDescriptor uses a special token. */ bool special; /** - * An id to uniquely identify this token. + * A flag indicating whether the token is greedy or not. Currently only used + * for "shortForm" tokens. Default value is true. If false, only one data + * command is passed to the corresponding handler if the handler was opened + * for the implicity default field. */ - TokenId id; + bool greedy; /** * Constructor for non-special tokens. The special flag is set to false and @@ -58,7 +66,10 @@ struct TokenDescriptor { * one. */ TokenDescriptor(std::string token = std::string()) - : token(std::move(token)), special(false), id(Tokens::Empty) + : token(std::move(token)), + id(Tokens::Empty), + special(false), + greedy(true) { } @@ -68,7 +79,10 @@ struct TokenDescriptor { * * @param id the id of the special token. */ - TokenDescriptor(TokenId id) : special(true), id(id) {} + TokenDescriptor(TokenId id, bool greedy = true) + : id(id), special(true), greedy(greedy) + { + } /** * Returns true if and only if neither a string nor an ID is given. @@ -128,6 +142,13 @@ struct SyntaxDescriptor { ssize_t depth; /** + * Set to true if the shortForm is greedy (default), to false if the + * corresponding handler should receive at most one piece of data if it was + * started implicitly. + */ + bool greedyShortForm; + + /** * Default constructor, sets all token ids to Tokens::Empty and the * descriptor handle to nullptr. */ @@ -136,7 +157,8 @@ struct SyntaxDescriptor { close(Tokens::Empty), shortForm(Tokens::Empty), descriptor(nullptr), - depth(-1) + depth(-1), + greedyShortForm(true) { } @@ -150,14 +172,19 @@ struct SyntaxDescriptor { * @param depth Given the current leaf in the parsed document the depth of a * SyntaxDescriptor is defined as the number of transparent elements that * would be needed to construct an instance of the referenced descriptor. + * @param greedyShortForm set to false if the shortForm token should be + * treated in a non-greedy way, meaning that it should be given at most + * one piece of data if it was started implicitly. */ SyntaxDescriptor(TokenId open, TokenId close, TokenId shortForm, - Handle<Node> descriptor, ssize_t depth) + Handle<Node> descriptor, ssize_t depth, + bool greedyShortForm) : open(open), close(close), shortForm(shortForm), descriptor(descriptor), - depth(depth) + depth(depth), + greedyShortForm(greedyShortForm) { } |