Still working on the dreaded lexer
[fridhskrift.git] / frith / lexer.hpp
blob6e9136bbce130ef6bc351e1c591a4bc8f3f5e6e9
1 #pragma once
3 #include <string>
4 #include <vector>
5 #include <ail/types.hpp>
6 #include <frith/variable.hpp>
8 namespace frith
10 enum lexeme_type
12 lexeme_type_name,
14 lexeme_type_signed_integer,
15 lexeme_type_unsigned_integer,
16 lexeme_type_floating_point_value,
17 lexeme_type_string,
19 lexeme_type_addition,
20 lexeme_type_subtraction,
21 lexeme_type_multiplication,
22 lexeme_type_division,
23 lexeme_type_modulo,
25 lexeme_type_less_than,
26 lexeme_type_less_than_or_equal,
27 lexeme_type_greater_than,
28 lexeme_type_greater_than_or_equal,
29 lexeme_type_unequal,
30 lexeme_type_equal,
32 lexeme_type_logical_not,
34 lexeme_type_logical_and,
35 lexeme_type_logical_or,
37 lexeme_type_shift_left,
38 lexeme_type_shift_right,
40 lexeme_type_binary_and,
41 lexeme_type_binary_or,
42 lexeme_type_binary_xor,
44 lexeme_type_binary_not,
46 lexeme_type_bracket_left,
47 lexeme_type_bracket_right,
49 lexeme_type_array_left,
50 lexeme_type_array_right,
53 struct lexeme
55 lexeme_type type;
56 union
58 types::signed_integer signed_integer;
59 types::unsigned_integer unsigned_integer;
60 types::floating_point_value floating_point_value;
61 std::string * string;
64 lexeme();
65 lexeme(lexeme_type type);
66 explicit lexeme(types::signed_integer signed_integer);
67 explicit lexeme(types::unsigned_integer unsigned_integer);
68 explicit lexeme(types::floating_point_value floating_point_value);
69 explicit lexeme(lexeme_type type, std::string const & string);
72 struct line_of_code
74 uword line;
75 uword indentation_level;
76 std::vector<lexeme> lexemes;
78 line_of_code();
81 struct operator_lexeme
83 lexeme_type lexeme;
84 std::string string;
86 operator_lexeme(lexeme_type lexeme, std::string const & string);
87 bool operator<(operator_lexeme const & other) const;
90 bool parse_lexemes(std::string const & input, std::vector<line_of_code> & lines, std::string & error);