mirror of
https://github.com/iofq/nvim-treesitter-main.git
synced 2026-01-23 01:15:17 -06:00
init
This commit is contained in:
commit
5d2b1a868e
11 changed files with 4018 additions and 0 deletions
30
generate-parsers/default.nix
Normal file
30
generate-parsers/default.nix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{ inputs, pkgs, ... }:
|
||||
with pkgs;
|
||||
stdenv.mkDerivation {
|
||||
pname = "generate-parsers";
|
||||
version = "1.0";
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkgs.makeWrapper
|
||||
];
|
||||
|
||||
src = ./generate-parsers.lua;
|
||||
|
||||
unpackPhase = ":";
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
echo "#!${pkgs.luajit}/bin/luajit" > $out/bin/generate-parsers
|
||||
cat $src >> $out/bin/generate-parsers
|
||||
chmod +x $out/bin/generate-parsers
|
||||
|
||||
wrapProgram $out/bin/generate-parsers \
|
||||
--add-flag ${inputs.nvim-treesitter}/lua/nvim-treesitter/parsers.lua \
|
||||
--add-flag "generated.nix" \
|
||||
--prefix PATH : "${
|
||||
pkgs.lib.makeBinPath [
|
||||
pkgs.nurl
|
||||
pkgs.nixfmt
|
||||
]
|
||||
}"
|
||||
'';
|
||||
}
|
||||
71
generate-parsers/generate-parsers.lua
Normal file
71
generate-parsers/generate-parsers.lua
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue