diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2023-06-21 16:06:16 -0400 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2023-06-27 09:11:42 -0400 |
commit | e8067daf0955c297f389c968dab3e927b395de07 (patch) | |
tree | c9c833228aa9fbb8ca25a166cd5a7f0e4691176b /src/libexpr | |
parent | 559fd7ffe7a8cb61b11bec081f14ce3c3ffb210d (diff) |
Generialize `showType`
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/eval.cc | 23 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 5 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 71fd6e6e4..8a0ff4cce 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -211,20 +211,21 @@ const Value * getPrimOp(const Value &v) { return primOp; } -std::string_view showType(ValueType type) +std::string_view showType(ValueType type, bool withArticle) { + #define WA(a, w) withArticle ? a " " w : w switch (type) { - case nInt: return "an integer"; - case nBool: return "a Boolean"; - case nString: return "a string"; - case nPath: return "a path"; + case nInt: return WA("an", "integer"); + case nBool: return WA("a", "Boolean"); + case nString: return WA("a", "string"); + case nPath: return WA("a", "path"); case nNull: return "null"; - case nAttrs: return "a set"; - case nList: return "a list"; - case nFunction: return "a function"; - case nExternal: return "an external value"; - case nFloat: return "a float"; - case nThunk: return "a thunk"; + case nAttrs: return WA("a", "set"); + case nList: return WA("a", "list"); + case nFunction: return WA("a", "function"); + case nExternal: return WA("an", "external value"); + case nFloat: return WA("a", "float"); + case nThunk: return WA("a", "thunk"); } abort(); } diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 7b726a78f..0c07ae081 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -704,8 +704,11 @@ struct DebugTraceStacker { /** * @return A string representing the type of the value `v`. + * + * @param withArticle Whether to begin with an english article, e.g. "an + * integer" vs "integer". */ -std::string_view showType(ValueType type); +std::string_view showType(ValueType type, bool withArticle = true); std::string showType(const Value & v); /** |