aboutsummaryrefslogtreecommitdiff
path: root/scripts/gendeclarations.lua
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-01-28 03:47:15 +0300
committerZyX <kp-pav@yandex.ru>2017-03-27 00:12:23 +0300
commitae4adcc70735a89bffb110bcf9d5a993b0786c4d (patch)
treeee10336f3c50e3a69f9a1660d5a7cb8735912391 /scripts/gendeclarations.lua
parent52c7066f4b546419a1838b41e68a5d1650ac498e (diff)
downloadrneovim-ae4adcc70735a89bffb110bcf9d5a993b0786c4d.tar.gz
rneovim-ae4adcc70735a89bffb110bcf9d5a993b0786c4d.tar.bz2
rneovim-ae4adcc70735a89bffb110bcf9d5a993b0786c4d.zip
gendeclarations: Make declarations generator work with macros funcs
Now it checks functions also after every semicolon and closing figure brace, possibly preceded by whitespaces (tabs and spaces). This should make messing with declarations in macros not needed.
Diffstat (limited to 'scripts/gendeclarations.lua')
-rwxr-xr-xscripts/gendeclarations.lua34
1 files changed, 21 insertions, 13 deletions
diff --git a/scripts/gendeclarations.lua b/scripts/gendeclarations.lua
index 3f948b91df..e999e53e4a 100755
--- a/scripts/gendeclarations.lua
+++ b/scripts/gendeclarations.lua
@@ -69,17 +69,18 @@ local word = branch(
right_word
)
)
+local inline_comment = concat(
+ lit('/*'),
+ any_amount(concat(
+ neg_look_ahead(lit('*/')),
+ any_character
+ )),
+ lit('*/')
+)
local spaces = any_amount(branch(
s,
-- Comments are really handled by preprocessor, so the following is not needed
- concat(
- lit('/*'),
- any_amount(concat(
- neg_look_ahead(lit('*/')),
- any_character
- )),
- lit('*/')
- ),
+ inline_comment,
concat(
lit('//'),
any_amount(concat(
@@ -110,6 +111,7 @@ local typ = one_or_more(typ_part)
local typ_id = two_or_more(typ_part)
local arg = typ_id -- argument name is swallowed by typ
local pattern = concat(
+ any_amount(branch(set(' ', '\t'), inline_comment)),
typ_id, -- return type with function name
spaces,
lit('('),
@@ -197,17 +199,22 @@ local neededfile = fname:match('[^/]+$')
local declline = 0
local declendpos = 0
local curdir = nil
+local is_needed_file = false
while init ~= nil do
- init = text:find('\n', init)
+ init = text:find('[\n;}]', init)
if init == nil then
break
end
+ local init_is_nl = text:sub(init, init) == '\n'
init = init + 1
- declline = declline + 1
- if text:sub(init, init) == '#' then
+ if init_is_nl and is_needed_file then
+ declline = declline + 1
+ end
+ if init_is_nl and text:sub(init, init) == '#' then
local line, dir, file = text:match(filepattern, init)
if file ~= nil then
curfile = file
+ is_needed_file = (curfile == neededfile)
declline = tonumber(line) - 1
local curdir_start = dir:find('src/nvim/')
if curdir_start ~= nil then
@@ -220,7 +227,7 @@ while init ~= nil do
end
elseif init < declendpos then
-- Skipping over declaration
- elseif curfile == neededfile then
+ elseif is_needed_file then
s = init
e = pattern:match(text, init)
if e ~= nil then
@@ -240,11 +247,12 @@ while init ~= nil do
declaration = declaration:gsub(' ?(%*+) ?', ' %1')
declaration = declaration:gsub(' ?(FUNC_ATTR_)', ' %1')
declaration = declaration:gsub(' $', '')
+ declaration = declaration:gsub('^ ', '')
declaration = declaration .. ';'
declaration = declaration .. (' // %s/%s:%u'):format(
curdir, curfile, declline)
declaration = declaration .. '\n'
- if text:sub(s, s + 5) == 'static' then
+ if declaration:sub(1, 6) == 'static' then
static = static .. declaration
else
non_static = non_static .. declaration