Line data Source code
1 : #ifndef LEXER_H
2 : #define LEXER_H
3 :
4 : #include <filesystem>
5 : #include <vector>
6 :
7 : #include "category.h"
8 : #include "tokenStream.h"
9 :
10 : namespace nicole {
11 :
12 : // Lexer that tokenize an input file
13 : class Lexer final {
14 : private:
15 : std::vector<Category> categories_;
16 :
17 : std::string extension_;
18 :
19 : // makes a category that matches with every token of our sintax
20 : [[nodiscard]] const Category concatCategories() const noexcept;
21 :
22 : [[nodiscard]] const std::expected<std::string, Error>
23 : readFile(const std::filesystem::path &fileName) const noexcept;
24 :
25 : [[nodiscard]] const std::expected<void, Error>
26 : checkUnmatched(const std::vector<Token> &tokens) const noexcept;
27 :
28 : public:
29 : explicit Lexer(const std::vector<Category> &categories,
30 : const std::string &extension) noexcept
31 18 : : categories_{categories}, extension_{extension} {};
32 :
33 18 : [[nodiscard]] const std::vector<Category> &categories() const noexcept {
34 18 : return categories_;
35 18 : }
36 :
37 : [[nodiscard]] const std::expected<TokenStream, Error>
38 : analyze(const std::filesystem::path &fileName,
39 : bool verbose = false) const noexcept;
40 : };
41 :
42 : } // namespace nicole
43 :
44 : #endif
|