diff options
Diffstat (limited to 'willow/tools/willowc/include/parser.hpp')
| -rw-r--r-- | willow/tools/willowc/include/parser.hpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/willow/tools/willowc/include/parser.hpp b/willow/tools/willowc/include/parser.hpp index 825dfdd..59f6bfb 100644 --- a/willow/tools/willowc/include/parser.hpp +++ b/willow/tools/willowc/include/parser.hpp @@ -1,31 +1,39 @@ #ifndef WILLOWC_INCLUDE_PARSER_HPP #define WILLOWC_INCLUDE_PARSER_HPP -#include <tokenizer.hpp> #include <ast.hpp> +#include <sourcemanager.hpp> +#include <tokenizer.hpp> + +#include <willow/IR/DiagnosticEngine.h> -#include <optional> #include <memory> +#include <optional> #include <vector> namespace willowc { class Parser { - std::string_view buf; +public: + Parser(SourceManager::File &f, willow::DiagnosticEngine &diagnostic_engine) + : file_(f), tokenizer_(f.buf.get()), + diagnostic_engine_(diagnostic_engine) {} - std::vector<TokenKind> kinds; - std::vector<std::size_t> starts; - Tokenizer tokenizer; + std::optional<std::unique_ptr<ModuleAST>> run(); - std::size_t pos; + TokenKind kind() const { return kinds_[pos_]; } + std::size_t start() const { return starts_[pos_]; } -public: - Parser(std::string_view buf) : buf(buf), tokenizer(buf) {} +private: + willow::DiagnosticBuilder emitParserError(Token t, willow::Severity severity); - std::optional<std::unique_ptr<ModuleAST>> parse(); + SourceManager::File &file_; + std::vector<TokenKind> kinds_; + std::vector<std::size_t> starts_; + Tokenizer tokenizer_; + std::size_t pos_; + willow::DiagnosticEngine &diagnostic_engine_; - TokenKind kind() const { return kinds[pos]; } - std::size_t start() const { return starts[pos]; } }; } // namespace willowc |