From 5aed7c46cff192311a208dc5e9cf7f81a40771a8 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 31 Mar 2015 23:49:44 +0200 Subject: Implement TokenStack::lookup method used to lookup the SyntaxDescriptors associated with a certain token. --- src/core/parser/stack/TokenStack.cpp | 18 ++++++++++++++++++ src/core/parser/stack/TokenStack.hpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'src') 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 &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 @@ -37,6 +37,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 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 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 open; +}; + /** * The TokenStack class is used by the Stack class to collect all currently * enabled user defined tokens. @@ -65,6 +93,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 -- cgit v1.2.3