Renamed the property operator to the selection operator
[fridhskrift.git] / frith / lexer.hpp
blob9ec10f7ddf03e111280f372c73156e74895c2368
1 #pragma once
3 #include <string>
4 #include <vector>
5 #include <ail/types.hpp>
6 #include <frith/symbol.hpp>
7 #include <boost/thread/mutex.hpp>
9 namespace frith
11 namespace lexeme_type
13 enum type
15 name,
17 boolean,
18 signed_integer,
19 unsigned_integer,
20 floating_point_value,
21 string,
23 addition,
24 subtraction,
25 multiplication,
26 division,
27 modulo,
28 exponentiation,
30 assignment,
31 addition_assignment,
32 subtraction_assignment,
33 multiplication_assignment,
34 division_assignment,
35 modulo_assignment,
36 exponentiation_assignment,
38 increment,
39 decrement,
41 less_than,
42 less_than_or_equal,
43 greater_than,
44 greater_than_or_equal,
45 unequal,
46 equal,
48 logical_not,
50 logical_and,
51 logical_or,
53 shift_left,
54 shift_right,
56 binary_and,
57 binary_or,
58 binary_xor,
60 binary_not,
62 bracket_start,
63 bracket_start_call,
64 bracket_end,
66 array_start,
67 array_end,
69 scope_start,
70 scope_end,
72 iteration,
73 iterator,
75 function_declaration,
76 anonymous_function_declaration,
78 class_operator,
79 selection_operator,
80 call_operator,
81 scope_operator,
85 struct lexeme
87 lexeme_type::type type;
88 union
90 bool boolean;
91 types::signed_integer signed_integer;
92 types::unsigned_integer unsigned_integer;
93 types::floating_point_value floating_point_value;
94 std::string * string;
97 lexeme();
98 lexeme(lexeme_type::type type);
99 explicit lexeme(types::boolean boolean);
100 explicit lexeme(types::signed_integer signed_integer);
101 explicit lexeme(types::unsigned_integer unsigned_integer);
102 explicit lexeme(types::floating_point_value floating_point_value);
103 explicit lexeme(lexeme_type::type type, std::string const & string);
104 std::string to_string() const;
107 struct line_of_code
109 uword line;
110 uword indentation_level;
111 std::vector<lexeme> lexemes;
113 line_of_code();
116 struct operator_lexeme
118 lexeme_type::type lexeme;
119 std::string string;
121 operator_lexeme(lexeme_type::type lexeme, std::string const & string);
122 bool operator<(operator_lexeme const & other) const;
125 class lexer
127 public:
128 lexer(std::string const & input, std::vector<line_of_code> & lines, std::string & error);
130 bool parse();
132 private:
133 std::string const & input;
134 std::vector<line_of_code> & lines;
135 std::string & error;
137 uword line;
138 std::size_t
140 end,
141 line_offset;
142 line_of_code current_line;
143 bool is_call_bracket;
145 bool parse_operator(line_of_code & output);
146 bool parse_string(line_of_code & output, std::string & error_message, std::string error_prefix = "");
147 bool parse_number(line_of_code & output, bool & error_occured);
148 void parse_name(line_of_code & output);
149 bool parse_comment(std::string & error_message);
151 std::string lexer_error(std::string const & message, uword error_line = 0);
152 std::string number_parsing_error(std::string const & message, bool & error_occured);
154 bool is_name_char(char input);
155 bool string_match(std::string const & target);
156 void process_newline();
159 std::string visualise_lexemes(std::vector<line_of_code> & lines);
161 void initialise_tables();
163 extern boost::mutex table_mutex;
164 extern std::vector<operator_lexeme> operator_lexeme_data;