summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-04-10 11:30:55 +0200
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2016-04-25 22:24:12 +0200
commitf0345a6617e2458000210fb6edafccf5a04eca61 (patch)
tree1159860413e1531f0a47faab3f062265ce4b7afa /src/core
parentc5357cc0bf59e60dd59f2b2a032245afd73e4acd (diff)
Add function for retrieving the name of a token.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/common/Token.cpp26
-rw-r--r--src/core/common/Token.hpp16
2 files changed, 42 insertions, 0 deletions
diff --git a/src/core/common/Token.cpp b/src/core/common/Token.cpp
index 17ce03e..f9e60ce 100644
--- a/src/core/common/Token.cpp
+++ b/src/core/common/Token.cpp
@@ -20,5 +20,31 @@
namespace ousia {
+std::string Token::name() const
+{
+ if (isSpecial()) {
+ return specialName(id);
+ }
+ return content;
+}
+
+const char* Token::specialName(TokenId id)
+{
+ switch (id) {
+ case Tokens::Newline:
+ return "newline";
+ case Tokens::Paragraph:
+ return "paragraph";
+ case Tokens::Section:
+ return "section";
+ case Tokens::Indent:
+ return "indent";
+ case Tokens::Dedent:
+ return "dedent";
+ }
+ return "";
+}
+
+
}
diff --git a/src/core/common/Token.hpp b/src/core/common/Token.hpp
index ad36e14..ccbc84b 100644
--- a/src/core/common/Token.hpp
+++ b/src/core/common/Token.hpp
@@ -190,6 +190,22 @@ struct Token {
static bool isSpecial(TokenId id) {return id > Tokens::MaxTokenId; }
/**
+ * Returns the name of the token -- which is either its content or the name
+ * of the special token (if it is one).
+ *
+ * @return the human readable name of this token instance.
+ */
+ std::string name() const;
+
+ /**
+ * Returns the name of the special token or an empty string if it is not a
+ * special token.
+ *
+ * @param id
+ */
+ static const char* specialName(TokenId id);
+
+ /**
* The getLocation function allows the tokens to be directly passed as
* parameter to Logger or LoggableException instances.
*