33class Parser :
public fe::Parser<Tok, Tok::Tag, Look_Ahead, Parser> {
37 , anonymous_(
world.sym(
"_"))
38 , return_(
world.sym(
"return")) {}
42 void import(std::string_view sv) {
return import(
driver().sym(sv)); }
43 void import(Sym, std::ostream* md =
nullptr);
44 void import(std::istream&,
const fs::path* =
nullptr, std::ostream* md =
nullptr);
50 Dbg dbg(
const Tracker& tracker, Sym sym)
const {
return {tracker.
loc(), sym}; }
51 Lexer& lexer() {
return *lexer_; }
56 Dbg parse_id(std::string_view ctxt = {});
57 std::pair<Annex&, bool> parse_annex(std::string_view ctxt = {});
58 std::pair<Dbg, bool> parse_name(std::string_view ctxt = {});
61 Ref parse_type_ascr(std::string_view ctxt = {});
62 void register_annex(Dbg, Ref);
64 template<
class F>
void parse_list(std::string ctxt,
Tok::Tag delim_l, F f,
Tok::Tag sep = Tok::Tag::T_comma) {
65 expect(delim_l, ctxt);
67 if (!ahead().isa(delim_r)) {
68 do {
f(); }
while (accept(sep) && !ahead().isa(delim_r));
70 expect(delim_r, std::string(
"closing delimiter of a ") + ctxt);
76 Ref parse_expr(std::string_view ctxt,
Tok::Prec = Tok::Prec::Bot);
77 Ref parse_primary_expr(std::string_view ctxt);
78 Ref parse_infix_expr(Tracker,
const Def* lhs,
Tok::Prec = Tok::Prec::Bot);
79 Ref parse_extract_expr(Tracker,
const Def*,
Tok::Prec);
85 Ref parse_pack_expr();
86 Ref parse_block_expr();
87 Ref parse_sigma_expr();
88 Ref parse_tuple_expr();
89 Ref parse_type_expr();
90 Pi* parse_pi_expr(Pi* =
nullptr);
92 Ref parse_insert_expr();
94 Lam* parse_lam(
bool decl =
false);
101 std::unique_ptr<Ptrn> parse_ptrn(
Tok::Tag tag, std::string_view ctxt,
Tok::Prec = Tok::Prec::Bot);
102 std::unique_ptr<TuplePtrn> parse_tuple_ptrn(Tracker,
bool rebind, Sym, Def* =
nullptr);
111 Ref parse_decls(std::string_view ctxt);
112 void parse_ax_decl();
113 void parse_let_decl();
114 void parse_sigma_decl();
115 void parse_pi_decl();
122 [[noreturn]]
void syntax_err(std::string_view what,
const Tok& tok, std::string_view ctxt) {
123 error(tok.loc(),
"expected {}, got '{}' while parsing {}", what, tok, ctxt);
127 [[noreturn]]
void syntax_err(std::string_view what, std::string_view ctxt) { syntax_err(what, ahead(), ctxt); }
129 [[noreturn]]
void syntax_err(
Tok::Tag tag, std::string_view ctxt) {
130 std::string msg(
"'");
132 syntax_err(msg, ctxt);
137 Lexer* lexer_ =
nullptr;