snix/third_party/nix/src/libexpr/parser.hh
Vincent Ambo d579ceb783 refactor(3p/nix/libexpr): Extract parser header out of Yacc file
First step (of many?) towards extracting all the inline code from the
Yacc file and keeping it somewhere more accessible instead.

Note that none of this code has previously been touched by a linter or
formatter, pretty much ever, so as it is extracted it also undergoes
similar changes to the whole codebase after the initial fork.

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

47 lines
1.3 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)
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);
}
} // namespace nix