From f74322b9a5695d2a3bf31e1da05197d700b94c76 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jan 2017 00:46:58 +0300 Subject: gendeclarations: Save where declaration is comping from --- scripts/gendeclarations.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'scripts/gendeclarations.lua') diff --git a/scripts/gendeclarations.lua b/scripts/gendeclarations.lua index ff69b18ae4..6358ea4778 100755 --- a/scripts/gendeclarations.lua +++ b/scripts/gendeclarations.lua @@ -188,23 +188,29 @@ local footer = [[ local non_static = header local static = header -local filepattern = '^#%a* %d+ "[^"]-/?([^"/]+)"' +local filepattern = '^#%a* (%d+) "[^"]-/?([^"/]+)"' local curfile init = 0 curfile = nil neededfile = fname:match('[^/]+$') +local declline = 0 +local declendpos = 0 while init ~= nil do init = text:find('\n', init) if init == nil then break end init = init + 1 + declline = declline + 1 if text:sub(init, init) == '#' then - file = text:match(filepattern, init) + local line, file = text:match(filepattern, init) if file ~= nil then curfile = file end + declline = tonumber(line) - 1 + elseif init < declendpos then + -- Skipping over declaration elseif curfile == neededfile then s = init e = pattern:match(text, init) @@ -225,13 +231,15 @@ while init ~= nil do declaration = declaration:gsub(' ?(%*+) ?', ' %1') declaration = declaration:gsub(' ?(FUNC_ATTR_)', ' %1') declaration = declaration:gsub(' $', '') - declaration = declaration .. ';\n' + declaration = declaration .. ';' + declaration = declaration .. ' // ' .. curfile .. ':' .. declline + declaration = declaration .. '\n' if text:sub(s, s + 5) == 'static' then static = static .. declaration else non_static = non_static .. declaration end - init = e + declendpos = e end end end -- cgit From c470fc32a8c96fb153b779489c22b8e86003e9f0 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jan 2017 00:52:27 +0300 Subject: gendeclarations: Also save information about directory --- scripts/gendeclarations.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'scripts/gendeclarations.lua') diff --git a/scripts/gendeclarations.lua b/scripts/gendeclarations.lua index 6358ea4778..5d5939f7d1 100755 --- a/scripts/gendeclarations.lua +++ b/scripts/gendeclarations.lua @@ -188,14 +188,15 @@ local footer = [[ local non_static = header local static = header -local filepattern = '^#%a* (%d+) "[^"]-/?([^"/]+)"' +local filepattern = '^#%a* (%d+) "([^"]-)/?([^"/]+)"' local curfile -init = 0 -curfile = nil -neededfile = fname:match('[^/]+$') +local init = 0 +local curfile = nil +local neededfile = fname:match('[^/]+$') local declline = 0 local declendpos = 0 +local curdir = nil while init ~= nil do init = text:find('\n', init) if init == nil then @@ -204,11 +205,17 @@ while init ~= nil do init = init + 1 declline = declline + 1 if text:sub(init, init) == '#' then - local line, file = text:match(filepattern, init) + local line, dir, file = text:match(filepattern, init) if file ~= nil then curfile = file end declline = tonumber(line) - 1 + local curdir_start = dir:find('src/nvim/') + if curdir_start ~= nil then + curdir = dir:sub(curdir_start + #('src/nvim/')) + else + curdir = dir + end elseif init < declendpos then -- Skipping over declaration elseif curfile == neededfile then @@ -232,7 +239,8 @@ while init ~= nil do declaration = declaration:gsub(' ?(FUNC_ATTR_)', ' %1') declaration = declaration:gsub(' $', '') declaration = declaration .. ';' - declaration = declaration .. ' // ' .. curfile .. ':' .. declline + declaration = declaration .. (' // %s/%s:%u'):format( + curdir, curfile, declline) declaration = declaration .. '\n' if text:sub(s, s + 5) == 'static' then static = static .. declaration -- cgit From 52c7066f4b546419a1838b41e68a5d1650ac498e Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jan 2017 01:07:18 +0300 Subject: gendeclarations: Handle case when text did not match --- scripts/gendeclarations.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'scripts/gendeclarations.lua') diff --git a/scripts/gendeclarations.lua b/scripts/gendeclarations.lua index 5d5939f7d1..3f948b91df 100755 --- a/scripts/gendeclarations.lua +++ b/scripts/gendeclarations.lua @@ -208,13 +208,15 @@ while init ~= nil do local line, dir, file = text:match(filepattern, init) if file ~= nil then curfile = file - end - declline = tonumber(line) - 1 - local curdir_start = dir:find('src/nvim/') - if curdir_start ~= nil then - curdir = dir:sub(curdir_start + #('src/nvim/')) + declline = tonumber(line) - 1 + local curdir_start = dir:find('src/nvim/') + if curdir_start ~= nil then + curdir = dir:sub(curdir_start + #('src/nvim/')) + else + curdir = dir + end else - curdir = dir + declline = declline - 1 end elseif init < declendpos then -- Skipping over declaration -- cgit From ae4adcc70735a89bffb110bcf9d5a993b0786c4d Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 28 Jan 2017 03:47:15 +0300 Subject: 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. --- scripts/gendeclarations.lua | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'scripts/gendeclarations.lua') 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 -- cgit