Skip to content

Commit d2f44a9

Browse files
committed
Format Str as 'Str "value"' and Space as 'Space'
Previously, Str was formatted as 'Str text: "value"' but that was inconsistent because it should really have been 'Str {text: "value"}'. Given the widespread usage of Str, and the fact that its constructor can be given a string, it makes sense to hide the 'text' attribute name. The same logic would also apply to other types with single 'text' attributes. Similarly, Space was formatted as 'Space {}' but it's so common that it makes sense to omit its empty contents.
1 parent 9da9863 commit d2f44a9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

logging.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,13 @@ local function dump_(prefix, value, maxlen, level, add)
104104
end
105105
end
106106
if numKeys == 0 then
107-
-- this (for example) avoids a newline in 'Space {}'
108-
-- XXX this wouldn't be needed with proper maxlen handling
109-
value = '{}'
110-
elseif numKeys == 1 and lastKey == 'text' and typename == 'Str' then
111-
-- this allows strings to be formatted on a single line
107+
-- this allows empty tables to be formatted on a single line
108+
value = typename == 'Space' and '' or '{}'
109+
elseif numKeys == 1 and lastKey == 'text' then
110+
-- this allows text-only types to be formatted on a single line
111+
typ = typename
112+
value = value[lastKey]
112113
typename = 'string'
113-
typ = 'Str text:'
114-
value = value.text
115114
end
116115
end
117116

@@ -122,6 +121,7 @@ local function dump_(prefix, value, maxlen, level, add)
122121
if valtyp == 'nil' then
123122
add('nil')
124123
elseif ({boolean=1, number=1, string=1})[valtyp] then
124+
typsep = #typ > 0 and valtyp == 'string' and #value > 0 and ' ' or ''
125125
local fmt = typename == 'string' and '%q' or '%s'
126126
add(string.format('%s%s%s%s%s' .. fmt, indent, prefix, presep,
127127
typ, typsep, value))

0 commit comments

Comments
 (0)