summaryrefslogtreecommitdiff
path: root/willow/tools/willowc/include/parser.hpp
blob: 59f6bfbd5574a0cb5079fea280d118c1ee9733e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef WILLOWC_INCLUDE_PARSER_HPP
#define WILLOWC_INCLUDE_PARSER_HPP

#include <ast.hpp>
#include <sourcemanager.hpp>
#include <tokenizer.hpp>

#include <willow/IR/DiagnosticEngine.h>

#include <memory>
#include <optional>
#include <vector>

namespace willowc {

class Parser {
public:
  Parser(SourceManager::File &f, willow::DiagnosticEngine &diagnostic_engine)
      : file_(f), tokenizer_(f.buf.get()),
        diagnostic_engine_(diagnostic_engine) {}

  std::optional<std::unique_ptr<ModuleAST>> run();

  TokenKind kind() const { return kinds_[pos_]; }
  std::size_t start() const { return starts_[pos_]; }

private:
  willow::DiagnosticBuilder emitParserError(Token t, willow::Severity severity);

  SourceManager::File &file_;
  std::vector<TokenKind> kinds_;
  std::vector<std::size_t> starts_;
  Tokenizer tokenizer_;
  std::size_t pos_;
  willow::DiagnosticEngine &diagnostic_engine_;

};

} // namespace willowc

#endif // WILLOWC_INCLUDE_PARSER_HPP