aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/gen_iface.lua
blob: 983f09135c2a48f10cade4b655b7d6328f797e29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/lua
-- Copyright 2007-2013 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 types = {
  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'

f = io.open('../core/iface.lua', 'wb')

-- Write header.
f:write [=[
-- Copyright 2007-2013 Mitchell mitchell.att.foicica.com. See LICENSE.

local M = {}

--[[ This comment is for LuaDoc.
---
-- Scintilla constants, functions, and properties.
-- Do not modify anything in this module. Doing so will have unpredictable
-- 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)
  fielddoc[#fielddoc + 1] = string_format('-- * `%s.%s` %d', s, event, value)
end

-- Write constants.
f:write [[
---
-- Map of Scintilla constant names to their numeric values.
-- @class table
-- @name 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 [[
---
-- Map of Scintilla function names to tables containing their IDs, return types,
-- wParam types, and lParam types. Types are as follows:
--
--   + `0`: Void.
--   + `1`: Integer.
--   + `2`: Length of the given lParam string.
--   + `3`: Integer position.
--   + `4`: Color, in "0xBBGGRR" format.
--   + `5`: Boolean `true` or `false`.
--   + `6`: Bitmask of Scintilla key modifiers and a key value.
--   + `7`: String parameter.
--   + `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])
end

-- Write properties.
f:write [[
---
-- Map of Scintilla property names to table values containing their "get"
-- function IDs, "set" function IDs, return types, and wParam types.
-- The wParam type will be non-zero if the property is indexable.
-- Types are the same as in the `functions` table.
-- @see functions
-- @class table
-- @name properties
M.properties = {]]
f:write(table.concat(properties, ','))
f:write('}\n\n')

-- Write footer.
f:write [[
local marker_number, indic_number, list_type = -1, -1, 0

---
-- Returns a unique marker number for use with `buffer.marker_define()`.
-- Use this function for custom markers in order to prevent clashes with
-- identifiers of other custom markers.
-- @usage local marknum = _SCINTILLA.next_marker_number()
-- @see buffer.marker_define
-- @name next_marker_number
function M.next_marker_number()
  marker_number = marker_number + 1
  return marker_number
end

---
-- Returns a unique indicator number for use with custom indicators.
-- Use this function for custom indicators in order to prevent clashes with
-- identifiers of other custom indicators.
-- @usage local indic_num = _SCINTILLA.next_indic_number()
-- @see buffer.indic_style
-- @name next_indic_number
function M.next_indic_number()
  indic_number = indic_number + 1
  return indic_number
end

---
-- Returns a unique user list identier number for use with
-- `buffer.user_list_show()`.
-- Use this function for custom user lists in order to prevent clashes with
-- list identifiers of other custom user lists.
-- @usage local list_type = _SCINTILLA.next_user_list_type()
-- @see buffer.user_list_show
-- @name next_user_list_type
function M.next_user_list_type()
  list_type = list_type + 1
  return list_type
end

return M
]]

f:close()

f = io.open('../core/._SCINTILLA.luadoc', 'wb')
f:write [[
-- Copyright 2007-2013 Mitchell mitchell.att.foicica.com. See LICENSE.
-- This is a DUMMY FILE used for making Adeptsense for built-in constants in the
-- global _SCINTILLA.constants table.

]]
f:write(table.concat(fielddoc, '\n'))
f:write('\n')
f:close()