summaryrefslogtreecommitdiff
path: root/willow/tools/willowc/include/parser.hpp
diff options
context:
space:
mode:
authorStefan Weigl-Bosker <stefan@s00.xyz>2026-02-23 22:18:22 -0500
committerGitHub <noreply@github.com>2026-02-23 22:18:22 -0500
commit8f98dc579af1993ec85bd849656c4835b4039dd6 (patch)
tree3ee45620d83b209c1c11248afc9ab83ffcf39691 /willow/tools/willowc/include/parser.hpp
parentc2d4209f85f46cc91163bc47cc43db252c94acf6 (diff)
downloadcompiler-8f98dc579af1993ec85bd849656c4835b4039dd6.tar.gz
[willow]: frontend plumbing (#13)
...
Diffstat (limited to 'willow/tools/willowc/include/parser.hpp')
-rw-r--r--willow/tools/willowc/include/parser.hpp32
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