38#define CODE(name, ...) name,
46#define CODE(name, assoc) case Prec::name: return Assoc::assoc;
82 m(K_extern, "extern") \
91 m(K_import, "import") \
96 m(K_match, "match" ) \
97 m(K_module, "module") \
99 m(K_plugin, "plugin") \
106 m(K_where, "where" ) \
109#define CODE(t, str) + size_t(1)
114 m(EoF, "<end of file>" ) \
116 m(L_s, "<signed integer literal>") \
117 m(L_u, "<integer literal>" ) \
118 m(L_i, "<index literal>" ) \
119 m(L_f, "<floating-point literal>") \
120 m(L_c, "<char literal>" ) \
121 m(L_str, "<string literal>" ) \
123 m(M_id, "<identifier>" ) \
124 m(M_anx, "<annex name>" ) \
140 m(T_fat_arrow, "=>") \
152 m(T_semicolon, ";") \
157#define MIM_SUBST(m) \
161 m("insert", K_ins ) \
169#define CODE(t, str) t,
195 , u_(
std::bit_cast<uint64_t>(s)) {}
199 , u_(
std::bit_cast<uint64_t>(d)) {}
208 assert(
tag == Tag::M_id ||
tag == Tag::M_anx ||
tag == Tag::L_str);
214 Loc
loc()
const {
return loc_; }
215 explicit operator bool()
const {
return tag_ != Tag::Nil; }
218 char8_t lit_c()
const { assert(
isa(Tag::L_c));
return c_; }
219 uint64_t
lit_u()
const { assert(
isa(Tag::L_u ) ||
isa(Tag::L_s ) ||
isa(Tag::L_f ));
return u_; }
220 Sym
sym()
const { assert(
isa(Tag::M_anx) ||
isa(Tag::M_id) ||
isa(Tag::L_str));
return sym_; }
222 std::string
str()
const;
friend std::ostream & operator<<(std::ostream &, Tok)
const Lit * lit_i() const
Tok(Loc loc, Tag tag, Sym sym)
Tok(Loc loc, const Lit *i)
static constexpr Tok::Tag delim_l2r(Tag tag)
friend std::ostream & operator<<(std::ostream &os, Tok::Tag tag)
static const char * tag2str(Tok::Tag)
constexpr bool is_lassoc(Prec p)
Assoc
Associativity of an infix expression.
constexpr bool is_rassoc(Prec p)
constexpr bool should_reduce(Prec curr, Prec op)
Should a Pratt parser reduce when the current binding power is curr and the infix operator has preced...
constexpr Assoc prec_assoc(Prec p)
Associativity of precedence level p.
Prec
Expression precedences used by the parser and the dumper; ordered low to high.