tvl-depot/third_party/nix/src/libexpr/parser.hh
Vincent Ambo e05eb20102 refactor(3p/nix/libexpr): Move EvalState:* implementations out of parser.y
Several definitions of functions declared in eval.hh were previously
implemented in parser.y, this moves them over to parser.cc.

While this still isn't a reasonable place to keep them, the long-term
fix is more likely to be that eval.hh needs to be split up.

Before we get to that point however, this already gives us the ability
to use tooling with this code.

Change-Id: If06fb655325fe281564047ffab0a0a640428a0ee
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1219
Tested-by: BuildkiteCI
Reviewed-by: isomer <isomer@tvl.fyi>
2020-07-16 19:53:51 +00:00

58 lines
1.6 KiB
C++

// Parser utilities for use in parser.y
#pragma once
// TODO(tazjin): Audit these includes, they were in parser.y
#include <optional>
#include <variant>
#include <glog/logging.h>
#include "libexpr/eval.hh"
#include "libexpr/nixexpr.hh"
#include "libutil/util.hh"
#define YY_DECL \
int yylex(YYSTYPE* yylval_param, YYLTYPE* yylloc_param, yyscan_t yyscanner, \
nix::ParseData* data)
#define CUR_POS makeCurPos(*yylocp, data)
namespace nix {
struct ParseData {
EvalState& state;
SymbolTable& symbols;
Expr* result;
Path basePath;
std::optional<Symbol> path;
std::string error;
Symbol sLetBody;
ParseData(EvalState& state)
: state(state),
symbols(state.symbols),
sLetBody(symbols.Create("<let-body>")){};
};
// TODO(tazjin): move dupAttr to anonymous namespace
static void dupAttr(const AttrPath& attrPath, const Pos& pos,
const Pos& prevPos) {
throw ParseError(format("attribute '%1%' at %2% already defined at %3%") %
showAttrPath(attrPath) % pos % prevPos);
}
static void dupAttr(Symbol attr, const Pos& pos, const Pos& prevPos) {
throw ParseError(format("attribute '%1%' at %2% already defined at %3%") %
attr % pos % prevPos);
}
void addAttr(ExprAttrs* attrs, AttrPath& attrPath, Expr* e, const Pos& pos);
void addFormal(const Pos& pos, Formals* formals, const Formal& formal);
Expr* stripIndentation(const Pos& pos, SymbolTable& symbols,
std::vector<Expr*>& es);
Path resolveExprPath(Path path);
} // namespace nix