4 #include "lexeme_impl.h"
8 using namespace utakata::lexeme;
9 using namespace utakata::utf8_string;
10 using namespace utakata::interpreter;
13 smart_ptr<ILexeme> utakata::lexeme::makeOpenParen()
15 smart_ptr<UTF8String> tmp(new UTF8String());
17 return smart_ptr<ILexeme>(new PureLexeme(tmp, LexemeID::openParenthesis));
20 smart_ptr<ILexeme> utakata::lexeme::makeEOS()
22 return smart_ptr<ILexeme>(new PureLexeme(smart_ptr<UTF8String>(), LexemeID::eos));
25 smart_ptr<ILexeme> utakata::lexeme::makeCloseParen()
27 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(")")));
28 return smart_ptr<ILexeme>(new PureLexeme(tmp,
29 LexemeID::closeParenthesis));
32 smart_ptr<ILexeme> utakata::lexeme::makeBackQuote()
34 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("`")));
35 return smart_ptr<ILexeme>(new PureLexeme(tmp,
36 LexemeID::backquote));
39 smart_ptr<ILexeme> utakata::lexeme::makeQuote()
41 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("'")));
42 return smart_ptr<ILexeme>(new PureLexeme(tmp,
46 smart_ptr<ILexeme> utakata::lexeme::makeDot()
48 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(".")));
49 return smart_ptr<ILexeme>(new PureLexeme(tmp,
53 smart_ptr<ILexeme> utakata::lexeme::makeIdentifier(const utakata::utf8_string::UTF8String& str)
55 return smart_ptr<ILexeme>(new Identifier(str));
58 smart_ptr<ILexeme> utakata::lexeme::makeString(const utakata::utf8_string::UTF8String& str)
60 return smart_ptr<ILexeme>(new String(str));
63 smart_ptr<ILexeme> utakata::lexeme::makeUnquoteSplicing(const utakata::utf8_string::UTF8String& str)
65 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(",@")));
66 return smart_ptr<ILexeme>(new PureLexeme(tmp,
67 LexemeID::unquoteSplicing));
70 smart_ptr<ILexeme> utakata::lexeme::makeUnquote()
72 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(",")));
73 return smart_ptr<ILexeme>(new PureLexeme(tmp,
77 smart_ptr<ILexeme> utakata::lexeme::makeByteVector()
79 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#vu(")));
80 return smart_ptr<ILexeme>(new PureLexeme(tmp,
81 LexemeID::byteVector));
84 smart_ptr<ILexeme> utakata::lexeme::makeVector()
86 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#(")));
87 return smart_ptr<ILexeme>(new PureLexeme(tmp,
91 smart_ptr<ILexeme> utakata::lexeme::makeSyntax()
93 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#'")));
94 return smart_ptr<ILexeme>(new PureLexeme(tmp,
98 smart_ptr<ILexeme> utakata::lexeme::makeQuasiSyntax()
100 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#`")));
101 return smart_ptr<ILexeme>(new PureLexeme(tmp,
102 LexemeID::quasiSyntax));
105 smart_ptr<ILexeme> utakata::lexeme::makeUnsyntaxSplicing()
107 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert("#,@")));
108 return smart_ptr<ILexeme>(new PureLexeme(tmp,
109 LexemeID::unsyntaxSplicing));
112 smart_ptr<ILexeme> utakata::lexeme::makeUnsyntax()
114 smart_ptr<UTF8String> tmp(new UTF8String(utf8_string::convert(",#")));
115 return smart_ptr<ILexeme>(new PureLexeme(tmp,
116 LexemeID::unsyntax));
119 smart_ptr<ILexeme> utakata::lexeme::makeCharactor(const utakata::utf8_string::UTF8String& str)
121 return smart_ptr<ILexeme>(new Charactor(str));
124 smart_ptr<ILexeme> utakata::lexeme::makeBoolean(const smart_ptr<utakata::utf8_string::UTF8Char>& ch)
126 return smart_ptr<ILexeme>(new Boolean(ch));
129 smart_ptr<ILexeme> utakata::lexeme::makeNanImaginary(const utakata::utf8_string::UTF8String& str,
132 return smart_ptr<ILexeme>(new Number(utakata::utf8_string::UTF8String(),
136 smart_ptr<ILexeme> utakata::lexeme::makeInfImaginary(const utakata::utf8_string::UTF8String& str,
139 return smart_ptr<ILexeme>(new Number(utakata::utf8_string::UTF8String(),
143 smart_ptr<ILexeme> utakata::lexeme::makeImaginaryOnly(const utakata::utf8_string::UTF8String& str,
147 return smart_ptr<ILexeme>(new Number(utakata::utf8_string::UTF8String(),
151 smart_ptr<ILexeme> utakata::lexeme::makeNumber(const utakata::utf8_string::UTF8String& real,
152 const utakata::utf8_string::UTF8String& imagin,
153 bool exact, int radix)
155 return smart_ptr<ILexeme>(new Number(real, imagin, exact, radix));
161 PureLexeme::PureLexeme(const smart_ptr<UTF8String>& str,
162 const LexemeID id) : str_(str), id_(id)
165 const LexemeID PureLexeme::getID() const
170 smart_ptr<UTF8String> PureLexeme::toString() const
175 smart_ptr<utakata::interpreter::LiteralData> PureLexeme::getData() const
177 return smart_ptr<utakata::interpreter::LiteralData>();
184 Identifier::Identifier(const utakata::utf8_string::UTF8String& str) :
185 str_(new utakata::utf8_string::UTF8String(str))
189 const utakata::lexeme::LexemeID Identifier::getID() const
191 return utakata::lexeme::LexemeID::identifier;
194 smart_ptr<utakata::utf8_string::UTF8String> Identifier::toString() const
199 smart_ptr<utakata::interpreter::LiteralData> Identifier::getData() const
201 smart_ptr<utakata::interpreter::LiteralData> data(new utakata::interpreter::LiteralData);
203 data->string.add(new utakata::interpreter::StringData);
204 data->string->str.add(new utakata::utf8_string::UTF8String(*str_));
212 String::String(const utakata::utf8_string::UTF8String& str) :
213 str_(new utakata::utf8_string::UTF8String(str))
217 const utakata::lexeme::LexemeID String::getID() const
219 return utakata::lexeme::LexemeID::identifier;
222 smart_ptr<utakata::utf8_string::UTF8String> String::toString() const
227 smart_ptr<utakata::interpreter::LiteralData> String::getData() const
229 smart_ptr<utakata::interpreter::LiteralData> data(new utakata::interpreter::LiteralData);
231 data->string.add(new utakata::interpreter::StringData);
232 data->string->str.add(new utakata::utf8_string::UTF8String(*str_));
240 Number::Number(const UTF8String& real,
241 const UTF8String& imagin,
242 bool exact, int radix) :
243 data_(new LiteralData)
245 data_->number = utakata::interpreter::makeNumberData(real, imagin, exact, radix);
248 const utakata::lexeme::LexemeID Number::getID() const
250 return utakata::lexeme::LexemeID::number;
253 smart_ptr<utakata::utf8_string::UTF8String> Number::toString() const
255 return smart_ptr<UTF8String>(new UTF8String(*data_->number->real + *data_->number->imagin));
258 smart_ptr<utakata::interpreter::LiteralData> Number::getData() const
267 Charactor::Charactor(const UTF8String& ch) : ch_(new UTF8String(ch))
271 const utakata::lexeme::LexemeID Charactor::getID() const
273 return utakata::lexeme::LexemeID::charactor;
276 smart_ptr<utakata::utf8_string::UTF8String> Charactor::toString() const
281 smart_ptr<utakata::interpreter::LiteralData> Charactor::getData() const
283 smart_ptr<utakata::interpreter::LiteralData> data(new utakata::interpreter::LiteralData);
285 data->string.add(new utakata::interpreter::StringData);
286 data->string->str.add(new utakata::utf8_string::UTF8String(*ch_));
295 Boolean::Boolean(const smart_ptr<UTF8Char>& ch) : bool_(new UTF8String())
300 const utakata::lexeme::LexemeID Boolean::getID() const
302 return utakata::lexeme::LexemeID::boolean;
305 smart_ptr<utakata::utf8_string::UTF8String> Boolean::toString() const
310 smart_ptr<utakata::interpreter::LiteralData> Boolean::getData() const
312 smart_ptr<utakata::interpreter::LiteralData> data(new utakata::interpreter::LiteralData);
314 data->string.add(new utakata::interpreter::StringData);
315 data->string->str.add(new utakata::utf8_string::UTF8String(*bool_));