summaryrefslogtreecommitdiff
path: root/willow/tools/willowc/lib/parser.cpp
blob: e658909e2a97c2f46cdcf9102ee1a05a07b56154 (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
#include <parser.hpp>

namespace willowc {

std::optional<std::unique_ptr<ModuleAST>> Parser::run() {
  bool failed = false;
  while (true) {
    Token t = tokenizer_.scan();

    if (t.kind == TokenKind::Eof) {
      willow::emit(diagnostic_engine_, willow::Severity::Debug)
          << std::format("[ <eof> :: {} : ({}, {}) ]", t.kind, t.start, t.end);
      break;
    }
    willow::emit(diagnostic_engine_, willow::Severity::Debug)
        << std::format("[ '{}' :: {} : ({}, {}) ]",
                       tokenizer_.buf.substr(t.start, t.end - t.start), t.kind,
                       t.start, t.end);
  }
  return std::nullopt;
}

willow::DiagnosticBuilder Parser::emitParserError(Token t, willow::Severity severity) {
  willow::Location loc = file_.getLoc(t.start);
  return willow::DiagnosticBuilder(diagnostic_engine_, severity, loc);
}

} // namespace willowc