diff options
Diffstat (limited to 'lib/token.h')
-rw-r--r-- | lib/token.h | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/token.h b/lib/token.h index e7f8c28..f3188c9 100644 --- a/lib/token.h +++ b/lib/token.h | |||
@@ -18,7 +18,8 @@ namespace verbly { | |||
18 | literal, | 18 | literal, |
19 | part, | 19 | part, |
20 | fillin, | 20 | fillin, |
21 | utterance | 21 | utterance, |
22 | transform | ||
22 | }; | 23 | }; |
23 | 24 | ||
24 | // Copy & move constructors | 25 | // Copy & move constructors |
@@ -87,6 +88,7 @@ namespace verbly { | |||
87 | 88 | ||
88 | token(); | 89 | token(); |
89 | token(std::vector<part> parts); | 90 | token(std::vector<part> parts); |
91 | token(std::initializer_list<token> pieces); | ||
90 | 92 | ||
91 | iterator begin(); | 93 | iterator begin(); |
92 | const_iterator begin() const; | 94 | const_iterator begin() const; |
@@ -96,7 +98,35 @@ namespace verbly { | |||
96 | 98 | ||
97 | token& operator<<(token arg); | 99 | token& operator<<(token arg); |
98 | 100 | ||
101 | // Transform | ||
102 | |||
103 | static token separator(std::string param, token inner); | ||
104 | static token punctuation(std::string param, token inner); | ||
105 | static token definiteArticle(token inner); | ||
106 | static token capitalize(token inner); | ||
107 | |||
108 | token& getInnerToken(); | ||
109 | const token& getInnerToken() const; | ||
110 | |||
99 | private: | 111 | private: |
112 | |||
113 | std::string compileHelper( | ||
114 | std::string separator, | ||
115 | bool definiteArticle, | ||
116 | bool capitalize) const; | ||
117 | |||
118 | enum class transform_type { | ||
119 | separator, | ||
120 | punctuation, | ||
121 | definite_article, | ||
122 | capitalize | ||
123 | }; | ||
124 | |||
125 | token( | ||
126 | transform_type type, | ||
127 | std::string param, | ||
128 | token inner); | ||
129 | |||
100 | union { | 130 | union { |
101 | struct { | 131 | struct { |
102 | word word_; | 132 | word word_; |
@@ -106,6 +136,11 @@ namespace verbly { | |||
106 | part part_; | 136 | part part_; |
107 | std::set<std::string> fillin_; | 137 | std::set<std::string> fillin_; |
108 | std::list<token> utterance_; | 138 | std::list<token> utterance_; |
139 | struct { | ||
140 | transform_type type_; | ||
141 | std::string param_; | ||
142 | std::unique_ptr<token> inner_; | ||
143 | } transform_; | ||
109 | }; | 144 | }; |
110 | type type_; | 145 | type type_; |
111 | }; | 146 | }; |