summary refs log tree commit diff stats
path: root/token.h
diff options
context:
space:
mode:
Diffstat (limited to 'token.h')
-rw-r--r--token.h82
1 files changed, 34 insertions, 48 deletions
diff --git a/token.h b/token.h index 2848fd0..44d99cb 100644 --- a/token.h +++ b/token.h
@@ -4,16 +4,10 @@
4#include <string> 4#include <string>
5#include <list> 5#include <list>
6#include <sstream> 6#include <sstream>
7#include "verb.h"
8 7
9namespace verbly { 8namespace verbly {
10 9
11 enum class type { 10 class verb;
12 verb,
13 fillin,
14 string,
15 utterance
16 };
17 11
18 class selrestr { 12 class selrestr {
19 }; 13 };
@@ -29,20 +23,22 @@ namespace verbly {
29 }; 23 };
30 24
31 class token { 25 class token {
26 public:
27 enum class type {
28 verb,
29 fillin,
30 string,
31 utterance
32 };
33
32 protected: 34 protected:
33 // General 35 // General
34 type type; 36 type _type;
35 37
36 token(enum type type) : type(type) 38 token(type _type);
37 {
38
39 }
40 39
41 public: 40 public:
42 enum type token_type() const 41 enum type token_type() const;
43 {
44 return type;
45 }
46 42
47 virtual bool complete() const = 0; 43 virtual bool complete() const = 0;
48 virtual std::string compile() const = 0; 44 virtual std::string compile() const = 0;
@@ -50,42 +46,32 @@ namespace verbly {
50 }; 46 };
51 47
52 class verb_token : public token { 48 class verb_token : public token {
49 public:
50 enum class inflection {
51 infinitive,
52 past_tense,
53 past_participle,
54 ing_form,
55 s_form
56 };
57
53 private: 58 private:
54 // Verb 59 // Verb
55 const verb* m_verb; 60 const verb* _verb;
56 conjugation verb_infl = conjugation::infinitive; 61 inflection _inflection = inflection::infinitive;
57 62
58 public: 63 public:
59 verb_token(const class verb& verb) : token(type::verb), m_verb(&verb) 64 verb_token(const class verb& _verb);
60 {
61
62 }
63 65
64 const class verb& verb() const 66 const class verb& verb() const;
65 {
66 return *m_verb;
67 }
68 67
69 verb_token& conjugate(conjugation infl) 68 verb_token& inflect(inflection infl);
70 {
71 verb_infl = infl;
72 return *this;
73 }
74 69
75 bool complete() const 70 bool complete() const;
76 {
77 return true;
78 }
79 71
80 std::string compile() const 72 std::string compile() const;
81 {
82 return m_verb->conjugate(verb_infl);
83 }
84 73
85 token* copy() const 74 token* copy() const;
86 {
87 return new verb_token(*this);
88 }
89 }; 75 };
90 76
91 class utterance_token : public token { 77 class utterance_token : public token {
@@ -140,7 +126,7 @@ namespace verbly {
140 } 126 }
141 };*/ 127 };*/
142 128
143 utterance_token(std::initializer_list<token*> tkns) : token(type::utterance) 129 utterance_token(std::initializer_list<token*> tkns) : token(token::type::utterance)
144 { 130 {
145 for (auto tkn : tkns) 131 for (auto tkn : tkns)
146 { 132 {
@@ -148,7 +134,7 @@ namespace verbly {
148 } 134 }
149 } 135 }
150 136
151 utterance_token(const utterance_token& other) : token(type::utterance) 137 utterance_token(const utterance_token& other) : token(token::type::utterance)
152 { 138 {
153 for (auto& tkn : other.utterance) 139 for (auto& tkn : other.utterance)
154 { 140 {
@@ -156,7 +142,7 @@ namespace verbly {
156 } 142 }
157 } 143 }
158 144
159 utterance_token(utterance_token&& other) : token(type::utterance), utterance(std::move(other.utterance)) 145 utterance_token(utterance_token&& other) : token(token::type::utterance), utterance(std::move(other.utterance))
160 { 146 {
161 147
162 } 148 }
@@ -237,7 +223,7 @@ namespace verbly {
237 fillin_type m_fillin_type; 223 fillin_type m_fillin_type;
238 224
239 public: 225 public:
240 fillin_token(fillin_type ft) : token(type::fillin), m_fillin_type(ft) 226 fillin_token(fillin_type ft) : token(token::type::fillin), m_fillin_type(ft)
241 { 227 {
242 228
243 } 229 }
@@ -301,7 +287,7 @@ namespace verbly {
301 std::string str; 287 std::string str;
302 288
303 public: 289 public:
304 string_token(std::string str) : token(type::string), str(str) 290 string_token(std::string str) : token(token::type::string), str(str)
305 { 291 {
306 292
307 } 293 }