aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/gen_iface.lua
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2014-06-09 14:43:39 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2014-06-09 14:43:39 -0400
commit80a0e030a1736ef7f4d9034c02b68fd3a84369b3 (patch)
tree6827625e8a7b79442bc148dedcfde9c7f2997132 /scripts/gen_iface.lua
parent107d2613c1a8d31ac2d6df3732229c283cea98d7 (diff)
Generate Lua interface using Scintilla instead of SciTE; scripts/gen_iface.lua
Diffstat (limited to 'scripts/gen_iface.lua')
-rwxr-xr-xscripts/gen_iface.lua213
1 files changed, 93 insertions, 120 deletions
diff --git a/scripts/gen_iface.lua b/scripts/gen_iface.lua
index f56fd50f..cf06ff75 100755
--- a/scripts/gen_iface.lua
+++ b/scripts/gen_iface.lua
@@ -1,25 +1,88 @@
#!/usr/bin/lua
-- Copyright 2007-2014 Mitchell mitchell.att.foicica.com. See LICENSE.
--- This script generates the _SCINTILLA table from SciTE's Lua Interface tables.
-
-local f = io.open(arg[1] or '../../scite-latest/scite/src/IFaceTable.cxx', 'rb')
-local iface = f:read('*all')
-f:close()
-
-local string_format = string.format
-local constants, fielddoc, functions, properties = {}, {}, {}, {}
+local constants, functions, properties = {}, {}, {}
+local const_patt = '^val ([%w_]+)=([-%dx%x]+)'
+local event_patt = '^evt %a+ ([%w_]+)=(%d+)'
+local msg_patt = '^(%a+) (%a+) (%w+)=(%d+)%((%a*) ?([^,]*),%s*(%a*)'
local types = {
- void = 0, int = 1, length = 2, position = 3, colour = 4, bool = 5,
+ [''] = 0, void = 0, int = 1, length = 2, position = 3, colour = 4, bool = 5,
keymod = 6, string = 7, stringresult = 8, cells = 9, textrange = 10,
findtext = 11, formatrange = 12
}
-local s = '_G._SCINTILLA.constants'
+local ignores = { -- constants to ignore
+ '^INDIC[012S]_', '^INVALID_POSITION', '^KEYWORDSET_MAX', '^SC_CACHE_',
+ '^SC_CHARSET_', '^SC_CP_DBCS', '^SC_EFF_', '^SC_FONT_SIZE_MULTIPLIER',
+ '^SC_LINE_END_TYPE_', '^SC_PRINT_', '^SC_STATUS_', '^SC_TECHNOLOGY_',
+ '^SC_TYPE_', '^SC_WEIGHT_', '^SCE_', '^SCEN_', '^SCFIND_POSIX', '^SCI_',
+ '^SCK_', '^SCLEX_', '^UNDO_MAY_COALESCE'
+}
+local changed_setter = {} -- holds properties changed to setter functions
+local string_format, table_unpack = string.format, table.unpack
-f = io.open('../core/iface.lua', 'wb')
+for line in io.lines('../src/scintilla/include/Scintilla.iface') do
+ if line:find('^val ') then
+ local name, value = line:match(const_patt)
+ for i = 1, #ignores do if name:find(ignores[i]) then goto continue end end
+ name = name:gsub('^SC_', ''):gsub('^SC([^N]%u+)', '%1')
+ if name == 'FIND_REGEXP' then
+ value = tostring(tonumber(value) + 2^22) -- add SCFIND_POSIX
+ elseif name == 'MASK_FOLDERS' then
+ value = '-33554432'
+ end
+ constants[#constants + 1] = string_format('%s=%s', name, value)
+ elseif line:find('^evt ') then
+ local name, value = line:match(event_patt)
+ constants[#constants + 1] = string_format('SCN_%s=%s', name:upper(), value)
+ elseif line:find('^fun ') then
+ local _, rtype, name, id, wtype, param, ltype = line:match(msg_patt)
+ name = name:gsub('([a-z])([A-Z])', '%1_%2')
+ :gsub('([A-Z])([A-Z][a-z])', '%1_%2'):lower()
+ if name == 'convert_eo_ls' then name = 'convert_eols' end
+ if wtype == 'int' and param == 'length' then wtype = 'length' end
+ functions[#functions + 1] = name
+ functions[name] = {id, types[rtype], types[wtype], types[ltype]}
+ elseif line:find('^get ') or line:find('^set ') then
+ local kind, rtype, name, id, wtype, _, ltype = line:match(msg_patt)
+ name = name:gsub('[GS]et%f[%u]', ''):gsub('([a-z])([A-Z])', '%1_%2')
+ :gsub('([A-Z])([A-Z][a-z])', '%1_%2'):lower()
+ if kind == 'get' and wtype == 'int' and ltype == 'int' or
+ wtype == 'bool' and ltype ~= '' or changed_setter[name] then
+ -- Special case getter/setter; handle as function.
+ local fname = kind..'_'..name
+ functions[#functions + 1] = fname
+ functions[fname] = {id, types[rtype], types[wtype], types[ltype]}
+ changed_setter[name] = true
+ goto continue
+ end
+ if not properties[name] then
+ properties[#properties + 1] = name
+ properties[name] = {0, 0, 0, 0}
+ end
+ local prop = properties[name]
+ if kind == 'get' then
+ prop[1] = id
+ prop[3] = types[ltype ~= 'stringresult' and rtype or ltype]
+ if wtype ~= '' then prop[4] = types[wtype] end
+ else
+ prop[2] = id
+ if prop[1] == 0 then
+ prop[3] = types[wtype ~= '' and ltype == '' and wtype or ltype]
+ end
+ prop[4] = types[ltype ~= '' and wtype or ltype]
+ end
+ elseif line:find('cat Provisional') then
+ break
+ end
+ ::continue::
+end
--- Write header.
-f:write [=[
+table.sort(constants)
+table.sort(functions)
+table.sort(properties)
+
+local f = io.open('../core/iface.lua', 'wb')
+f:write([=[
-- Copyright 2007-2014 Mitchell mitchell.att.foicica.com. See LICENSE.
local M = {}
@@ -31,96 +94,17 @@ local M = {}
-- consequences.
module('_SCINTILLA')]]
-]=]
-
--- Constants to ignore.
-local ignores = {
- '^IDM_', '^INDIC[012S]_', '^INVALID_POSITION', '^KEYWORDSET_MAX',
- '^SC_CACHE_', '^SC_CHARSET_', '^SC_EFF_', '^SC_FONT_SIZE_MULTIPLIER',
- '^SC_LINE_END_TYPE_', -- provisional
- '^SC_PRINT_', '^SC_STATUS_', '^SC_TECHNOLOGY_', '^SC_TYPE_', '^SC_WEIGHT_',
- '^SCE_', '^SCEN_', '^SCFIND_POSIX', '^SCI_', '^SCK_', '^SCLEX_',
- '^UNDO_MAY_COALESCE'
-}
--- Constants ({"constant", value}).
-for item in iface:match('Constants%[%] = (%b{})'):sub(2, -2):gmatch('%b{}') do
- local name, value = item:match('^{"(.-)",(.-)}')
- local skip = false
- for i = 1, #ignores do if name:find(ignores[i]) then skip = true break end end
- if not skip then
- name = name:gsub('^SC_', ''):gsub('^SC([^N]%u+)', '%1')
- if name == 'FIND_REGEXP' then
- value = tostring(tonumber(value) + 2^22) -- add SCFIND_POSIX
- elseif name == 'MASK_FOLDERS' then
- value = '-33554432'
- end
- constants[#constants + 1] = string_format('%s=%s', name, value)
- fielddoc[#fielddoc + 1] = string_format('-- * `%s.%s` %d', s, name, value)
- end
-end
-
--- Events added to constants.
-local events = {
- SCN_STYLENEEDED = 2000,
- SCN_CHARADDED = 2001,
- SCN_SAVEPOINTREACHED = 2002,
- SCN_SAVEPOINTLEFT = 2003,
- SCN_MODIFYATTEMPTRO = 2004,
- SCN_KEY = 2005,
- SCN_DOUBLECLICK = 2006,
- SCN_UPDATEUI = 2007,
- SCN_MODIFIED = 2008,
- SCN_MACRORECORD = 2009,
- SCN_MARGINCLICK = 2010,
- SCN_NEEDSHOWN = 2011,
- SCN_PAINTED = 2013,
- SCN_USERLISTSELECTION = 2014,
- SCN_URIDROPPED = 2015,
- SCN_DWELLSTART = 2016,
- SCN_DWELLEND = 2017,
- SCN_ZOOM = 2018,
- SCN_HOTSPOTCLICK = 2019,
- SCN_HOTSPOTDOUBLECLICK = 2020,
- SCN_CALLTIPCLICK = 2021,
- SCN_AUTOCSELECTION = 2022,
- SCN_INDICATORCLICK = 2023,
- SCN_INDICATORRELEASE = 2024,
- SCN_AUTOCCANCELLED = 2025,
- SCN_AUTOCCHARDELETED = 2026,
- SCN_HOTSPOTRELEASECLICK = 2027,
- SCN_FOCUSIN = 2028,
- SCN_FOCUSOUT = 2029
-}
-for event, value in pairs(events) do
- constants[#constants + 1] = string_format('%s=%d', event, value)
-end
-
--- Write constants.
-f:write [[
+]=])
+f:write([[
---
-- Map of Scintilla constant names to their numeric values.
-- @class table
-- @name constants
-- @see _G.buffer
-M.constants = {]]
+M.constants = {]])
f:write(table.concat(constants, ','))
f:write('}\n\n')
-
--- Functions ({"function", msg_id, iface_*, {iface_*, iface_*}}).
-for item in iface:match('Functions%[%] = (%b{})'):sub(2, -2):gmatch('%b{}') do
- local name, msg_id, rt_type, p1_type, p2_type =
- item:match('^{"(.-)"%D+(%d+)%A+iface_(%a+)%A+iface_(%a+)%A+iface_(%a+)')
- name = name:gsub('([a-z])([A-Z])', '%1_%2')
- name = name:gsub('([A-Z])([A-Z][a-z])', '%1_%2')
- name = name:lower()
- if name == 'convert_eo_ls' then name = 'convert_eols' end
- local line = string_format('%s={%d,%d,%d,%d}', name, msg_id, types[rt_type],
- types[p1_type], types[p2_type])
- functions[#functions + 1] = line
-end
-
--- Write functions.
-f:write [[
+f:write([[
---
-- Map of Scintilla function names to tables containing their IDs, return types,
-- wParam types, and lParam types. Types are as follows:
@@ -136,24 +120,13 @@ f:write [[
-- + `8`: String return value.
-- @class table
-- @name functions
-M.functions = {]]
-f:write(table.concat(functions, ','))
-f:write('}\n\n')
-
--- Properties ({"property", get_id, set_id, rt_type, p1_type}).
-for item in iface:match('Properties%[%] = (%b{})'):sub(2, -2):gmatch('%b{}') do
- local name, get_id, set_id, rt_type, p1_type =
- item:match('^{"(.-)"%D+(%d+)%D+(%d+)%A+iface_(%a+)%A+iface_(%a+)')
- name = name:gsub('([a-z])([A-Z])', '%1_%2')
- name = name:gsub('([A-Z])([A-Z][a-z])', '%1_%2')
- name = name:lower()
- properties[#properties + 1] = string_format('%s={%d,%d,%d,%d}', name, get_id,
- set_id, types[rt_type],
- types[p1_type])
+M.functions = {]])
+for i = 1, #functions do
+ f:write(string_format('%s={%d,%d,%d,%d},', functions[i],
+ table_unpack(functions[functions[i]])))
end
-
--- Write properties.
-f:write [[
+f:write('}\n\n')
+f:write([[
---
-- Map of Scintilla property names to table values containing their "get"
-- function IDs, "set" function IDs, return types, and wParam types.
@@ -162,12 +135,13 @@ f:write [[
-- @see functions
-- @class table
-- @name properties
-M.properties = {]]
-f:write(table.concat(properties, ','))
+M.properties = {]])
+for i = 1, #properties do
+ f:write(string_format('%s={%d,%d,%d,%d},', properties[i],
+ table_unpack(properties[properties[i]])))
+end
f:write('}\n\n')
-
--- Write footer.
-f:write [[
+f:write([[
local marker_number, indic_number, list_type = -1, -1, 0
---
@@ -208,6 +182,5 @@ function M.next_user_list_type()
end
return M
-]]
-
+]])
f:close()