summary refs log tree commit diff stats
path: root/lib/token.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/token.h')
-rw-r--r--lib/token.h76
1 files changed, 37 insertions, 39 deletions
diff --git a/lib/token.h b/lib/token.h index ae7bf96..910a465 100644 --- a/lib/token.h +++ b/lib/token.h
@@ -5,6 +5,8 @@
5#include <string> 5#include <string>
6#include <list> 6#include <list>
7#include <set> 7#include <set>
8#include <variant.hpp>
9#include <hkutil/recptr.h>
8#include "enums.h" 10#include "enums.h"
9#include "word.h" 11#include "word.h"
10#include "part.h" 12#include "part.h"
@@ -22,23 +24,6 @@ namespace verbly {
22 transform 24 transform
23 }; 25 };
24 26
25 // Copy & move constructors
26
27 token(const token& other);
28 token(token&& other);
29
30 // Assignment operator
31
32 token& operator=(token other);
33
34 // Swap
35
36 friend void swap(token& first, token& second);
37
38 // Destructor
39
40 ~token();
41
42 // Accessors 27 // Accessors
43 28
44 type getType() const 29 type getType() const
@@ -52,7 +37,8 @@ namespace verbly {
52 37
53 bool isEmpty() const 38 bool isEmpty() const
54 { 39 {
55 return ((type_ == type::utterance) && (utterance_.empty())); 40 return (type_ == type::utterance &&
41 mpark::get<utterance_type>(variant_).empty());
56 } 42 }
57 43
58 // Word 44 // Word
@@ -68,13 +54,13 @@ namespace verbly {
68 token(std::string arg); 54 token(std::string arg);
69 token(const char* arg); 55 token(const char* arg);
70 56
71 std::string getLiteral() const; 57 const std::string& getLiteral() const;
72 58
73 // Part 59 // Part
74 60
75 token(part arg); 61 token(part arg);
76 62
77 part getPart() const; 63 const part& getPart() const;
78 64
79 // Fillin 65 // Fillin
80 66
@@ -128,7 +114,7 @@ namespace verbly {
128 bool indefiniteArticle, 114 bool indefiniteArticle,
129 casing capitalization) const; 115 casing capitalization) const;
130 116
131 enum class transform_type { 117 enum class transform_mode {
132 separator, 118 separator,
133 punctuation, 119 punctuation,
134 indefinite_article, 120 indefinite_article,
@@ -137,34 +123,46 @@ namespace verbly {
137 }; 123 };
138 124
139 token( 125 token(
140 transform_type type, 126 transform_mode type,
141 std::string param1, 127 std::string param1,
142 std::string param2, 128 std::string param2,
143 token inner); 129 token inner);
144 130
145 token( 131 token(
146 transform_type type, 132 transform_mode type,
147 casing param, 133 casing param,
148 token inner); 134 token inner);
149 135
150 union { 136 struct word_type {
151 struct { 137 word value;
152 word word_; 138 inflection category;
153 inflection category_;
154 } word_;
155 std::string literal_;
156 part part_;
157 std::set<std::string> fillin_;
158 std::list<token> utterance_;
159 struct {
160 transform_type type_;
161 std::string strParam_;
162 std::string strParam2_;
163 casing casingParam_;
164 std::unique_ptr<token> inner_;
165 } transform_;
166 }; 139 };
140
141 using literal_type = std::string;
142
143 using fillin_type = std::set<std::string>;
144
145 using utterance_type = std::list<token>;
146
147 struct transform_type {
148 transform_mode type;
149 std::string strParam;
150 std::string strParam2;
151 casing casingParam;
152 hatkirby::recptr<token> inner;
153 };
154
155 using variant_type =
156 mpark::variant<
157 word_type,
158 literal_type,
159 part,
160 fillin_type,
161 utterance_type,
162 transform_type>;
163
167 type type_; 164 type type_;
165 variant_type variant_;
168 }; 166 };
169 167
170 std::ostream& operator<<(std::ostream& os, token::type type); 168 std::ostream& operator<<(std::ostream& os, token::type type);