-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlove-api-npp.lua
154 lines (128 loc) · 4.17 KB
/
love-api-npp.lua
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
--[[
This file is part of love-api-npp.
Copyright (C)2016 Justin Dailey <[email protected]>
love-api-npp is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--]]
local love = require("love-api.love_api")
local function reflow(str, limit)
local function wrap(str, limit)
local ws = string.match(str, "^(%s+)") or " "
local indent = ws .. " "
limit = limit or 100
local here = 1
return str:gsub("(%s+)()(%S+)()",
function(sp, st, word, fi)
if fi-here > limit then
here = st - #indent
return "\n" .. indent .. word
end
end)
end
return (str:gsub("[^\n]+",
function(line)
return wrap(line, limit)
end))
end
local function escape(s)
s = string.gsub(s, "&", "&")
s = string.gsub(s, "<", "<")
s = string.gsub(s, ">", ">")
s = string.gsub(s, "'", "'")
s = string.gsub(s, '"', """)
return s
end
local keywords = {}
local function add_keyword(kw)
keywords[#keywords + 1] = {name = kw, text = "\t\t<KeyWord name=\"" .. kw .. "\" />"}
end
local function format_table(t, name)
local indent = " "
local keys = {}
for _, key in ipairs(t) do
keys[#keys + 1] = indent .. indent .. "- " .. name .. "." .. key.name .. " " .. key.type .. ": " .. key.description
end
return table.concat(keys, "\n")
end
local function format_type(t)
local indent = " * "
local s
if t.description then
s = indent .. t.type .. " " .. t.name .. ": " .. t.description
else
s = indent .. t.type .. " " .. t.name
end
if t.type == "table" and t.table then
s = s .. "\n" .. format_table(t.table, t.name)
end
return s
end
function parse_function(func, prefix)
local xml = ""
xml = xml .. "\t\t<KeyWord name=\"" .. prefix .. func.name .. "\" func=\"yes\">\n"
for _, variant in ipairs(func.variants) do
local desc = variant.description or func.description
local args = {}
if variant.arguments then
for _, argument in ipairs(variant.arguments) do
args[#args + 1] = format_type(argument)
end
desc = desc .. "\n\nParameters:\n" .. table.concat(args, "\n")
end
args = {}
if variant.returns then
for _, ret in ipairs(variant.returns) do
args[#args + 1] = format_type(ret)
end
desc = desc .. "\n\nReturns:\n" .. table.concat(args, "\n")
end
xml = xml .. "\t\t\t<Overload retVal=\"\" descr=\"\n" .. reflow(escape(desc)) .. "\">\n"
args = {}
if variant.arguments then
for _, argument in ipairs(variant.arguments) do
local s = argument.type .. " " .. argument.name
if argument.default then
s = s .. " = " .. argument.default
end
xml = xml .. "\t\t\t\t<Param name=\"" .. escape(s) .. "\" />\n"
end
end
xml = xml .. "\t\t\t</Overload>\n"
end
xml = xml .. "\t\t</KeyWord>"
keywords[#keywords + 1] = {name = prefix .. func.name, text = xml}
end
add_keyword("love")
for _, func in ipairs(love.functions) do
parse_function(func, "love.")
end
for _, mod in ipairs(love.modules) do
add_keyword("love." .. mod.name)
for _, func in ipairs(mod.functions) do
parse_function(func, "love." .. mod.name .. ".")
end
end
for _, cb in ipairs(love.callbacks) do
parse_function(cb, "love.")
end
-- Now do it
print("<?xml version=\"1.0\" encoding=\"Windows-1252\" ?>")
print("<NotepadPlus>")
print("\t<!-- Love API v" .. love.version .. " -->")
print("\t<AutoComplete language=\"Lua\">")
print("\t\t<Environment ignoreCase=\"yes\" startFunc=\"(\" stopFunc=\")\" paramSeparator=\",\" terminal=\";\" additionalWordChar=\".\" />")
table.sort(keywords, function(a, b) return a.name < b.name end)
for _, keyword in ipairs(keywords) do
print(keyword.text)
end
print("\t</AutoComplete>")
print("</NotepadPlus>")