30class Parser :
public fe::Parser<Tok, Tok::Tag, Look_Ahead, Parser> {
31 using Super = fe::Parser<Tok, Tok::Tag, Look_Ahead, Parser>;
40 return import({Loc(),
driver().sym(sv)},
nullptr, tag);
43 Ptr<Module> import(std::istream&, Loc = {},
const fs::path* =
nullptr, std::ostream* md =
nullptr);
49 template<
class T,
class... Args>
50 auto ptr(Args&&... args) {
51 return ast_.
ptr<
const T>(std::forward<Args>(args)...);
54 Dbg anon()
const {
return {ahead().loc().anew_begin(), ast_.
sym_anon()}; }
55 Dbg dbg(
const Tracker& tracker, Sym sym)
const {
return {tracker.loc(), sym}; }
56 Lexer& lexer() {
return *lexer_; }
61 Dbg parse_id(std::string_view ctxt = {});
62 std::pair<Annex&, bool> parse_annex(std::string_view ctxt = {});
63 Dbg parse_name(std::string_view ctxt = {});
66 Ptr<Expr> parse_type_ascr(std::string_view ctxt = {});
69 void parse_list(std::string ctxt,
Tok::Tag delim_l, F f,
Tok::Tag sep = Tok::Tag::T_comma) {
70 expect(delim_l, ctxt);
72 if (!ahead().isa(delim_r)) {
75 }
while (accept(sep) && !ahead().isa(delim_r));
77 expect(delim_r, std::string(
"closing delimiter of a ") + ctxt);
83 Ptr<Expr> parse_expr(std::string_view ctxt,
Prec = Prec::Bot);
84 Ptr<Expr> parse_primary_expr(std::string_view ctxt);
116 static bool is_paren_style(
int style) {
return (style & Style_Bit) == Paren_Style; }
117 static bool is_brket_style(
int style) {
return (style & Style_Bit) == Brckt_Style; }
118 static bool is_implicit(
int style) {
return (style & Implicit); }
119 Ptr<Ptrn> parse_ptrn(
int style, std::string_view ctxt,
Prec = Prec::Bot);
120 Ptr<Ptrn> parse_ptrn_(
int style, std::string_view ctxt,
Prec = Prec::Bot);
143 void syntax_err(std::string_view what,
const Tok& tok, std::string_view ctxt) {
144 ast().
error(tok.loc(),
"expected {}, got '{}' while parsing {}", what, tok, ctxt);
148 void syntax_err(std::string_view what, std::string_view ctxt) { syntax_err(what, ahead(), ctxt); }
150 void syntax_err(
Tok::Tag tag, std::string_view ctxt) {
151 std::string msg(
"'");
153 syntax_err(msg, ctxt);
157 template<
class... Args>
158 Tok expect(
Tok::Tag tag,
const char* f, Args&&... args) {
159 std::ostringstream oss;
160 print(oss, f, std::forward<Args>(args)...);
161 return Super::expect(tag, oss.str());
166 Lexer* lexer_ =
nullptr;