mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-14 02:06:16 +02:00
Print syntactially invalid attribute names as strings.
This commit is contained in:
parent
a52fd0dbd0
commit
97da6d62f2
1 changed files with 19 additions and 9 deletions
28
nix-repl.cc
28
nix-repl.cc
|
@ -472,6 +472,19 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::ostream & printStringValue(std::ostream & str, const char * string) {
|
||||||
|
str << "\"";
|
||||||
|
for (const char * i = string; *i; i++)
|
||||||
|
if (*i == '\"' || *i == '\\') str << "\\" << *i;
|
||||||
|
else if (*i == '\n') str << "\\n";
|
||||||
|
else if (*i == '\r') str << "\\r";
|
||||||
|
else if (*i == '\t') str << "\\t";
|
||||||
|
else str << *i;
|
||||||
|
str << "\"";
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// FIXME: lot of cut&paste from Nix's eval.cc.
|
// FIXME: lot of cut&paste from Nix's eval.cc.
|
||||||
std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int maxDepth, ValuesSeen & seen)
|
std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int maxDepth, ValuesSeen & seen)
|
||||||
{
|
{
|
||||||
|
@ -491,14 +504,7 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tString:
|
case tString:
|
||||||
str << "\"";
|
printStringValue(str, v.string.s);
|
||||||
for (const char * i = v.string.s; *i; i++)
|
|
||||||
if (*i == '\"' || *i == '\\') str << "\\" << *i;
|
|
||||||
else if (*i == '\n') str << "\\n";
|
|
||||||
else if (*i == '\r') str << "\\r";
|
|
||||||
else if (*i == '\t') str << "\\t";
|
|
||||||
else str << *i;
|
|
||||||
str << "\"";
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case tPath:
|
case tPath:
|
||||||
|
@ -546,7 +552,11 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto & i : sorted) {
|
for (auto & i : sorted) {
|
||||||
str << i.first << " = ";
|
if (isVarName(i.first))
|
||||||
|
str << i.first;
|
||||||
|
else
|
||||||
|
printStringValue(str, i.first.c_str());
|
||||||
|
str << " = ";
|
||||||
if (hidden.find(i.first) != hidden.end())
|
if (hidden.find(i.first) != hidden.end())
|
||||||
str << "«...»";
|
str << "«...»";
|
||||||
else if (seen.find(i.second) != seen.end())
|
else if (seen.find(i.second) != seen.end())
|
||||||
|
|
Loading…
Reference in a new issue