1 #include <fridh/lexer.hpp>
2 #include <ail/string.hpp>
7 type(lexeme_type::uninitialised
)
11 lexeme::lexeme(lexeme
const & other
)
16 lexeme::lexeme(lexeme_type::type type
):
21 lexeme::lexeme(types::boolean boolean
):
22 type(lexeme_type::boolean
),
27 lexeme::lexeme(types::signed_integer signed_integer
):
28 type(lexeme_type::signed_integer
),
29 signed_integer(signed_integer
)
33 lexeme::lexeme(types::unsigned_integer unsigned_integer
):
34 type(lexeme_type::unsigned_integer
),
35 unsigned_integer(unsigned_integer
)
39 lexeme::lexeme(types::floating_point_value floating_point_value
):
40 type(lexeme_type::floating_point_value
),
41 floating_point_value(floating_point_value
)
45 lexeme::lexeme(std::string
const & string
):
46 type(lexeme_type::string
),
47 string(new std::string(string
))
56 std::string
lexeme::to_string() const
60 case lexeme_type::name
:
61 return "name: " + *string
;
63 case lexeme_type::nil
:
66 case lexeme_type::boolean
:
67 return "boolean: " + ail::bool_to_string(boolean
);
69 case lexeme_type::signed_integer
:
70 return "integer: " + ail::number_to_string(signed_integer
);
72 case lexeme_type::unsigned_integer
:
73 return "unsigned-integer: " + ail::number_to_string(unsigned_integer
);
75 case lexeme_type::floating_point_value
:
76 return "float: " + ail::number_to_string(floating_point_value
);
78 case lexeme_type::string
:
79 return "string: " + ail::replace_string(*string
, "\n", "\\n");
81 case lexeme_type::addition
:
84 case lexeme_type::subtraction
:
87 case lexeme_type::multiplication
:
90 case lexeme_type::division
:
93 case lexeme_type::modulo
:
96 case lexeme_type::assignment
:
99 case lexeme_type::addition_assignment
:
102 case lexeme_type::subtraction_assignment
:
105 case lexeme_type::multiplication_assignment
:
108 case lexeme_type::division_assignment
:
111 case lexeme_type::modulo_assignment
:
114 case lexeme_type::exponentiation_assignment
:
117 case lexeme_type::increment
:
120 case lexeme_type::decrement
:
123 case lexeme_type::exponentiation
:
126 case lexeme_type::less_than
:
129 case lexeme_type::less_than_or_equal
:
132 case lexeme_type::greater_than
:
135 case lexeme_type::greater_than_or_equal
:
138 case lexeme_type::not_equal
:
141 case lexeme_type::equal
:
144 case lexeme_type::logical_not
:
147 case lexeme_type::logical_and
:
150 case lexeme_type::logical_or
:
153 case lexeme_type::shift_left
:
156 case lexeme_type::shift_right
:
159 case lexeme_type::binary_and
:
162 case lexeme_type::binary_or
:
165 case lexeme_type::binary_xor
:
168 case lexeme_type::binary_not
:
171 case lexeme_type::bracket_start
:
172 return "bracket: start";
174 case lexeme_type::bracket_end
:
175 return "bracket: end";
177 case lexeme_type::array_start
:
178 return "array: start";
180 case lexeme_type::array_end
:
183 case lexeme_type::scope_start
:
184 return "scope: start";
186 case lexeme_type::scope_end
:
189 case lexeme_type::iteration
:
192 case lexeme_type::iterator
:
195 case lexeme_type::while_operator
:
198 case lexeme_type::function_declaration
:
201 case lexeme_type::anonymous_function_declaration
:
202 return "anonymous function";
204 case lexeme_type::class_operator
:
205 return "class operator";
207 case lexeme_type::dot
:
210 case lexeme_type::call_operator
:
213 case lexeme_type::scope_operator
:
221 lexeme
& lexeme::operator=(lexeme
const & other
)
228 void lexeme::copy(lexeme
const & other
)
232 string
= new std::string(*other
.string
);
235 void lexeme::destroy()
240 type
= lexeme_type::uninitialised
;
243 bool lexeme::is_string() const
246 type
== lexeme_type::name
||
247 type
== lexeme_type::string