mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 22:18:33 +00:00
Merge pull request #840 from ZyX-I/generate-ex_cmds
Use lua generator in place of ex_cmds_defs header trick
This commit is contained in:
87
scripts/genex_cmds.lua
Normal file
87
scripts/genex_cmds.lua
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
local nvimsrcdir = arg[1]
|
||||||
|
local includedir = arg[2]
|
||||||
|
local autodir = arg[3]
|
||||||
|
|
||||||
|
if nvimsrcdir == '--help' then
|
||||||
|
print ([[
|
||||||
|
Usage:
|
||||||
|
lua genex_cmds.lua src/nvim build/include build/src/nvim/auto
|
||||||
|
|
||||||
|
Will generate files build/include/ex_cmds_enum.generated.h with cmdidx_T
|
||||||
|
enum and build/src/nvim/auto/ex_cmds_defs.generated.h with main Ex commands
|
||||||
|
definitions.
|
||||||
|
]])
|
||||||
|
os.exit(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
package.path = nvimsrcdir .. '/?.lua;' .. package.path
|
||||||
|
|
||||||
|
local enumfname = includedir .. '/ex_cmds_enum.generated.h'
|
||||||
|
local defsfname = autodir .. '/ex_cmds_defs.generated.h'
|
||||||
|
|
||||||
|
local enumfile = io.open(enumfname, 'w')
|
||||||
|
local defsfile = io.open(defsfname, 'w')
|
||||||
|
|
||||||
|
local defs = require('ex_cmds')
|
||||||
|
local lastchar = nil
|
||||||
|
|
||||||
|
local i
|
||||||
|
local cmd
|
||||||
|
local first = true
|
||||||
|
local prevfirstchar = nil
|
||||||
|
|
||||||
|
local byte_a = string.byte('a')
|
||||||
|
local byte_z = string.byte('z')
|
||||||
|
|
||||||
|
local cmdidxs = string.format([[
|
||||||
|
static const cmdidx_T cmdidxs[%u] = {
|
||||||
|
]], byte_z - byte_a + 2)
|
||||||
|
|
||||||
|
enumfile:write([[
|
||||||
|
typedef enum CMD_index {
|
||||||
|
]])
|
||||||
|
defsfile:write(string.format([[
|
||||||
|
static CommandDefinition cmdnames[%u] = {
|
||||||
|
]], #defs))
|
||||||
|
for i, cmd in ipairs(defs) do
|
||||||
|
local enumname = cmd.enum or ('CMD_' .. cmd.command)
|
||||||
|
firstchar = string.byte(cmd.command)
|
||||||
|
if firstchar ~= prevfirstchar then
|
||||||
|
if (not prevfirstchar
|
||||||
|
or (byte_a <= firstchar and firstchar <= byte_z)
|
||||||
|
or (byte_a <= prevfirstchar and prevfirstchar <= byte_z)) then
|
||||||
|
if not first then
|
||||||
|
cmdidxs = cmdidxs .. ',\n'
|
||||||
|
end
|
||||||
|
cmdidxs = cmdidxs .. ' ' .. enumname
|
||||||
|
end
|
||||||
|
prevfirstchar = firstchar
|
||||||
|
end
|
||||||
|
if first then
|
||||||
|
first = false
|
||||||
|
else
|
||||||
|
defsfile:write(',\n')
|
||||||
|
end
|
||||||
|
enumfile:write(' ' .. enumname .. ',\n')
|
||||||
|
defsfile:write(string.format([[
|
||||||
|
[%s] = {
|
||||||
|
.cmd_name = (char_u *) "%s",
|
||||||
|
.cmd_func = &%s,
|
||||||
|
.cmd_argt = %uL
|
||||||
|
}]], enumname, cmd.command, cmd.func, cmd.flags))
|
||||||
|
end
|
||||||
|
defsfile:write([[
|
||||||
|
|
||||||
|
};
|
||||||
|
]])
|
||||||
|
enumfile:write([[
|
||||||
|
CMD_SIZE,
|
||||||
|
CMD_USER = -1,
|
||||||
|
CMD_USER_BUF = -2
|
||||||
|
} cmdidx_T;
|
||||||
|
]])
|
||||||
|
cmdidxs = cmdidxs .. [[
|
||||||
|
|
||||||
|
};
|
||||||
|
]]
|
||||||
|
defsfile:write(cmdidxs)
|
@@ -7,6 +7,10 @@ set(MSGPACK_RPC_HEADER ${PROJECT_SOURCE_DIR}/src/nvim/os/msgpack_rpc.h)
|
|||||||
set(MSGPACK_DISPATCH ${GENERATED_DIR}/msgpack_dispatch.c)
|
set(MSGPACK_DISPATCH ${GENERATED_DIR}/msgpack_dispatch.c)
|
||||||
set(HEADER_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendeclarations.lua)
|
set(HEADER_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendeclarations.lua)
|
||||||
set(GENERATED_INCLUDES_DIR ${PROJECT_BINARY_DIR}/include)
|
set(GENERATED_INCLUDES_DIR ${PROJECT_BINARY_DIR}/include)
|
||||||
|
set(GENERATED_EX_CMDS_ENUM ${GENERATED_INCLUDES_DIR}/ex_cmds_enum.generated.h)
|
||||||
|
set(GENERATED_EX_CMDS_DEFS ${GENERATED_DIR}/ex_cmds_defs.generated.h)
|
||||||
|
set(EX_CMDS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/genex_cmds.lua)
|
||||||
|
set(EX_CMDS_DEFS_FILE ${PROJECT_SOURCE_DIR}/src/nvim/ex_cmds.lua)
|
||||||
|
|
||||||
include_directories(${GENERATED_DIR})
|
include_directories(${GENERATED_DIR})
|
||||||
include_directories(${GENERATED_INCLUDES_DIR})
|
include_directories(${GENERATED_INCLUDES_DIR})
|
||||||
@@ -128,7 +132,16 @@ add_custom_command(OUTPUT ${MSGPACK_DISPATCH}
|
|||||||
|
|
||||||
list(APPEND NEOVIM_GENERATED_SOURCES
|
list(APPEND NEOVIM_GENERATED_SOURCES
|
||||||
"${PROJECT_BINARY_DIR}/config/auto/pathdef.c"
|
"${PROJECT_BINARY_DIR}/config/auto/pathdef.c"
|
||||||
"${MSGPACK_DISPATCH}")
|
"${MSGPACK_DISPATCH}"
|
||||||
|
"${GENERATED_EX_CMDS_ENUM}"
|
||||||
|
"${GENERATED_EX_CMDS_DEFS}"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT ${GENERATED_EX_CMDS_ENUM} ${GENERATED_EX_CMDS_DEFS}
|
||||||
|
COMMAND ${LUA_PRG} ${EX_CMDS_GENERATOR}
|
||||||
|
${PROJECT_SOURCE_DIR}/src/nvim ${GENERATED_INCLUDES_DIR} ${GENERATED_DIR}
|
||||||
|
DEPENDS ${EX_CMDS_GENERATOR} ${EX_CMDS_DEFS_FILE}
|
||||||
|
)
|
||||||
|
|
||||||
# Our dependencies come first.
|
# Our dependencies come first.
|
||||||
|
|
||||||
|
2552
src/nvim/ex_cmds.lua
Normal file
2552
src/nvim/ex_cmds.lua
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -66,6 +66,7 @@
|
|||||||
#include "nvim/version.h"
|
#include "nvim/version.h"
|
||||||
#include "nvim/window.h"
|
#include "nvim/window.h"
|
||||||
#include "nvim/os/os.h"
|
#include "nvim/os/os.h"
|
||||||
|
#include "nvim/ex_cmds_defs.h"
|
||||||
|
|
||||||
static int quitmore = 0;
|
static int quitmore = 0;
|
||||||
static int ex_pressedreturn = FALSE;
|
static int ex_pressedreturn = FALSE;
|
||||||
@@ -156,42 +157,9 @@ static int did_lcd; /* whether ":lcd" was produced for a session */
|
|||||||
/*
|
/*
|
||||||
* Declare cmdnames[].
|
* Declare cmdnames[].
|
||||||
*/
|
*/
|
||||||
#define DO_DECLARE_EXCMD
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
#include "nvim/ex_cmds_defs.h"
|
# include "ex_cmds_defs.generated.h"
|
||||||
|
#endif
|
||||||
/*
|
|
||||||
* Table used to quickly search for a command, based on its first character.
|
|
||||||
*/
|
|
||||||
static cmdidx_T cmdidxs[27] =
|
|
||||||
{
|
|
||||||
CMD_append,
|
|
||||||
CMD_buffer,
|
|
||||||
CMD_change,
|
|
||||||
CMD_delete,
|
|
||||||
CMD_edit,
|
|
||||||
CMD_file,
|
|
||||||
CMD_global,
|
|
||||||
CMD_help,
|
|
||||||
CMD_insert,
|
|
||||||
CMD_join,
|
|
||||||
CMD_k,
|
|
||||||
CMD_list,
|
|
||||||
CMD_move,
|
|
||||||
CMD_next,
|
|
||||||
CMD_open,
|
|
||||||
CMD_print,
|
|
||||||
CMD_quit,
|
|
||||||
CMD_read,
|
|
||||||
CMD_substitute,
|
|
||||||
CMD_t,
|
|
||||||
CMD_undo,
|
|
||||||
CMD_vglobal,
|
|
||||||
CMD_write,
|
|
||||||
CMD_xit,
|
|
||||||
CMD_yank,
|
|
||||||
CMD_z,
|
|
||||||
CMD_bang
|
|
||||||
};
|
|
||||||
|
|
||||||
static char_u dollar_command[2] = {'$', 0};
|
static char_u dollar_command[2] = {'$', 0};
|
||||||
|
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
#ifndef NVIM_EX_DOCMD_H
|
#ifndef NVIM_EX_DOCMD_H
|
||||||
#define NVIM_EX_DOCMD_H
|
#define NVIM_EX_DOCMD_H
|
||||||
|
|
||||||
|
#include "nvim/ex_cmds_defs.h"
|
||||||
|
|
||||||
/* flags for do_cmdline() */
|
/* flags for do_cmdline() */
|
||||||
#define DOCMD_VERBOSE 0x01 /* included command in error message */
|
#define DOCMD_VERBOSE 0x01 /* included command in error message */
|
||||||
#define DOCMD_NOWAIT 0x02 /* don't call wait_return() and friends */
|
#define DOCMD_NOWAIT 0x02 /* don't call wait_return() and friends */
|
||||||
@@ -17,8 +19,6 @@
|
|||||||
#define EXMODE_NORMAL 1
|
#define EXMODE_NORMAL 1
|
||||||
#define EXMODE_VIM 2
|
#define EXMODE_VIM 2
|
||||||
|
|
||||||
typedef char_u *(*LineGetter)(int, void *, int);
|
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "ex_docmd.h.generated.h"
|
# include "ex_docmd.h.generated.h"
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user