diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-23 11:59:23 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-23 11:59:23 -0500 |
commit | 4cbe7a42a685bc2449f1adb7c37144c9496eab5f (patch) | |
tree | cc635814bb6a42222dda78bf3b4a0d6a2c9b81fb /lib/token.h | |
parent | 9bd863c9002b525b7827f9158d9136143393be5c (diff) | |
download | verbly-4cbe7a42a685bc2449f1adb7c37144c9496eab5f.tar.gz verbly-4cbe7a42a685bc2449f1adb7c37144c9496eab5f.tar.bz2 verbly-4cbe7a42a685bc2449f1adb7c37144c9496eab5f.zip |
Rewrote tokens
Diffstat (limited to 'lib/token.h')
-rw-r--r-- | lib/token.h | 236 |
1 files changed, 91 insertions, 145 deletions
diff --git a/lib/token.h b/lib/token.h index ff3c37b..e7f8c28 100644 --- a/lib/token.h +++ b/lib/token.h | |||
@@ -1,170 +1,116 @@ | |||
1 | #ifndef TOKEN_H_AD62C505 | 1 | #ifndef TOKEN_H_AD62C505 |
2 | #define TOKEN_H_AD62C505 | 2 | #define TOKEN_H_AD62C505 |
3 | 3 | ||
4 | #include <ostream> | ||
5 | #include <string> | ||
6 | #include <list> | ||
7 | #include <set> | ||
8 | #include "enums.h" | ||
9 | #include "word.h" | ||
10 | #include "part.h" | ||
11 | |||
4 | namespace verbly { | 12 | namespace verbly { |
5 | 13 | ||
6 | class token { | 14 | class token { |
7 | public: | 15 | public: |
8 | enum class type { | 16 | enum class type { |
9 | verb, | 17 | word, |
10 | noun, | 18 | literal, |
11 | adjective, | 19 | part, |
12 | adverb, | ||
13 | preposition, | ||
14 | fillin, | 20 | fillin, |
15 | utterance, | 21 | utterance |
16 | string | ||
17 | }; | ||
18 | |||
19 | enum class verb_inflection { | ||
20 | infinitive, | ||
21 | past_tense, | ||
22 | past_participle, | ||
23 | s_form, | ||
24 | ing_form | ||
25 | }; | ||
26 | |||
27 | enum class noun_inflection { | ||
28 | singular, | ||
29 | plural | ||
30 | }; | ||
31 | |||
32 | enum class adjective_inflection { | ||
33 | base, | ||
34 | comparative, | ||
35 | superlative | ||
36 | }; | ||
37 | |||
38 | enum class adverb_inflection { | ||
39 | base, | ||
40 | comparative, | ||
41 | superlative | ||
42 | }; | ||
43 | |||
44 | enum class fillin_type { | ||
45 | generic, | ||
46 | noun_phrase, | ||
47 | adjective_phrase, | ||
48 | adverb_phrase, | ||
49 | participle_phrase, | ||
50 | infinitive_phrase | ||
51 | }; | 22 | }; |
52 | 23 | ||
53 | type get_type() const; | 24 | // Copy & move constructors |
54 | 25 | ||
55 | int get_extra() const; | ||
56 | void set_extra(int _arg); | ||
57 | |||
58 | token(const token& other); | 26 | token(const token& other); |
59 | token& operator=(const token& other); | 27 | token(token&& other); |
28 | |||
29 | // Assignment operator | ||
30 | |||
31 | token& operator=(token other); | ||
32 | |||
33 | // Swap | ||
34 | |||
35 | friend void swap(token& first, token& second); | ||
36 | |||
37 | // Destructor | ||
38 | |||
60 | ~token(); | 39 | ~token(); |
61 | 40 | ||
62 | bool is_complete() const; | 41 | // Accessors |
42 | |||
43 | type getType() const | ||
44 | { | ||
45 | return type_; | ||
46 | } | ||
47 | |||
48 | bool isComplete() const; | ||
49 | |||
63 | std::string compile() const; | 50 | std::string compile() const; |
64 | 51 | ||
65 | // Verb | 52 | // Word |
66 | token(verb _verb); | 53 | |
67 | token(verb _verb, verb_inflection _infl); | 54 | token(word arg, inflection category = inflection::base); |
68 | token& operator=(verb _verb); | 55 | |
69 | verb get_verb() const; | 56 | const word& getWord() const; |
70 | void set_verb(verb _verb); | 57 | |
71 | verb_inflection get_verb_inflection() const; | 58 | token inflect(inflection category) const; |
72 | void set_verb_inflection(verb_inflection _infl); | 59 | |
73 | 60 | // Literal | |
74 | // Noun | 61 | |
75 | token(noun _noun); | 62 | token(std::string arg); |
76 | token(noun _noun, noun_inflection _infl); | 63 | token(const char* arg); |
77 | token& operator=(noun _noun); | 64 | |
78 | noun get_noun() const; | 65 | std::string getLiteral() const; |
79 | void set_noun(noun _noun); | 66 | |
80 | noun_inflection get_noun_inflection() const; | 67 | // Part |
81 | void set_noun_inflection(noun_inflection _infl); | 68 | |
82 | 69 | token(part arg); | |
83 | // Adjective | 70 | |
84 | token(adjective _adjective); | 71 | part getPart() const; |
85 | token(adjective _adjective, adjective_inflection _infl); | 72 | |
86 | token& operator=(adjective _adjective); | ||
87 | adjective get_adjective() const; | ||
88 | void set_adjective(adjective _adjective); | ||
89 | adjective_inflection get_adjective_inflection() const; | ||
90 | void set_adjective_inflection(adjective_inflection _infl); | ||
91 | |||
92 | // Adverb | ||
93 | token(adverb _adverb); | ||
94 | token(adverb _adverb, adverb_inflection _infl); | ||
95 | token& operator=(adverb _adverb); | ||
96 | adverb get_adverb() const; | ||
97 | void set_adverb(adverb _adverb); | ||
98 | adverb_inflection get_adverb_inflection() const; | ||
99 | void set_adverb_inflection(adverb_inflection _infl); | ||
100 | |||
101 | // Preposition | ||
102 | token(preposition _preposition); | ||
103 | token& operator=(preposition _preposition); | ||
104 | preposition get_preposition() const; | ||
105 | void set_preposition(preposition _preposition); | ||
106 | |||
107 | // Fillin | 73 | // Fillin |
108 | token(fillin_type _ft); | 74 | |
109 | token& operator=(fillin_type _ft); | 75 | token(std::set<std::string> synrestrs); |
110 | fillin_type get_fillin_type() const; | 76 | |
111 | void set_fillin_type(fillin_type _ft); | 77 | const std::set<std::string>& getSynrestrs() const; |
112 | 78 | ||
79 | bool hasSynrestr(std::string synrestr) const; | ||
80 | |||
81 | void addSynrestr(std::string synrestr); | ||
82 | |||
113 | // Utterance | 83 | // Utterance |
114 | typedef std::list<token>::iterator iterator; | 84 | |
115 | 85 | using iterator = std::list<token>::iterator; | |
86 | using const_iterator = std::list<token>::const_iterator; | ||
87 | |||
116 | token(); | 88 | token(); |
117 | token(std::initializer_list<token> _init); | 89 | token(std::vector<part> parts); |
90 | |||
118 | iterator begin(); | 91 | iterator begin(); |
92 | const_iterator begin() const; | ||
93 | |||
119 | iterator end(); | 94 | iterator end(); |
120 | token& operator<<(token _tkn); | 95 | const_iterator end() const; |
121 | void push_back(token _tkn); | 96 | |
122 | void insert(iterator before, token _tkn); | 97 | token& operator<<(token arg); |
123 | void replace(iterator torepl, token _tkn); | 98 | |
124 | void erase(iterator toer); | ||
125 | |||
126 | // String | ||
127 | token(std::string _str); | ||
128 | token& operator=(std::string _str); | ||
129 | std::string get_string() const; | ||
130 | void set_string(std::string _str); | ||
131 | |||
132 | private: | 99 | private: |
133 | type _type; | ||
134 | int _extra = 0; | ||
135 | union { | 100 | union { |
136 | struct { | 101 | struct { |
137 | verb _verb; | 102 | word word_; |
138 | verb_inflection _infl; | 103 | inflection category_; |
139 | } _verb; | 104 | } word_; |
140 | struct { | 105 | std::string literal_; |
141 | noun _noun; | 106 | part part_; |
142 | noun_inflection _infl; | 107 | std::set<std::string> fillin_; |
143 | } _noun; | 108 | std::list<token> utterance_; |
144 | struct { | ||
145 | adjective _adjective; | ||
146 | adjective_inflection _infl; | ||
147 | } _adjective; | ||
148 | struct { | ||
149 | adverb _adverb; | ||
150 | adverb_inflection _infl; | ||
151 | } _adverb; | ||
152 | struct { | ||
153 | preposition _preposition; | ||
154 | } _preposition; | ||
155 | struct { | ||
156 | fillin_type _type; | ||
157 | } _fillin; | ||
158 | struct { | ||
159 | std::string _str; | ||
160 | } _string; | ||
161 | struct { | ||
162 | std::list<token> _utterance; | ||
163 | } _utterance; | ||
164 | }; | 109 | }; |
110 | type type_; | ||
165 | }; | 111 | }; |
166 | 112 | ||
167 | std::ostream& operator<<(std::ostream& os, token::type _type); | 113 | std::ostream& operator<<(std::ostream& os, token::type type); |
168 | 114 | ||
169 | }; | 115 | }; |
170 | 116 | ||