Added assignment lexemes
[fridhskrift.git] / lexer / lexeme.cpp
blob9b9ff648429a9280bd3d4e04f22fd7913da0312b
1 #include <frith/lexer.hpp>
2 #include <ail/string.hpp>
4 namespace frith
5 {
6 lexeme_type::lexeme()
10 lexeme_type::lexeme(lexeme_type::type type):
11 type(type)
15 lexeme_type::lexeme(types::boolean boolean):
16 type(boolean),
17 boolean(boolean)
21 lexeme_type::lexeme(types::signed_integer signed_integer):
22 type(signed_integer),
23 signed_integer(signed_integer)
27 lexeme_type::lexeme(types::unsigned_integer unsigned_integer):
28 type(unsigned_integer),
29 unsigned_integer(unsigned_integer)
33 lexeme_type::lexeme(types::floating_point_value floating_point_value):
34 type(floating_point_value),
35 floating_point_value(floating_point_value)
39 lexeme_type::lexeme(lexeme_type::type type, std::string const & string):
40 type(type),
41 string(new std::string(string))
45 std::string lexeme_type::to_string() const
47 using namespace lexeme_type;
49 switch(type)
51 case name:
52 return "name: " + *string;
54 case boolean:
55 return "boolean: " + ail::bool_to_string(boolean);
57 case signed_integer:
58 return "integer: " + ail::number_to_string(signed_integer);
60 case unsigned_integer:
61 return "unsigned-integer: " + ail::number_to_string(unsigned_integer);
63 case floating_point_value:
64 return "float: " + ail::number_to_string(floating_point_value);
66 case string:
67 return "string: " + ail::replace_string(*string, "\n", "\\n");
69 case addition:
70 return "+";
72 case subtraction:
73 return "-";
75 case multiplication:
76 return "*";
78 case division:
79 return "/";
81 case modulo:
82 return "%";
84 case assignment:
85 return "=";
87 case addition_assignment:
88 return "+=";
90 case subtraction_assignment:
91 return "-=";
93 case multiplication_assignment:
94 return "*=";
96 case division_assignment:
97 return "/=";
99 case modulo_assignment:
100 return "%=";
102 case increment:
103 return "++";
105 case decrement:
106 return "--";
108 case exponentiation:
109 return "**";
111 case less_than:
112 return "<";
114 case less_than_or_equal:
115 return "<=";
117 case greater_than:
118 return ">";
120 case greater_than_or_equal:
121 return ">=";
123 case unequal:
124 return "!=";
126 case equal:
127 return "==";
129 case logical_not:
130 return "!";
132 case logical_and:
133 return "&";
135 case logical_or:
136 return "|";
138 case shift_left:
139 return "<<";
141 case shift_right:
142 return ">>";
144 case binary_and:
145 return "&&";
147 case binary_or:
148 return "||";
150 case binary_xor:
151 return "^";
153 case binary_not:
154 return "~";
156 case bracket_start:
157 return "bracket: start";
159 case bracket_end:
160 return "bracket: end";
162 case array_start:
163 return "array: start";
165 case array_end:
166 return "array: end";
168 case scope_start:
169 return "symbol_tree_node: start";
171 case scope_end:
172 return "symbol_tree_node: end";
174 case iteration:
175 return "iteration";
177 case iterator:
178 return "iterator";
180 case function_declaration:
181 return "function";
183 case anonymous_function_declaration:
184 return "anonymous function";
186 case class_operator:
187 return "class operator";
189 case dot:
190 return ".";
192 case scope_operator:
193 return ":";
195 default:
196 return "unknown";