5#include <boost/container/small_vector.hpp>
20 :
Expr(NK_ExprInt, Range), Value(Value) {}
31 :
Expr(NK_ExprFloat, Range), Value(Value) {}
39 const std::shared_ptr<Expr> E;
43 :
Node(NK_Interpolation, Range), E(std::move(E)) {}
45 [[nodiscard]]
Expr *
expr()
const {
return E.get(); }
59 const std::string Escaped;
60 const std::shared_ptr<Interpolation> Interp;
64 : Kind(
SPK_Escaped), Escaped(std::move(Escaped)), Interp(nullptr) {}
68 assert(this->Interp &&
"interpolation must not be null");
73 [[nodiscard]]
const std::string &
escaped()
const {
80 assert(Interp &&
"interpolation must not be null");
86 const std::vector<InterpolablePart> Fragments;
90 std::vector<InterpolablePart> Fragments);
92 [[nodiscard]]
const std::vector<InterpolablePart> &
fragments()
const {
97 return Fragments.size() == 1 &&
101 [[nodiscard]]
const std::string &
literal()
const {
102 assert(
isLiteral() &&
"must be a literal");
103 return Fragments[0].escaped();
108 for (
const auto &Frag : Fragments) {
110 Children.emplace_back(&Frag.interpolation());
117 const std::shared_ptr<InterpolatedParts> Parts;
121 :
Expr(NK_ExprString, Range), Parts(std::move(Parts)) {
122 assert(this->Parts &&
"parts must not be null");
126 assert(Parts &&
"parts must not be null");
131 assert(Parts &&
"parts must not be null");
132 return Parts->isLiteral();
135 [[nodiscard]]
const std::string &
literal()
const {
136 assert(Parts &&
"parts must not be null");
137 return Parts->literal();
144 std::shared_ptr<InterpolatedParts> Parts;
148 :
Expr(NK_ExprPath, Range), Parts(std::move(Parts)) {
149 assert(this->Parts &&
"parts must not be null");
153 assert(Parts &&
"parts must not be null");
165 :
Expr(NK_ExprSPath, Range), Text(std::move(Text)) {}
169 [[nodiscard]]
const std::string &
text()
const {
return Text; }
173 const std::shared_ptr<Expr> E;
174 const std::shared_ptr<Misc> LParen;
175 const std::shared_ptr<Misc> RParen;
179 std::shared_ptr<Misc> LParen, std::shared_ptr<Misc> RParen)
180 :
Expr(NK_ExprParen, Range), E(std::move(E)), LParen(std::move(LParen)),
181 RParen(std::move(RParen)) {}
183 [[nodiscard]]
const Expr *
expr()
const {
return E.get(); }
184 [[nodiscard]]
const Misc *
lparen()
const {
return LParen.get(); }
185 [[nodiscard]]
const Misc *
rparen()
const {
return RParen.get(); }
188 return {E.get(), LParen.get(), RParen.get()};
193 const std::shared_ptr<Identifier> ID;
197 :
Expr(NK_ExprVar, Range), ID(std::move(ID)) {
198 assert(this->ID &&
"ID must not be null");
201 assert(ID &&
"ID must not be null");
ExprFloat(LexerCursorRange Range, NixFloat Value)
ChildVector children() const override
ChildVector children() const override
ExprInt(LexerCursorRange Range, NixInt Value)
const Expr * expr() const
const Misc * rparen() const
ChildVector children() const override
ExprParen(LexerCursorRange Range, std::shared_ptr< Expr > E, std::shared_ptr< Misc > LParen, std::shared_ptr< Misc > RParen)
const Misc * lparen() const
ChildVector children() const override
ExprPath(LexerCursorRange Range, std::shared_ptr< InterpolatedParts > Parts)
const InterpolatedParts & parts() const
ChildVector children() const override
const std::string & text() const
ExprSPath(LexerCursorRange Range, std::string Text)
ChildVector children() const override
const std::string & literal() const
const InterpolatedParts & parts() const
ExprString(LexerCursorRange Range, std::shared_ptr< InterpolatedParts > Parts)
ChildVector children() const override
const Identifier & id() const
ExprVar(LexerCursorRange Range, std::shared_ptr< Identifier > ID)
Identifier. Variable names, attribute names, etc.
InterpolablePart(std::string Escaped)
InterpolablePartKind kind() const
const std::string & escaped() const
InterpolablePart(std::shared_ptr< Interpolation > Interp)
Interpolation & interpolation() const
InterpolatedParts(LexerCursorRange Range, std::vector< InterpolablePart > Fragments)
ChildVector children() const override
const std::string & literal() const
const std::vector< InterpolablePart > & fragments() const
ChildVector children() const override
Interpolation(LexerCursorRange Range, std::shared_ptr< Expr > E)
Misc node, used for parentheses, keywords, etc.
boost::container::small_vector< Node *, 8 > ChildVector