OSDN Git Service

-boolean、およびバイトベクタについて足りなかったため、実装した。
[simplecms/utakata.git] / lexeme_impl.cpp
1 #include <vector>
2 #include <string>
3
4 #include "lexeme_impl.h"
5 #include "lexeme_id.h"
6
7
8 using namespace utakata::lexeme;
9 using namespace utakata::utf8_string;
10
11 smart_ptr<ILexeme> utakata::lexeme::makeOpenParen()
12 {
13     return smart_ptr<ILexeme>(new OpenParen());
14 }
15
16 smart_ptr<ILexeme> utakata::lexeme::makeEOF()
17 {
18     return smart_ptr<ILexeme>(new EOFToken());
19 }
20
21 smart_ptr<ILexeme> utakata::lexeme::makeCloseParen()
22 {
23     return smart_ptr<ILexeme>(new CloseParen());
24 }
25
26 smart_ptr<ILexeme> utakata::lexeme::makeBackQuote()
27 {
28     return smart_ptr<ILexeme>(new BackQuote());
29 }
30
31 smart_ptr<ILexeme> utakata::lexeme::makeQuote()
32 {
33     return smart_ptr<ILexeme>(new Quote());
34 }
35
36 smart_ptr<ILexeme> utakata::lexeme::makeDot()
37 {
38     return smart_ptr<ILexeme>(new Dot());
39 }
40
41 smart_ptr<ILexeme> utakata::lexeme::makeIdentifier(const utakata::utf8_string::UTF8String& str)
42 {
43     return smart_ptr<ILexeme>(new Identifier(str));
44 }
45
46 smart_ptr<ILexeme> utakata::lexeme::makeString(const utakata::utf8_string::UTF8String& str)
47 {
48     return smart_ptr<ILexeme>(new String(str));
49 }
50
51 smart_ptr<ILexeme> utakata::lexeme::makeUnquoteSplicing(const utakata::utf8_string::UTF8String& str)
52 {
53     return smart_ptr<ILexeme>(new UnquoteSplicing());
54 }
55
56 smart_ptr<ILexeme> utakata::lexeme::makeUnquote()
57 {
58     return smart_ptr<ILexeme>(new Unquote());
59 }
60
61 smart_ptr<ILexeme> utakata::lexeme::makeByteVector()
62 {
63     return smart_ptr<ILexeme>(new ByteVector());
64 }
65
66 smart_ptr<ILexeme> utakata::lexeme::makeSyntax()
67 {
68     return smart_ptr<ILexeme>(new Syntax());
69 }
70
71 smart_ptr<ILexeme> utakata::lexeme::makeQuasiSyntax()
72 {
73     return smart_ptr<ILexeme>(new QuasiSyntax());
74 }
75
76 smart_ptr<ILexeme> utakata::lexeme::makeUnsyntaxSplicing()
77 {
78     return smart_ptr<ILexeme>(new UnsyntaxSplicing());
79 }
80
81 smart_ptr<ILexeme> utakata::lexeme::makeUnsyntax()
82 {
83     return smart_ptr<ILexeme>(new Unsyntax());
84 }
85
86 smart_ptr<ILexeme> utakata::lexeme::makeCharactor(const utakata::utf8_string::UTF8String& str)
87 {
88     return smart_ptr<ILexeme>(new Charactor(str));
89 }
90
91 smart_ptr<ILexeme> utakata::lexeme::makeBoolean(const smart_ptr<utakata::utf8_string::UTF8Char>& ch)
92 {
93     return smart_ptr<ILexeme>(new Boolean(ch));
94 }
95
96 smart_ptr<ILexeme> utakata::lexeme::makeNanImaginary(const utakata::utf8_string::UTF8String& str,
97                                                      bool exact)
98 {
99     return smart_ptr<ILexeme>(new Number(utakata::utf8_string::UTF8String(),
100                                          str, exact, 10));
101 }
102
103 smart_ptr<ILexeme> utakata::lexeme::makeInfImaginary(const utakata::utf8_string::UTF8String& str,
104                                                      bool exact)
105 {
106     return smart_ptr<ILexeme>(new Number(utakata::utf8_string::UTF8String(),
107                                          str, exact, 10));
108 }
109
110 smart_ptr<ILexeme> utakata::lexeme::makeImaginaryOnly(const utakata::utf8_string::UTF8String& str,
111                                                       bool exact)
112 {
113
114     return smart_ptr<ILexeme>(new Number(utakata::utf8_string::UTF8String(),
115                                          str, exact, 10));
116 }
117
118 smart_ptr<ILexeme> utakata::lexeme::makeNumber(const utakata::utf8_string::UTF8String& real,
119                                                const utakata::utf8_string::UTF8String& imagin,
120                                                bool exact, int radix)
121 {
122     return smart_ptr<ILexeme>(new Number(real, imagin, exact, radix));
123 }
124
125
126 // 各lexemeの実装
127
128 ///////////////
129 // OpenParen //
130 ///////////////
131
132 int OpenParen::getID() const
133 {
134     return IDProxy()->openParenthesis;
135 }
136
137 smart_ptr<utakata::utf8_string::UTF8String> OpenParen::toString() const
138 {
139     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
140     *p += std::string("(");
141     return p;
142 }
143
144 /////////
145 // EOF //
146 /////////
147
148 int EOFToken::getID() const
149 {
150     return IDProxy()->eof;
151 }
152
153 smart_ptr<utakata::utf8_string::UTF8String> EOFToken::toString() const
154 {
155     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
156     *p += std::string("");
157     return p;
158 }
159
160
161 ////////////////
162 // CloseParen //
163 ////////////////
164
165 int CloseParen::getID() const
166 {
167     return IDProxy()->closeParenthesis;
168 }
169
170 smart_ptr<utakata::utf8_string::UTF8String> CloseParen::toString() const
171 {
172     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
173     *p += std::string(")");
174     return p;
175 }
176
177 ///////////////
178 // BackQuote //
179 ///////////////
180
181 int BackQuote::getID() const
182 {
183     return IDProxy()->backquote;
184 }
185
186 smart_ptr<utakata::utf8_string::UTF8String> BackQuote::toString() const
187 {
188     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
189     *p += std::string("`");
190     return p;
191 }
192
193 ///////////
194 // Quote //
195 ///////////
196
197 int Quote::getID() const
198 {
199     return IDProxy()->quote;
200 }
201
202 smart_ptr<utakata::utf8_string::UTF8String> Quote::toString() const
203 {
204     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
205     *p += std::string("'");
206     return p;
207 }
208
209 /////////
210 // Dot //
211 /////////
212
213 int Dot::getID() const
214 {
215     return IDProxy()->dot;
216 }
217
218 smart_ptr<utakata::utf8_string::UTF8String> Dot::toString() const
219 {
220     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
221     *p += std::string(".");
222     return p;
223 }
224
225 /////////////////////
226 // UnquoteSplicing //
227 /////////////////////
228
229 int UnquoteSplicing::getID() const
230 {
231     return IDProxy()->unquoteSplicing;
232 }
233
234 smart_ptr<utakata::utf8_string::UTF8String> UnquoteSplicing::toString() const
235 {
236     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
237     *p += std::string(",@");
238     return p;
239 }
240
241 ////////////////
242 // ByteVector //
243 ////////////////
244
245 int ByteVector::getID() const
246 {
247     return IDProxy()->unquoteSplicing;
248 }
249
250 smart_ptr<utakata::utf8_string::UTF8String> ByteVector::toString() const
251 {
252     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
253     *p += std::string("#vu8(");
254     return p;
255 }
256
257
258 /////////////
259 // Unquote //
260 /////////////
261
262 int Unquote::getID() const
263 {
264     return IDProxy()->unquote;
265 }
266
267 smart_ptr<utakata::utf8_string::UTF8String> Unquote::toString() const
268 {
269     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
270     *p += std::string(",");
271     return p;
272 }
273
274 ////////////
275 // Syntax //
276 ////////////
277
278 int Syntax::getID() const
279 {
280     return IDProxy()->syntax;
281 }
282
283 smart_ptr<utakata::utf8_string::UTF8String> Syntax::toString() const
284 {
285     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
286     *p += std::string("#'");
287     return p;
288 }
289
290 /////////////////
291 // QuasiSyntax //
292 /////////////////
293
294 int QuasiSyntax::getID() const
295 {
296     return IDProxy()->quasiSyntax;
297 }
298
299 smart_ptr<utakata::utf8_string::UTF8String> QuasiSyntax::toString() const
300 {
301     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
302     *p += std::string("#`");
303     return p;
304 }
305
306 //////////////
307 // Unsyntax //
308 //////////////
309
310 int Unsyntax::getID() const
311 {
312     return IDProxy()->unsyntax;
313 }
314
315 smart_ptr<utakata::utf8_string::UTF8String> Unsyntax::toString() const
316 {
317     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
318     *p += std::string("#,");
319     return p;
320 }
321
322 //////////////////////
323 // UnsyntaxSplicing //
324 //////////////////////
325
326 int UnsyntaxSplicing::getID() const
327 {
328     return IDProxy()->unsyntaxSplicing;
329 }
330
331 smart_ptr<utakata::utf8_string::UTF8String> UnsyntaxSplicing::toString() const
332 {
333     smart_ptr<utakata::utf8_string::UTF8String> p(new utf8_string::UTF8String);
334     *p += std::string("#,@");
335     return p;
336 }
337
338 ////////////////
339 // Identifier //
340 ////////////////
341
342 Identifier::Identifier(const utakata::utf8_string::UTF8String& str) :
343     str_(new utakata::utf8_string::UTF8String(str))
344 {}
345
346 int Identifier::getID() const
347 {
348     return IDProxy()->identifier;
349 }
350
351 smart_ptr<utakata::utf8_string::UTF8String> Identifier::toString() const
352 {
353     return str_;
354 }
355
356 /////////////
357 // String  //
358 /////////////
359
360 String::String(const utakata::utf8_string::UTF8String& str) :
361     str_(new utakata::utf8_string::UTF8String(str))
362 {}
363
364 int String::getID() const
365 {
366     return IDProxy()->string;
367 }
368
369 smart_ptr<utakata::utf8_string::UTF8String> String::toString() const
370 {
371     return str_;
372 }
373
374 ////////////
375 // Number //
376 ////////////
377
378 Number::Number(const UTF8String& real,
379                const UTF8String& imagin,
380                bool exact, int radix) :
381     real_(new UTF8String(real)), imagin_(new UTF8String(imagin)),
382     exact_(exact), radix_(radix)
383 {
384 }
385
386 int Number::getID() const
387 {
388     return IDProxy()->number;
389 }
390
391 smart_ptr<utakata::utf8_string::UTF8String> Number::toString() const
392 {
393     return smart_ptr<UTF8String>(new UTF8String(*real_ + *imagin_));
394 }
395
396 ///////////////
397 // Charactor //
398 ///////////////
399
400 Charactor::Charactor(const UTF8String& ch) : ch_(new UTF8String(ch))
401 {}
402
403 int Charactor::getID() const
404 {
405     return IDProxy()->charactor;
406 }
407
408 smart_ptr<utakata::utf8_string::UTF8String> Charactor::toString() const
409 {
410     return ch_;
411 }
412
413 /////////////
414 // Boolean //
415 /////////////
416
417 Boolean::Boolean(const smart_ptr<UTF8Char>& ch) : str_(new UTF8String())
418 {
419     *str_ += *ch;
420 }
421
422 int Boolean::getID() const
423 {
424     return IDProxy()->boolean;
425 }
426
427 smart_ptr<utakata::utf8_string::UTF8String> Boolean::toString() const
428 {
429     return str_;
430 }