33std::pair<unsigned, unsigned> getBP(
TokenKind Kind) {
35 case tok_op_pipe_from:
37 case tok_op_pipe_into:
66 __builtin_unreachable();
77 __builtin_unreachable();
83std::shared_ptr<Expr> Parser::parseExprOpBP(
unsigned LeftRBP) {
84 std::shared_ptr<Expr> Prefix;
90 assert(LastToken &&
"consume() should have set LastToken");
91 auto O = std::make_shared<Op>(Tok.range(), Tok.kind());
92 auto Expr = parseExprOpBP(getUnaryBP(Tok.kind()));
98 std::move(O), std::move(
Expr));
109 switch (
Token Tok = peek(); Tok.
kind()) {
110#define TOK_BIN_OP(NAME) case tok_op_##NAME:
120 auto [LBP, RBP] = getBP(Tok.kind());
123 if (LeftRBP == LBP) {
125 Diags.emplace_back(Diagnostic::DK_OperatorNotAssociative,
129 assert(LastToken &&
"consume() should have set LastToken");
130 auto O = std::make_shared<Op>(Tok.range(), Tok.kind());
131 auto RHS = parseExprOpBP(RBP);
133 diagNullExpr(Diags, LastToken->rCur(),
"binary op RHS");
137 Prefix = std::make_shared<ExprBinOp>(Range, std::move(O),
138 std::move(Prefix), std::move(RHS));
144 assert(LastToken &&
"consume() should have set LastToken");
145 auto O = std::make_shared<Op>(Tok.range(), Tok.kind());
149 Prefix = std::make_shared<ExprOpHasAttr>(
150 Range, std::move(O), std::move(Prefix), std::move(Path));
A point in the source file.
std::shared_ptr< Expr > parseExprApp(int Limit=INT_MAX)
std::shared_ptr< AttrPath > parseAttrPath()
A token. With it's kind, and the range in source code.
tok::TokenKind kind() const
Diagnostic & diagNullExpr(std::vector< Diagnostic > &Diags, LexerCursor Loc, std::string As)
constexpr std::string_view spelling(TokenKind Kind)
Parser for the Nix expression language.