mirror of
https://github.com/iofq/nvim-treesitter-main.git
synced 2026-01-23 01:15:17 -06:00
71 lines
1.9 KiB
Lua
71 lines
1.9 KiB
Lua
local function fmt_grammar(grammar)
|
|
local lines = {
|
|
string.format('%s = buildGrammar {', grammar.language),
|
|
string.format('language = "%s";', grammar.language),
|
|
string.format('version = "%s";', grammar.version),
|
|
string.format('src = %s;', grammar.src),
|
|
string.format('meta.homepage = "%s";', grammar.meta.homepage),
|
|
}
|
|
if grammar.generate then table.insert(lines, string.format('generate = %s;', grammar.generate)) end
|
|
if grammar.location then table.insert(lines, string.format('location = "%s";', grammar.location)) end
|
|
|
|
table.insert(lines, "};")
|
|
return table.concat(lines, "\n")
|
|
end
|
|
|
|
local function generate_grammars(g)
|
|
local output = {}
|
|
for name, p in pairs(g) do
|
|
if p.install_info then
|
|
local out = assert(
|
|
io.popen(
|
|
string.format(
|
|
"nurl %s %s",
|
|
p.install_info.url,
|
|
p.install_info.revision
|
|
)
|
|
)
|
|
)
|
|
local grammar = {
|
|
version = "0.0.0+rev=" .. p.install_info.revision,
|
|
language = name,
|
|
src = out:read("*a"),
|
|
meta = {
|
|
homepage = p.install_info.url,
|
|
},
|
|
}
|
|
out:close()
|
|
|
|
if p.install_info.generate then
|
|
grammar.generate = p.install_info.generate
|
|
end
|
|
if p.install_info.location then
|
|
grammar.location = p.install_info.location
|
|
end
|
|
|
|
table.insert(output, fmt_grammar(grammar))
|
|
end
|
|
end
|
|
table.sort(output)
|
|
return table.concat(output)
|
|
end
|
|
|
|
local function header()
|
|
local out = assert(io.popen("nurl -Ls ','"):read("*a"))
|
|
return string.format([[
|
|
# This file was generated by generate-parsers.lua for nvim-treesitter-main
|
|
{ buildGrammar, %s }: {
|
|
]], out)
|
|
end
|
|
|
|
local parsers = dofile(arg[1])
|
|
local output_path = arg[2]
|
|
local file = assert(io.open(output_path, "w"))
|
|
|
|
file:write(header())
|
|
file:write(generate_grammars(parsers))
|
|
file:write("}") -- footer
|
|
|
|
file:close()
|
|
|
|
assert(os.execute("nixfmt " .. output_path))
|