aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/generators
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/generators')
-rw-r--r--src/nvim/generators/c_grammar.lua12
-rw-r--r--src/nvim/generators/gen_api_dispatch.lua52
-rw-r--r--src/nvim/generators/gen_api_ui_events.lua15
-rw-r--r--src/nvim/generators/gen_declarations.lua28
-rw-r--r--src/nvim/generators/gen_eval.lua1
-rw-r--r--src/nvim/generators/gen_options.lua2
-rw-r--r--src/nvim/generators/gen_options_enum.lua2
-rw-r--r--src/nvim/generators/gen_unicode_tables.lua323
-rw-r--r--src/nvim/generators/gen_vimvim.lua7
-rw-r--r--src/nvim/generators/hashy.lua22
10 files changed, 91 insertions, 373 deletions
diff --git a/src/nvim/generators/c_grammar.lua b/src/nvim/generators/c_grammar.lua
index 9ce9f3d7a6..ed6e30ea10 100644
--- a/src/nvim/generators/c_grammar.lua
+++ b/src/nvim/generators/c_grammar.lua
@@ -35,11 +35,7 @@ local cdoc_comment = P('///') * opt(Ct(Cg(rep(space) * rep(not_nl), 'comment')))
local c_preproc = P('#') * rep(not_nl)
local dllexport = P('DLLEXPORT') * rep1(ws)
-local typed_container = (
- (P('ArrayOf(') + P('DictionaryOf(') + P('Dict('))
- * rep1(any - P(')'))
- * P(')')
-)
+local typed_container = ((P('ArrayOf(') + P('DictOf(') + P('Dict(')) * rep1(any - P(')')) * P(')'))
local c_id = (typed_container + (letter * rep(alpha)))
local c_void = P('void')
@@ -91,7 +87,9 @@ local c_proto = Ct(
* (P(';') + (P('{') * nl + (impl_line ^ 0) * P('}')))
)
-local c_field = Ct(Cg(c_id, 'type') * ws * Cg(c_id, 'name') * fill * P(';') * fill)
+local dict_key = P('DictKey(') * Cg(rep1(any - P(')')), 'dict_key') * P(')')
+local keyset_field =
+ Ct(Cg(c_id, 'type') * ws * Cg(c_id, 'name') * fill * (dict_key ^ -1) * fill * P(';') * fill)
local c_keyset = Ct(
P('typedef')
* ws
@@ -99,7 +97,7 @@ local c_keyset = Ct(
* fill
* P('{')
* fill
- * Cg(Ct(c_field ^ 1), 'fields')
+ * Cg(Ct(keyset_field ^ 1), 'fields')
* P('}')
* fill
* P('Dict')
diff --git a/src/nvim/generators/gen_api_dispatch.lua b/src/nvim/generators/gen_api_dispatch.lua
index 62c99ce082..9e0aa407a1 100644
--- a/src/nvim/generators/gen_api_dispatch.lua
+++ b/src/nvim/generators/gen_api_dispatch.lua
@@ -72,14 +72,19 @@ local keysets = {}
local function add_keyset(val)
local keys = {}
local types = {}
+ local c_names = {}
local is_set_name = 'is_set__' .. val.keyset_name .. '_'
local has_optional = false
for i, field in ipairs(val.fields) do
+ local dict_key = field.dict_key or field.name
if field.type ~= 'Object' then
- types[field.name] = field.type
+ types[dict_key] = field.type
end
if field.name ~= is_set_name and field.type ~= 'OptionalKeys' then
- table.insert(keys, field.name)
+ table.insert(keys, dict_key)
+ if dict_key ~= field.name then
+ c_names[dict_key] = field.name
+ end
else
if i > 1 then
error("'is_set__{type}_' must be first if present")
@@ -94,6 +99,7 @@ local function add_keyset(val)
table.insert(keysets, {
name = val.keyset_name,
keys = keys,
+ c_names = c_names,
types = types,
has_optional = has_optional,
})
@@ -210,15 +216,15 @@ for _, f in ipairs(functions) do
end
f_exported.parameters = {}
for i, param in ipairs(f.parameters) do
- if param[1] == 'DictionaryOf(LuaRef)' then
- param = { 'Dictionary', param[2] }
+ if param[1] == 'DictOf(LuaRef)' then
+ param = { 'Dict', param[2] }
elseif startswith(param[1], 'Dict(') then
- param = { 'Dictionary', param[2] }
+ param = { 'Dict', param[2] }
end
f_exported.parameters[i] = param
end
if startswith(f.return_type, 'Dict(') then
- f_exported.return_type = 'Dictionary'
+ f_exported.return_type = 'Dict'
end
exported_functions[#exported_functions + 1] = f_exported
end
@@ -306,6 +312,7 @@ local keysets_defs = assert(io.open(keysets_outputf, 'wb'))
-- so that the dispatcher can find the C functions that you are creating!
-- ===========================================================================
output:write([[
+#include "nvim/errors.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
#include "nvim/globals.h"
@@ -331,19 +338,6 @@ output:write([[
keysets_defs:write('// IWYU pragma: private, include "nvim/api/private/dispatch.h"\n\n')
for _, k in ipairs(keysets) do
- local c_name = {}
-
- for i = 1, #k.keys do
- -- some keys, like "register" are c keywords and get
- -- escaped with a trailing _ in the struct.
- if vim.endswith(k.keys[i], '_') then
- local orig = k.keys[i]
- k.keys[i] = string.sub(k.keys[i], 1, #k.keys[i] - 1)
- c_name[k.keys[i]] = orig
- k.types[k.keys[i]] = k.types[orig]
- end
- end
-
local neworder, hashfun = hashy.hashy_hash(k.name, k.keys, function(idx)
return k.name .. '_table[' .. idx .. '].str'
end)
@@ -353,6 +347,8 @@ for _, k in ipairs(keysets) do
local function typename(type)
if type == 'HLGroupID' then
return 'kObjectTypeInteger'
+ elseif type == 'StringArray' then
+ return 'kUnpackTypeStringArray'
elseif type ~= nil then
return 'kObjectType' .. type
else
@@ -373,7 +369,7 @@ for _, k in ipairs(keysets) do
.. '", offsetof(KeyDict_'
.. k.name
.. ', '
- .. (c_name[key] or key)
+ .. (k.c_names[key] or key)
.. '), '
.. typename(k.types[key])
.. ', '
@@ -410,7 +406,7 @@ local function real_type(type)
if rv:match('Array') then
rv = 'Array'
else
- rv = 'Dictionary'
+ rv = 'Dict'
end
end
return rv
@@ -470,7 +466,7 @@ for i = 1, #functions do
output:write('\n ' .. converted .. ' = args.items[' .. (j - 1) .. '];\n')
elseif rt:match('^KeyDict_') then
converted = '&' .. converted
- output:write('\n if (args.items[' .. (j - 1) .. '].type == kObjectTypeDictionary) {') --luacheck: ignore 631
+ output:write('\n if (args.items[' .. (j - 1) .. '].type == kObjectTypeDict) {') --luacheck: ignore 631
output:write('\n memset(' .. converted .. ', 0, sizeof(*' .. converted .. '));') -- TODO: neeeee
output:write(
'\n if (!api_dict_to_keydict('
@@ -479,7 +475,7 @@ for i = 1, #functions do
.. rt
.. '_get_field, args.items['
.. (j - 1)
- .. '].data.dictionary, error)) {'
+ .. '].data.dict, error)) {'
)
output:write('\n goto cleanup;')
output:write('\n }')
@@ -558,7 +554,7 @@ for i = 1, #functions do
)
end
-- accept empty lua tables as empty dictionaries
- if rt:match('^Dictionary') then
+ if rt:match('^Dict') then
output:write(
'\n } else if (args.items['
.. (j - 1)
@@ -566,7 +562,7 @@ for i = 1, #functions do
.. (j - 1)
.. '].data.array.size == 0) {'
) --luacheck: ignore 631
- output:write('\n ' .. converted .. ' = (Dictionary)ARRAY_DICT_INIT;')
+ output:write('\n ' .. converted .. ' = (Dict)ARRAY_DICT_INIT;')
end
output:write('\n } else {')
output:write(
@@ -647,7 +643,7 @@ for i = 1, #functions do
if string.match(ret_type, '^KeyDict_') then
local table = string.sub(ret_type, 9) .. '_table'
output:write(
- '\n ret = DICTIONARY_OBJ(api_keydict_to_dict(&rv, '
+ '\n ret = DICT_OBJ(api_keydict_to_dict(&rv, '
.. table
.. ', ARRAY_SIZE('
.. table
@@ -783,12 +779,12 @@ local function process_function(fn)
local param = fn.parameters[j]
local cparam = string.format('arg%u', j)
local param_type = real_type(param[1])
- local extra = param_type == 'Dictionary' and 'false, ' or ''
+ local extra = param_type == 'Dict' and 'false, ' or ''
local arg_free_code = ''
if param[1] == 'Object' then
extra = 'true, '
arg_free_code = 'api_luarefs_free_object(' .. cparam .. ');'
- elseif param[1] == 'DictionaryOf(LuaRef)' then
+ elseif param[1] == 'DictOf(LuaRef)' then
extra = 'true, '
arg_free_code = 'api_luarefs_free_dict(' .. cparam .. ');'
elseif param[1] == 'LuaRef' then
diff --git a/src/nvim/generators/gen_api_ui_events.lua b/src/nvim/generators/gen_api_ui_events.lua
index 516b5ad5ae..3e8ae19c9a 100644
--- a/src/nvim/generators/gen_api_ui_events.lua
+++ b/src/nvim/generators/gen_api_ui_events.lua
@@ -54,7 +54,7 @@ local function call_ui_event_method(output, ev)
local kind = ev.parameters[j][1]
if kind ~= 'Object' then
if kind == 'HlAttrs' then
- kind = 'Dictionary'
+ kind = 'Dict'
end
output:write('\n || args.items[' .. (j - 1) .. '].type != kObjectType' .. kind .. '')
end
@@ -74,7 +74,7 @@ local function call_ui_event_method(output, ev)
output:write(
'ui_client_dict2hlattrs(args.items['
.. (j - 1)
- .. '].data.dictionary, '
+ .. '].data.dict, '
.. (hlattrs_args_count == 0 and 'true' or 'false')
.. ');\n'
)
@@ -128,8 +128,16 @@ for i = 1, #events do
write_signature(call_output, ev, '')
call_output:write('\n{\n')
if ev.remote_only then
+ -- Lua callbacks may emit other events or the same event again. Avoid the latter
+ -- by adding a recursion guard to each generated function that may call a Lua callback.
+ call_output:write(' static bool entered = false;\n')
+ call_output:write(' if (entered) {\n')
+ call_output:write(' return;\n')
+ call_output:write(' }\n')
+ call_output:write(' entered = true;\n')
write_arglist(call_output, ev)
call_output:write(' ui_call_event("' .. ev.name .. '", ' .. args .. ');\n')
+ call_output:write(' entered = false;\n')
elseif ev.compositor_impl then
call_output:write(' ui_comp_' .. ev.name)
write_signature(call_output, ev, '', true)
@@ -197,7 +205,8 @@ for _, ev in ipairs(events) do
ev_exported[attr] = ev[attr]
end
for _, p in ipairs(ev_exported.parameters) do
- if p[1] == 'HlAttrs' then
+ if p[1] == 'HlAttrs' or p[1] == 'Dict' then
+ -- TODO(justinmk): for back-compat, but do clients actually look at this?
p[1] = 'Dictionary'
end
end
diff --git a/src/nvim/generators/gen_declarations.lua b/src/nvim/generators/gen_declarations.lua
index 5d1e586fe6..2ec0e9ab68 100644
--- a/src/nvim/generators/gen_declarations.lua
+++ b/src/nvim/generators/gen_declarations.lua
@@ -2,6 +2,7 @@ local fname = arg[1]
local static_fname = arg[2]
local non_static_fname = arg[3]
local preproc_fname = arg[4]
+local static_basename = arg[5]
local lpeg = vim.lpeg
@@ -69,7 +70,7 @@ local raw_word = concat(w, any_amount(aw))
local right_word = concat(raw_word, neg_look_ahead(aw))
local word = branch(
concat(
- branch(lit('ArrayOf('), lit('DictionaryOf('), lit('Dict(')), -- typed container macro
+ branch(lit('ArrayOf('), lit('DictOf('), lit('Dict(')), -- typed container macro
one_or_more(any_character - lit(')')),
lit(')')
),
@@ -207,6 +208,10 @@ if fname:find('.*/src/nvim/.*%.c$') then
// IWYU pragma: private, include "%s"
]]):format(header_fname:gsub('.*/src/nvim/', 'nvim/')) .. non_static
end
+elseif fname:find('.*/src/nvim/.*%.h$') then
+ static = ([[
+// IWYU pragma: private, include "%s"
+]]):format(fname:gsub('.*/src/nvim/', 'nvim/')) .. static
elseif non_static_fname:find('/include/api/private/dispatch_wrappers%.h%.generated%.h$') then
non_static = [[
// IWYU pragma: private, include "nvim/api/private/dispatch.h"
@@ -235,6 +240,7 @@ local declendpos = 0
local curdir = nil
local is_needed_file = false
local init_is_nl = true
+local any_static = false
while init ~= nil do
if init_is_nl and text:sub(init, init) == '#' then
local line, dir, file = text:match(filepattern, init)
@@ -276,6 +282,9 @@ while init ~= nil do
end
declaration = declaration .. '\n'
if declaration:sub(1, 6) == 'static' then
+ if declaration:find('FUNC_ATTR_') then
+ any_static = true
+ end
static = static .. declaration
else
declaration = 'DLLEXPORT ' .. declaration
@@ -303,6 +312,21 @@ F = io.open(static_fname, 'w')
F:write(static)
F:close()
+if any_static then
+ F = io.open(fname, 'r')
+ local orig_text = F:read('*a')
+ local pat = '\n#%s?include%s+"' .. static_basename .. '"\n'
+ local pat_comment = '\n#%s?include%s+"' .. static_basename .. '"%s*//'
+ if not string.find(orig_text, pat) and not string.find(orig_text, pat_comment) then
+ error('fail: missing include for ' .. static_basename .. ' in ' .. fname)
+ end
+ F:close()
+end
+
+if non_static_fname == 'SKIP' then
+ return -- only want static declarations
+end
+
-- Before generating the non-static headers, check if the current file (if
-- exists) is different from the new one. If they are the same, we won't touch
-- the current version to avoid triggering an unnecessary rebuilds of modules
@@ -312,7 +336,7 @@ if F ~= nil then
if F:read('*a') == non_static then
os.exit(0)
end
- io.close(F)
+ F:close()
end
F = io.open(non_static_fname, 'w')
diff --git a/src/nvim/generators/gen_eval.lua b/src/nvim/generators/gen_eval.lua
index 1ce7f1af9d..443c68e008 100644
--- a/src/nvim/generators/gen_eval.lua
+++ b/src/nvim/generators/gen_eval.lua
@@ -19,6 +19,7 @@ hashpipe:write([[
#include "nvim/digraph.h"
#include "nvim/eval.h"
#include "nvim/eval/buffer.h"
+#include "nvim/eval/fs.h"
#include "nvim/eval/funcs.h"
#include "nvim/eval/typval.h"
#include "nvim/eval/vars.h"
diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua
index 0718d965c6..591a6b93df 100644
--- a/src/nvim/generators/gen_options.lua
+++ b/src/nvim/generators/gen_options.lua
@@ -148,7 +148,7 @@ local get_defaults = function(d, n)
return value_dumpers[type(d)](d)
end
---- @type {[1]:string,[2]:string}[]
+--- @type [string,string][]
local defines = {}
--- @param i integer
diff --git a/src/nvim/generators/gen_options_enum.lua b/src/nvim/generators/gen_options_enum.lua
index 9a3953fcbc..d1419137d3 100644
--- a/src/nvim/generators/gen_options_enum.lua
+++ b/src/nvim/generators/gen_options_enum.lua
@@ -80,7 +80,7 @@ enum_w('')
--- @type { [string]: string }
local option_index = {}
--- Generate option index enum and populate the `option_index` dictionary.
+-- Generate option index enum and populate the `option_index` dict.
enum_w('typedef enum {')
enum_w(' kOptInvalid = -1,')
diff --git a/src/nvim/generators/gen_unicode_tables.lua b/src/nvim/generators/gen_unicode_tables.lua
deleted file mode 100644
index 6cedb5db50..0000000000
--- a/src/nvim/generators/gen_unicode_tables.lua
+++ /dev/null
@@ -1,323 +0,0 @@
--- Script creates the following tables in unicode_tables.generated.h:
---
--- 1. doublewidth and ambiguous tables: sorted list of non-overlapping closed
--- intervals. Codepoints in these intervals have double (W or F) or ambiguous
--- (A) east asian width respectively.
--- 2. combining table: same as the above, but characters inside are combining
--- characters (i.e. have general categories equal to Mn, Mc or Me).
--- 3. foldCase, toLower and toUpper tables used to convert characters to
--- folded/lower/upper variants. In these tables first two values are
--- character ranges: like in previous tables they are sorted and must be
--- non-overlapping. Third value means step inside the range: e.g. if it is
--- 2 then interval applies only to first, third, fifth, … character in range.
--- Fourth value is number that should be added to the codepoint to yield
--- folded/lower/upper codepoint.
--- 4. emoji_wide and emoji_all tables: sorted lists of non-overlapping closed
--- intervals of Emoji characters. emoji_wide contains all the characters
--- which don't have ambiguous or double width, and emoji_all has all Emojis.
-if arg[1] == '--help' then
- print('Usage:')
- print(' gen_unicode_tables.lua unicode/ unicode_tables.generated.h')
- os.exit(0)
-end
-
-local basedir = arg[1]
-local pathsep = package.config:sub(1, 1)
-local get_path = function(fname)
- return basedir .. pathsep .. fname
-end
-
-local unicodedata_fname = get_path('UnicodeData.txt')
-local casefolding_fname = get_path('CaseFolding.txt')
-local eastasianwidth_fname = get_path('EastAsianWidth.txt')
-local emoji_fname = get_path('emoji-data.txt')
-
-local utf_tables_fname = arg[2]
-
-local split_on_semicolons = function(s)
- local ret = {}
- local idx = 1
- while idx <= #s + 1 do
- local item = s:match('^[^;]*', idx)
- idx = idx + #item + 1
- if idx <= #s + 1 then
- assert(s:sub(idx - 1, idx - 1) == ';')
- end
- item = item:gsub('^%s*', '')
- item = item:gsub('%s*$', '')
- table.insert(ret, item)
- end
- return ret
-end
-
-local fp_lines_to_lists = function(fp, n, has_comments)
- local ret = {}
- local line
- local i = 0
- while true do
- i = i + 1
- line = fp:read('*l')
- if not line then
- break
- end
- if not has_comments or (line:sub(1, 1) ~= '#' and not line:match('^%s*$')) then
- local l = split_on_semicolons(line)
- if #l ~= n then
- io.stderr:write(('Found %s items in line %u, expected %u\n'):format(#l, i, n))
- io.stderr:write('Line: ' .. line .. '\n')
- return nil
- end
- table.insert(ret, l)
- end
- end
- return ret
-end
-
-local parse_data_to_props = function(ud_fp)
- return fp_lines_to_lists(ud_fp, 15, false)
-end
-
-local parse_fold_props = function(cf_fp)
- return fp_lines_to_lists(cf_fp, 4, true)
-end
-
-local parse_width_props = function(eaw_fp)
- return fp_lines_to_lists(eaw_fp, 2, true)
-end
-
-local parse_emoji_props = function(emoji_fp)
- return fp_lines_to_lists(emoji_fp, 2, true)
-end
-
-local make_range = function(start, end_, step, add)
- if step and add then
- return (' {0x%x, 0x%x, %d, %d},\n'):format(start, end_, step == 0 and -1 or step, add)
- else
- return (' {0x%04x, 0x%04x},\n'):format(start, end_)
- end
-end
-
-local build_convert_table = function(ut_fp, props, cond_func, nl_index, table_name)
- ut_fp:write('static const convertStruct ' .. table_name .. '[] = {\n')
- local start = -1
- local end_ = -1
- local step = 0
- local add = -1
- for _, p in ipairs(props) do
- if cond_func(p) then
- local n = tonumber(p[1], 16)
- local nl = tonumber(p[nl_index], 16)
- if start >= 0 and add == (nl - n) and (step == 0 or n - end_ == step) then
- -- Continue with the same range.
- step = n - end_
- end_ = n
- else
- if start >= 0 then
- -- Produce previous range.
- ut_fp:write(make_range(start, end_, step, add))
- end
- start = n
- end_ = n
- step = 0
- add = nl - n
- end
- end
- end
- if start >= 0 then
- ut_fp:write(make_range(start, end_, step, add))
- end
- ut_fp:write('};\n')
-end
-
-local build_case_table = function(ut_fp, dataprops, table_name, index)
- local cond_func = function(p)
- return p[index] ~= ''
- end
- return build_convert_table(ut_fp, dataprops, cond_func, index, 'to' .. table_name)
-end
-
-local build_fold_table = function(ut_fp, foldprops)
- local cond_func = function(p)
- return (p[2] == 'C' or p[2] == 'S')
- end
- return build_convert_table(ut_fp, foldprops, cond_func, 3, 'foldCase')
-end
-
-local build_combining_table = function(ut_fp, dataprops)
- ut_fp:write('static const struct interval combining[] = {\n')
- local start = -1
- local end_ = -1
- for _, p in ipairs(dataprops) do
- -- The 'Mc' property was removed, it does take up space.
- if ({ Mn = true, Me = true })[p[3]] then
- local n = tonumber(p[1], 16)
- if start >= 0 and end_ + 1 == n then
- -- Continue with the same range.
- end_ = n
- else
- if start >= 0 then
- -- Produce previous range.
- ut_fp:write(make_range(start, end_))
- end
- start = n
- end_ = n
- end
- end
- end
- if start >= 0 then
- ut_fp:write(make_range(start, end_))
- end
- ut_fp:write('};\n')
-end
-
-local build_width_table = function(ut_fp, dataprops, widthprops, widths, table_name)
- ut_fp:write('static const struct interval ' .. table_name .. '[] = {\n')
- local start = -1
- local end_ = -1
- local dataidx = 1
- local ret = {}
- for _, p in ipairs(widthprops) do
- if widths[p[2]:sub(1, 1)] then
- local rng_start, rng_end = p[1]:find('%.%.')
- local n, n_last
- if rng_start then
- -- It is a range. We don’t check for composing char then.
- n = tonumber(p[1]:sub(1, rng_start - 1), 16)
- n_last = tonumber(p[1]:sub(rng_end + 1), 16)
- else
- n = tonumber(p[1], 16)
- n_last = n
- end
- local dn
- while true do
- dn = tonumber(dataprops[dataidx][1], 16)
- if dn >= n then
- break
- end
- dataidx = dataidx + 1
- end
- if dn ~= n and n_last == n then
- io.stderr:write('Cannot find character ' .. n .. ' in data table.\n')
- end
- -- Only use the char when it’s not a composing char.
- -- But use all chars from a range.
- local dp = dataprops[dataidx]
- if (n_last > n) or not ({ Mn = true, Mc = true, Me = true })[dp[3]] then
- if start >= 0 and end_ + 1 == n then -- luacheck: ignore 542
- -- Continue with the same range.
- else
- if start >= 0 then
- ut_fp:write(make_range(start, end_))
- table.insert(ret, { start, end_ })
- end
- start = n
- end
- end_ = n_last
- end
- end
- end
- if start >= 0 then
- ut_fp:write(make_range(start, end_))
- table.insert(ret, { start, end_ })
- end
- ut_fp:write('};\n')
- return ret
-end
-
-local build_emoji_table = function(ut_fp, emojiprops, doublewidth, ambiwidth)
- local emojiwidth = {}
- local emoji = {}
- for _, p in ipairs(emojiprops) do
- if p[2]:match('Emoji%s+#') then
- local rng_start, rng_end = p[1]:find('%.%.')
- local n
- local n_last
- if rng_start then
- n = tonumber(p[1]:sub(1, rng_start - 1), 16)
- n_last = tonumber(p[1]:sub(rng_end + 1), 16)
- else
- n = tonumber(p[1], 16)
- n_last = n
- end
- if #emoji > 0 and n - 1 == emoji[#emoji][2] then
- emoji[#emoji][2] = n_last
- else
- table.insert(emoji, { n, n_last })
- end
-
- -- Characters below 1F000 may be considered single width traditionally,
- -- making them double width causes problems.
- if n >= 0x1f000 then
- -- exclude characters that are in the ambiguous/doublewidth table
- for _, ambi in ipairs(ambiwidth) do
- if n >= ambi[1] and n <= ambi[2] then
- n = ambi[2] + 1
- end
- if n_last >= ambi[1] and n_last <= ambi[2] then
- n_last = ambi[1] - 1
- end
- end
- for _, double in ipairs(doublewidth) do
- if n >= double[1] and n <= double[2] then
- n = double[2] + 1
- end
- if n_last >= double[1] and n_last <= double[2] then
- n_last = double[1] - 1
- end
- end
-
- if n <= n_last then
- if #emojiwidth > 0 and n - 1 == emojiwidth[#emojiwidth][2] then
- emojiwidth[#emojiwidth][2] = n_last
- else
- table.insert(emojiwidth, { n, n_last })
- end
- end
- end
- end
- end
-
- ut_fp:write('static const struct interval emoji_all[] = {\n')
- for _, p in ipairs(emoji) do
- ut_fp:write(make_range(p[1], p[2]))
- end
- ut_fp:write('};\n')
-
- ut_fp:write('static const struct interval emoji_wide[] = {\n')
- for _, p in ipairs(emojiwidth) do
- ut_fp:write(make_range(p[1], p[2]))
- end
- ut_fp:write('};\n')
-end
-
-local ud_fp = io.open(unicodedata_fname, 'r')
-local dataprops = parse_data_to_props(ud_fp)
-ud_fp:close()
-
-local ut_fp = io.open(utf_tables_fname, 'w')
-
-build_case_table(ut_fp, dataprops, 'Lower', 14)
-build_case_table(ut_fp, dataprops, 'Upper', 13)
-build_combining_table(ut_fp, dataprops)
-
-local cf_fp = io.open(casefolding_fname, 'r')
-local foldprops = parse_fold_props(cf_fp)
-cf_fp:close()
-
-build_fold_table(ut_fp, foldprops)
-
-local eaw_fp = io.open(eastasianwidth_fname, 'r')
-local widthprops = parse_width_props(eaw_fp)
-eaw_fp:close()
-
-local doublewidth =
- build_width_table(ut_fp, dataprops, widthprops, { W = true, F = true }, 'doublewidth')
-local ambiwidth = build_width_table(ut_fp, dataprops, widthprops, { A = true }, 'ambiguous')
-
-local emoji_fp = io.open(emoji_fname, 'r')
-local emojiprops = parse_emoji_props(emoji_fp)
-emoji_fp:close()
-
-build_emoji_table(ut_fp, emojiprops, doublewidth, ambiwidth)
-
-ut_fp:close()
diff --git a/src/nvim/generators/gen_vimvim.lua b/src/nvim/generators/gen_vimvim.lua
index fcdc5bddc2..0675f04b73 100644
--- a/src/nvim/generators/gen_vimvim.lua
+++ b/src/nvim/generators/gen_vimvim.lua
@@ -80,12 +80,13 @@ for _, cmd_desc in ipairs(ex_cmds.cmds) do
end
local vimopt_start = 'syn keyword vimOption contained '
+local vimopt_end = ' skipwhite nextgroup=vimSetEqual,vimSetMod'
w('\n\n' .. vimopt_start)
for _, opt_desc in ipairs(options.options) do
if not opt_desc.immutable then
if lld.line_length > 850 then
- w('\n' .. vimopt_start)
+ w(vimopt_end .. '\n' .. vimopt_start)
end
w(' ' .. opt_desc.full_name)
if opt_desc.abbreviation then
@@ -102,7 +103,9 @@ for _, opt_desc in ipairs(options.options) do
end
end
-w('\n\nsyn case ignore')
+w(vimopt_end .. '\n')
+
+w('\nsyn case ignore')
local vimau_start = 'syn keyword vimAutoEvent contained '
w('\n\n' .. vimau_start)
diff --git a/src/nvim/generators/hashy.lua b/src/nvim/generators/hashy.lua
index 711e695742..ea35064962 100644
--- a/src/nvim/generators/hashy.lua
+++ b/src/nvim/generators/hashy.lua
@@ -73,11 +73,15 @@ function M.switcher(put, tab, maxlen, worst_buck_size)
vim.list_extend(neworder, buck)
local endidx = #neworder
put(" case '" .. c .. "': ")
- put('low = ' .. startidx .. '; ')
- if bucky then
- put('high = ' .. endidx .. '; ')
+ if len == 1 then
+ put('return ' .. startidx .. ';\n')
+ else
+ put('low = ' .. startidx .. '; ')
+ if bucky then
+ put('high = ' .. endidx .. '; ')
+ end
+ put 'break;\n'
end
- put 'break;\n'
end
put ' default: break;\n'
put ' }\n '
@@ -105,13 +109,19 @@ function M.hashy_hash(name, strings, access)
end
local len_pos_buckets, maxlen, worst_buck_size = M.build_pos_hash(strings)
put('int ' .. name .. '_hash(const char *str, size_t len)\n{\n')
- if worst_buck_size > 1 then
+ if maxlen == 1 then
+ put('\n') -- nothing
+ elseif worst_buck_size > 1 then
put(' int low = 0, high = 0;\n')
else
put(' int low = -1;\n')
end
local neworder = M.switcher(put, len_pos_buckets, maxlen, worst_buck_size)
- if worst_buck_size > 1 then
+ if maxlen == 1 then
+ put([[
+ return -1;
+]])
+ elseif worst_buck_size > 1 then
put([[
for (int i = low; i < high; i++) {
if (!memcmp(str, ]] .. access('i') .. [[, len)) {