diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-02-16 20:03:48 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-02-16 20:03:48 -0500 |
| commit | 49d6f0387f7b7cc3c6a51ef8fcdf519da98487f6 (patch) | |
| tree | bfddbfdd38317e4f66c4600729b7ea85a94f1061 /lib/token.h | |
| parent | 7cb714b57d1cbebb572e2279e2058f5fc94ba171 (diff) | |
| download | verbly-49d6f0387f7b7cc3c6a51ef8fcdf519da98487f6.tar.gz verbly-49d6f0387f7b7cc3c6a51ef8fcdf519da98487f6.tar.bz2 verbly-49d6f0387f7b7cc3c6a51ef8fcdf519da98487f6.zip | |
Added transform tokens
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 | }; |
