-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The REPL itself and the `nix repl` CLI are conceptually different things, and thus deserve to be in different files.
- Loading branch information
1 parent
c9e52f8
commit 7a85980
Showing
9 changed files
with
220 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "util.hh" | ||
#include "editor-for.hh" | ||
|
||
namespace nix { | ||
|
||
Strings editorFor(const Path & file, uint32_t line) | ||
{ | ||
auto editor = getEnv("EDITOR").value_or("cat"); | ||
auto args = tokenizeString<Strings>(editor); | ||
if (line > 0 && ( | ||
editor.find("emacs") != std::string::npos || | ||
editor.find("nano") != std::string::npos || | ||
editor.find("vim") != std::string::npos || | ||
editor.find("kak") != std::string::npos)) | ||
args.push_back(fmt("+%d", line)); | ||
args.push_back(file); | ||
return args; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include "types.hh" | ||
|
||
namespace nix { | ||
|
||
/* Helper function to generate args that invoke $EDITOR on | ||
filename:lineno. */ | ||
Strings editorFor(const Path & file, uint32_t line); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#pragma once | ||
|
||
#include "eval.hh" | ||
|
||
#if HAVE_BOEHMGC | ||
#define GC_INCLUDE_NEW | ||
#include <gc/gc_cpp.h> | ||
#endif | ||
|
||
namespace nix { | ||
|
||
class NixRepl | ||
#if HAVE_BOEHMGC | ||
: public gc | ||
#endif | ||
{ | ||
std::string curDir; | ||
|
||
public: | ||
|
||
ref<EvalState> state; | ||
Bindings * autoArgs; | ||
|
||
private: | ||
|
||
size_t debugTraceIndex; | ||
|
||
Strings loadedFiles; | ||
|
||
public: | ||
|
||
typedef std::vector<std::pair<Value*, std::string>> AnnotatedValues; | ||
|
||
private: | ||
|
||
std::function<AnnotatedValues()> getValues; | ||
|
||
const static int envSize = 32768; | ||
std::shared_ptr<StaticEnv> staticEnv; | ||
Env * env; | ||
int displ; | ||
StringSet varNames; | ||
|
||
const Path historyFile; | ||
|
||
public: | ||
|
||
NixRepl(const Strings & searchPath, nix::ref<Store> store, ref<EvalState> state, | ||
std::function<AnnotatedValues()> getValues); | ||
~NixRepl(); | ||
|
||
static void runSimple( | ||
ref<EvalState> evalState, | ||
const ValMap & extraEnv); | ||
|
||
void initEnv(); | ||
|
||
void mainLoop(); | ||
|
||
StringSet completePrefix(const std::string & prefix); | ||
|
||
private: | ||
|
||
bool getLine(std::string & input, const std::string & prompt); | ||
StorePath getDerivationPath(Value & v); | ||
bool processLine(std::string line); | ||
|
||
void loadFile(const Path & path); | ||
void loadFlake(const std::string & flakeRef); | ||
void loadFiles(); | ||
void reloadFiles(); | ||
void addAttrsToScope(Value & attrs); | ||
void addVarToScope(const Symbol name, Value & v); | ||
Expr * parseString(std::string s); | ||
void evalString(std::string s, Value & v); | ||
void loadDebugTraceEnv(DebugTrace & dt); | ||
|
||
typedef std::set<Value *> ValuesSeen; | ||
std::ostream & printValue(std::ostream & str, Value & v, unsigned int maxDepth); | ||
std::ostream & printValue(std::ostream & str, Value & v, unsigned int maxDepth, ValuesSeen & seen); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.