2023-05-24 13:37:59 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
|
|
|
#!nix-shell -i python3 -p python3
|
|
|
|
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
parsers = {}
|
|
|
|
dir = Path(__file__).parent
|
2024-06-05 15:53:02 +00:00
|
|
|
regex = re.compile(r"^TREESITTER_([A-Z_]+)_(URL|SHA256)\s+(.+)$")
|
2023-05-24 13:37:59 +00:00
|
|
|
|
|
|
|
src = subprocess.check_output(
|
|
|
|
[
|
|
|
|
"nix-build",
|
|
|
|
dir.parent.parent.parent.parent,
|
|
|
|
"-A",
|
|
|
|
"neovim-unwrapped.src",
|
|
|
|
"--no-out-link",
|
|
|
|
],
|
|
|
|
text=True,
|
|
|
|
).strip()
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
for line in open(f"{src}/cmake.deps/deps.txt"):
|
|
|
|
m = regex.fullmatch(line.strip())
|
2023-05-24 13:37:59 +00:00
|
|
|
if m is None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
lang = m[1].lower()
|
|
|
|
ty = m[2]
|
|
|
|
val = m[3]
|
|
|
|
|
|
|
|
if not lang in parsers:
|
|
|
|
parsers[lang] = {}
|
|
|
|
parsers[lang][ty] = val
|
|
|
|
|
|
|
|
with open(dir / "treesitter-parsers.nix", "w") as f:
|
|
|
|
f.write("{ fetchurl }:\n\n{\n")
|
|
|
|
for lang, src in parsers.items():
|
|
|
|
f.write(
|
2024-06-05 15:53:02 +00:00
|
|
|
f""" {lang}.src = fetchurl {{
|
2023-05-24 13:37:59 +00:00
|
|
|
url = "{src["URL"]}";
|
|
|
|
hash = "sha256:{src["SHA256"]}";
|
|
|
|
}};
|
|
|
|
"""
|
|
|
|
)
|
|
|
|
f.write("}\n")
|