forked from orbitalquark/scintillua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_lexer_props.lua
executable file
·59 lines (53 loc) · 1.7 KB
/
gen_lexer_props.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
#!/usr/bin/lua
local format, concat = string.format, table.concat
-- Do not glob these files. (e.g. *.foo)
local noglobs = {
Dockerfile = true,
GNUmakefile = true,
Makefile = true,
makefile = true,
Rakefile = true,
['Rout.save'] = true,
['Rout.fail'] = true,
}
local alt_name = {
actionscript = 'flash',
ansi_c = 'c',
dmd = 'd',
javascript = 'js',
python = 'py',
rstats = 'r',
ruby = 'rb',
}
-- Process file patterns and lexer definitions from Textadept.
local f = io.open('../textadept/modules/textadept/file_types.lua')
local definitions = f:read('*all'):match('M%.extensions = (%b{})')
f:close()
local output = {'# Lexer definitions ('}
local lexer, ext, last_lexer
local exts = {}
for ext, lexer in definitions:gmatch("([^,'%]]+)'?%]?='([%w_]+)'") do
if lexer ~= last_lexer and #exts > 0 then
local name = alt_name[last_lexer] or last_lexer
output[#output + 1] = format('file.patterns.%s=%s', name,
concat(exts, ';'))
output[#output + 1] = format('lexer.$(file.patterns.%s)=lpeg_%s', name,
last_lexer)
exts = {}
end
exts[#exts + 1] = not noglobs[ext] and '*.'..ext or ext
last_lexer = lexer
end
local name = alt_name[last_lexer] or last_lexer
output[#output + 1] = format('file.patterns.%s=%s', name, concat(exts, ';'))
output[#output + 1] = format('lexer.$(file.patterns.%s)=lpeg_%s', name,
last_lexer)
output[#output + 1] = '# )'
-- Write to lpeg.properties.
f = io.open('lexers/lpeg.properties')
local text = f:read('*all')
text = text:gsub('# Lexer definitions %b()', table.concat(output, '\n'), 1)
f:close()
f = io.open('lexers/lpeg.properties', 'wb')
f:write(text)
f:close()