Working on outphasing the options
value.
This commit is contained in:
parent
192575ded8
commit
7005a080c0
40
pretty.lua
40
pretty.lua
|
@ -301,25 +301,25 @@ local format_value
|
|||
|
||||
-- Ways to format keys
|
||||
|
||||
local function format_key_and_value_string_map (l, key, value, options, depth)
|
||||
local function format_key_and_value_string_map (l, key, value, _, depth)
|
||||
l[#l+1] = key
|
||||
l[#l+1] = { 'align', 'key', #key }
|
||||
l[#l+1] = ' = '
|
||||
return format_value(value, options, depth, l)
|
||||
return format_value(value, nil, depth, l)
|
||||
end
|
||||
|
||||
local function format_key_and_value_arbitr_map (l, key, value, options, depth)
|
||||
local function format_key_and_value_arbitr_map (l, key, value, _, depth)
|
||||
local index_before_key = #l+1
|
||||
l[#l+1] = '['
|
||||
format_value(key, options, math.huge, l)
|
||||
format_value(key, nil, math.huge, l)
|
||||
l[#l+1] = ']'
|
||||
l[#l+1] = { 'align', 'key', width_of_strings_in_l(l, index_before_key) }
|
||||
l[#l+1] = ' = '
|
||||
return format_value(value, options, depth, l)
|
||||
return format_value(value, nil, depth, l)
|
||||
end
|
||||
|
||||
local function format_key_and_value_sequence (l, key, value, options, depth)
|
||||
return format_value(value, options, depth, l)
|
||||
local function format_key_and_value_sequence (l, key, value, _, depth)
|
||||
return format_value(value, nil, depth, l)
|
||||
end
|
||||
|
||||
local TABLE_TYPE_TO_PAIR_FORMAT = {
|
||||
|
@ -333,18 +333,18 @@ local TABLE_TYPE_TO_PAIR_FORMAT = {
|
|||
|
||||
-- Formatting tables
|
||||
|
||||
function format_table (t, options, depth, l)
|
||||
function format_table (t, _, depth, l)
|
||||
-- Error Checking
|
||||
-- TODO: Add more nuanced formatting.
|
||||
|
||||
assert(type(t) == 'table')
|
||||
assert(type(options) == 'table' and type(depth) == 'number' and type(l) == 'table')
|
||||
assert(type(depth) == 'number' and type(l) == 'table')
|
||||
|
||||
-- Do stuff
|
||||
|
||||
local table_info = l.info[t] or get_table_info(t)
|
||||
|
||||
if options.recursion == 'marked' and table_info.marker then
|
||||
if l.options.recursion == 'marked' and table_info.marker then
|
||||
l[#l+1], l[#l+2], l[#l+3] = '<', table_info.marker, '>'
|
||||
end
|
||||
|
||||
|
@ -354,7 +354,7 @@ function format_table (t, options, depth, l)
|
|||
if table_info.type == TABLE_TYPE.EMPTY then
|
||||
-- Empty Map
|
||||
return l '{}'
|
||||
elseif depth >= options.max_depth or already_visited then
|
||||
elseif depth >= l.options.max_depth or already_visited then
|
||||
-- Already visited or above max depth
|
||||
return l '{...}'
|
||||
end
|
||||
|
@ -373,7 +373,7 @@ function format_table (t, options, depth, l)
|
|||
-- Begin formatting table.
|
||||
l[#l+1] = {'indent', '{'}
|
||||
for _, pair in ipairs(key_value_pairs) do
|
||||
pair_format_func(l, pair[1], pair[2], options, depth + 1)
|
||||
pair_format_func(l, pair[1], pair[2], nil, depth + 1)
|
||||
l[#l+1] = ','
|
||||
l[#l+1] = {'seperator'}
|
||||
end
|
||||
|
@ -394,12 +394,12 @@ end
|
|||
|
||||
-- Formatting Strings
|
||||
|
||||
local function format_string (str, options, depth, l)
|
||||
local function format_string (str, _, depth, l)
|
||||
-- TODO: Add option for escaping unicode characters.
|
||||
|
||||
-- Error checking
|
||||
assert( type(str) == 'string' )
|
||||
assert(type(options) == 'table' and type(depth) == 'number' and type(l) == 'table')
|
||||
assert(type(depth) == 'number' and type(l) == 'table')
|
||||
|
||||
-- Do work
|
||||
|
||||
|
@ -410,8 +410,8 @@ local function format_string (str, options, depth, l)
|
|||
|
||||
-- ...
|
||||
local chance_of_longform = is_long_string and ((newline_or_tab_index or math.huge) <= NR_CHARS_IN_LONG_STRING) or double_quote_index and single_quote_index
|
||||
local cut_string_index = options.cut_strings and (is_long_string or chance_of_longform)
|
||||
and math.min(NR_CHARS_IN_LONG_STRING - 3, newline_or_tab_index or 1/0, double_quote_index or 1/0, single_quote_index or 1/0)
|
||||
local cut_string_index = l.options.cut_strings and (is_long_string or chance_of_longform)
|
||||
and math.min(NR_CHARS_IN_LONG_STRING - 3, newline_or_tab_index or 1/0, double_quote_index or 1/0, single_quote_index or 1/0)
|
||||
|
||||
local longform = chance_of_longform and ((not cut_string_index) or cut_string_index < math.min(newline_or_tab_index or 1/0, double_quote_index or 1/0, single_quote_index or 1/0))
|
||||
|
||||
|
@ -440,13 +440,13 @@ local function format_string (str, options, depth, l)
|
|||
l[#l+1] = right
|
||||
end
|
||||
|
||||
local function format_coroutine (value, options, depth, l)
|
||||
local function format_coroutine (value, _, depth, l)
|
||||
l[#l+1] = coroutine.status(value)
|
||||
l[#l+1] = ' coroutine: '
|
||||
l[#l+1] = tostring(value):sub(9)
|
||||
end
|
||||
|
||||
local function format_primitive (value, options, depth, l)
|
||||
local function format_primitive (value, _, depth, l)
|
||||
l[#l+1] = tostring(value)
|
||||
end
|
||||
|
||||
|
@ -464,9 +464,11 @@ local TYPE_TO_FORMAT_FUNC = {
|
|||
}
|
||||
|
||||
function format_value (value, _, depth, l)
|
||||
assert(type(depth) == 'number' and type(l) == 'table')
|
||||
if _ ~= nil then print('Ugh: ' .. tostring(_)) end
|
||||
local formatting = TYPE_TO_FORMAT_FUNC[type(value)]
|
||||
if formatting then
|
||||
formatting(value, l.options, depth, l, format_value)
|
||||
formatting(value, nil, depth, l, format_value)
|
||||
else
|
||||
error(ERROR_UNKNOWN_TYPE:format(type(value), tostring(value)), 2)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user