summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/parser/stack/TokenStack.cpp18
-rw-r--r--src/core/parser/stack/TokenStack.hpp36
2 files changed, 54 insertions, 0 deletions
diff --git a/src/core/parser/stack/TokenStack.cpp b/src/core/parser/stack/TokenStack.cpp
index c20c764..1c26a7c 100644
--- a/src/core/parser/stack/TokenStack.cpp
+++ b/src/core/parser/stack/TokenStack.cpp
@@ -30,6 +30,24 @@ void TokenStack::pushTokens(const std::vector<SyntaxDescriptor> &tokens,
stack.push_back(tokens);
}
+TokenDescriptor TokenStack::lookup(TokenId token) const
+{
+ TokenDescriptor res;
+ if (!stack.empty()) {
+ for (const SyntaxDescriptor &descr : stack.back()) {
+ if (descr.close == token) {
+ res.close.emplace_back(descr);
+ }
+ if (descr.shortForm == token) {
+ res.shortForm.emplace_back(descr);
+ }
+ if (descr.open == token) {
+ res.open.emplace_back(descr);
+ }
+ }
+ }
+ return res;
+}
void TokenStack::popTokens() { stack.pop_back(); }
TokenSet TokenStack::tokens() const
diff --git a/src/core/parser/stack/TokenStack.hpp b/src/core/parser/stack/TokenStack.hpp
index 32f181a..d5deafe 100644
--- a/src/core/parser/stack/TokenStack.hpp
+++ b/src/core/parser/stack/TokenStack.hpp
@@ -38,6 +38,34 @@ namespace ousia {
namespace parser_stack {
/**
+ * Structure describing a token once it has been found in the text. Contains
+ * lists pointing at the corresponding SyntaxDescriptors for the open, close and
+ * shortForm token types.
+ */
+struct TokenDescriptor {
+ /**
+ * Vector containing the SyntaxDescriptors in which the token occurs as
+ * "close" token. The Token is first tried to be processed as a "close"
+ * token.
+ */
+ std::vector<SyntaxDescriptor> close;
+
+ /**
+ * Vector containing the SyntaxDescriptors in which the token occurs as
+ * "shortForm" token. Creating a "shortForm" of the referenced ontology
+ * descriptor is tried next.
+ */
+ std::vector<SyntaxDescriptor> shortForm;
+
+ /**
+ * Vector containing the SyntaxDescriptors in which the token occurs as
+ * "open" token. The possibility of using the token in the "open" mode is
+ * tried in the last step.
+ */
+ std::vector<SyntaxDescriptor> open;
+};
+
+/**
* The TokenStack class is used by the Stack class to collect all currently
* enabled user defined tokens.
*/
@@ -66,6 +94,14 @@ public:
void popTokens();
/**
+ * Returns the TokenDescriptor for the given token.
+ *
+ * @param token is the token for which the different forms should be looked
+ * up.
+ */
+ TokenDescriptor lookup(TokenId token) const;
+
+ /**
* Returns a set containing all currently enabled tokens. The set of enabled
* tokens are those tokens that were pushed last onto the stack. This set
* has to be passed to the TokenizedData instance in order to gather all