30class Parser :
public fe::Parser<Tok, Tok::Tag, Look_Ahead, Parser> {
31 using Super = fe::Parser<Tok, Tok::Tag, Look_Ahead, Parser>;
41 Ptr<Module> import(std::istream&, Loc = {},
const fs::path* =
nullptr, std::ostream* md =
nullptr);
47 template<
class T,
class... Args>
auto ptr(Args&&... args) {
48 return ast_.
ptr<
const T>(std::forward<Args&&>(args)...);
51 Dbg anon()
const {
return {ahead().loc().anew_begin(), ast_.
sym_anon()}; }
52 Dbg dbg(
const Tracker& tracker, Sym sym)
const {
return {tracker.loc(), sym}; }
53 Lexer& lexer() {
return *lexer_; }
58 Dbg parse_id(std::string_view ctxt = {});
59 std::pair<Annex&, bool> parse_annex(std::string_view ctxt = {});
60 Dbg parse_name(std::string_view ctxt = {});
63 Ptr<Expr> parse_type_ascr(std::string_view ctxt = {});
65 template<
class F>
void parse_list(std::string ctxt,
Tok::Tag delim_l, F f,
Tok::Tag sep = Tok::Tag::T_comma) {
66 expect(delim_l, ctxt);
68 if (!ahead().isa(delim_r)) {
69 do {
f(); }
while (accept(sep) && !ahead().isa(delim_r));
71 expect(delim_r, std::string(
"closing delimiter of a ") + ctxt);
78 Ptr<Expr> parse_primary_expr(std::string_view ctxt);
84 template<
bool>
Ptr<Expr> parse_arr_or_pack_expr();
122 void syntax_err(std::string_view what,
const Tok& tok, std::string_view ctxt) {
123 ast().
error(tok.loc(),
"expected {}, got '{}' while parsing {}", what, tok, ctxt);
127 void syntax_err(std::string_view what, std::string_view ctxt) { syntax_err(what, ahead(), ctxt); }
129 void syntax_err(
Tok::Tag tag, std::string_view ctxt) {
130 std::string msg(
"'");
132 syntax_err(msg, ctxt);
136 template<
class... Args> Tok expect(
Tok::Tag tag,
const char* f, Args&&... args) {
137 std::ostringstream oss;
138 print(oss, f, std::forward<Args&&>(args)...);
139 return Super::expect(tag, oss.str());
144 Lexer* lexer_ =
nullptr;