5#include <boost/container/small_vector.hpp>
15#define NODE(NAME) NK_##NAME,
19#define EXPR(NAME) NK_##NAME,
27 LexerCursorRange Range;
31 : Kind(Kind), Range(Range) {}
40 [[nodiscard]]
const char *
name()
const {
return name(Kind); }
42 using ChildVector = boost::container::small_vector<Node *, 8>;
53 for (
const auto &Child :
children()) {
56 if (Child->positionRange().contains(Range)) {
57 return Child->descend(Range);
63 [[nodiscard]] std::string_view
src(std::string_view Src)
const {
66 return Src.substr(Begin, Length);
88 case Node::NK_ExprInt:
89 case Node::NK_ExprFloat:
90 case Node::NK_ExprAttrs:
91 case Node::NK_ExprString:
92 case Node::NK_ExprPath:
115 const std::string Name;
119 :
Node(NK_Identifier, Range), Name(std::move(Name)) {}
120 [[nodiscard]]
const std::string &
name()
const {
return Name; }
132 :
Node(NK_Dot, Range), Prev(Prev), Next(Next) {
142 [[nodiscard]]
const Node *
next()
const {
return Next; }
Holds a "." in the language.
ChildVector children() const override
const Node & prev() const
Dot(LexerCursorRange Range, const Node *Prev, const Node *Next)
const Node * next() const
Expr(NodeKind Kind, LexerCursorRange Range)
static bool classof(const Node *N)
static bool isExpr(NodeKind Kind)
static bool maybeLambda(NodeKind Kind)
Identifier. Variable names, attribute names, etc.
const std::string & name() const
Identifier(LexerCursorRange Range, std::string Name)
ChildVector children() const override
A point in the source file.
std::size_t offset() const
Offset in the source file, starting from 0.
Misc node, used for parentheses, keywords, etc.
Misc(LexerCursorRange Range)
ChildVector children() const override
const Node * descend(PositionRange Range) const
Descendant node that contains the given range.
const char * name() const
@ NK_EndExpr
provides NODE(NAME) EXPR(NAME)
@ NK_BeginExpr
provides NODE(NAME) EXPR(NAME)
std::string_view src(std::string_view Src) const
boost::container::small_vector< Node *, 8 > ChildVector
PositionRange positionRange() const
LexerCursorRange range() const
Node(NodeKind Kind, LexerCursorRange Range)
virtual ChildVector children() const =0