Implemented the one-liner operators ` ( )
[fridhskrift.git] / lexer / operator.cpp
blob3f75b28bea170fdcd99e400b763d60654a0d3d85
1 #include <fridh/lexer.hpp>
2 #include <algorithm>
3 #include <ail/string.hpp>
4 #include <ail/array.hpp>
6 namespace fridh
8 bool tables_initialised = false;
10 operator_lexeme operators[] =
12 operator_lexeme(lexeme_type::addition, "+"),
13 operator_lexeme(lexeme_type::subtraction, "-"),
14 operator_lexeme(lexeme_type::multiplication, "*"),
15 operator_lexeme(lexeme_type::division, "/"),
16 operator_lexeme(lexeme_type::modulo, "%"),
17 operator_lexeme(lexeme_type::exponentiation, "**"),
19 operator_lexeme(lexeme_type::assignment, "="),
20 operator_lexeme(lexeme_type::addition_assignment, "+="),
21 operator_lexeme(lexeme_type::subtraction_assignment, "-="),
22 operator_lexeme(lexeme_type::multiplication_assignment, "*="),
23 operator_lexeme(lexeme_type::division_assignment, "/="),
24 operator_lexeme(lexeme_type::modulo_assignment, "%="),
25 operator_lexeme(lexeme_type::exponentiation_assignment, "**="),
27 operator_lexeme(lexeme_type::increment, "++"),
28 operator_lexeme(lexeme_type::decrement, "--"),
30 operator_lexeme(lexeme_type::less_than, "<"),
31 operator_lexeme(lexeme_type::less_than_or_equal, "<="),
32 operator_lexeme(lexeme_type::greater_than, ">"),
33 operator_lexeme(lexeme_type::greater_than_or_equal, ">="),
34 operator_lexeme(lexeme_type::not_equal, "!="),
35 operator_lexeme(lexeme_type::equal, "=="),
37 operator_lexeme(lexeme_type::logical_not, "!"),
39 operator_lexeme(lexeme_type::logical_and, "&"),
40 operator_lexeme(lexeme_type::logical_or, "|"),
42 operator_lexeme(lexeme_type::shift_left, "<<"),
43 operator_lexeme(lexeme_type::shift_right, ">>"),
45 operator_lexeme(lexeme_type::binary_and, "&&"),
46 operator_lexeme(lexeme_type::binary_or, "||"),
47 operator_lexeme(lexeme_type::binary_xor, "^"),
49 operator_lexeme(lexeme_type::binary_not, "~"),
51 operator_lexeme(lexeme_type::bracket_start, "["),
52 operator_lexeme(lexeme_type::bracket_end, "]"),
54 operator_lexeme(lexeme_type::array_start, "{"),
55 operator_lexeme(lexeme_type::array_end, "}"),
58 operator_lexeme(lexeme_type::scope_start, "("),
59 operator_lexeme(lexeme_type::scope_end, ")"),
62 operator_lexeme(lexeme_type::iteration, "\\"),
63 operator_lexeme(lexeme_type::iterator, "#"),
65 operator_lexeme(lexeme_type::while_operator, "\\\\"),
67 operator_lexeme(lexeme_type::function_declaration, "@"),
68 operator_lexeme(lexeme_type::anonymous_function_declaration, "@@"),
69 operator_lexeme(lexeme_type::class_operator, "$"),
70 operator_lexeme(lexeme_type::dot, "."),
71 operator_lexeme(lexeme_type::scope_operator, ":"),
73 operator_lexeme(lexeme_type::call_operator, ","),
74 operator_lexeme(lexeme_type::spaced_call_operator, ", "),
77 std::vector<operator_lexeme> operator_lexeme_data;
79 void initialise_tables()
81 boost::mutex::scoped_lock scoped_lock(table_mutex);
83 if(tables_initialised)
84 return;
86 tables_initialised = true;
88 std::sort(operators, operators + ail::countof(operators));
90 for(std::size_t i = 0; i < ail::countof(operators); i++)
91 operator_lexeme_data.push_back(operators[i]);