diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-02-23T10·07+0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2016-02-23T10·07+0100 |
commit | 5599665a270128361862774701ae41fbfba5a661 (patch) | |
tree | 82b35cec2ec9f0a729b2e17c0b70e9767dabb944 | |
parent | a52fd0dbd0200ba165d1da8a4bf2bc36a455a0d1 (diff) | |
parent | 97da6d62f2a1580dfdae9575c92418d5f45a29af (diff) |
Merge pull request #22 from tsion/quote-invalid-vars
Print syntactially invalid attribute names as strings.
-rw-r--r-- | nix-repl.cc | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/nix-repl.cc b/nix-repl.cc index f4850271dc6a..577efa8e2ba5 100644 --- a/nix-repl.cc +++ b/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. 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; case tString: - str << "\""; - 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 << "\""; + printStringValue(str, v.string.s); break; case tPath: @@ -546,7 +552,11 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m } 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()) str << "«...»"; else if (seen.find(i.second) != seen.end()) |