1 #!/usr/bin/env nix-shell
2 #! nix-shell ../../../../../../../. -i python3 -p python3 -p nix
19 def fmt_grammar(grammar
: str) -> str:
20 return "tree-sitter-" + grammar
23 def eval_expr(nixpkgs
: str, expr
: str) -> Any
:
30 ("with import %s {}; %s" % (nixpkgs
, expr
)),
33 stdout
=subprocess
.PIPE
,
35 return json
.loads(p
.stdout
)
38 def check_grammar_exists(nixpkgs
: str, grammar
: str) -> bool:
40 nixpkgs
, f
'lib.hasAttr "{fmt_grammar(grammar)}" tree-sitter-grammars'
44 def build_attr(nixpkgs
, attr
: str) -> str:
47 ["nix-build", "--no-out-link", nixpkgs
, "-A", attr
],
49 stdout
=subprocess
.PIPE
,
56 if __name__
== "__main__":
57 cwd
= dirname(abspath(__file__
))
58 nixpkgs
= abspath(join(cwd
, "../../../../../.."))
60 src_dir
= build_attr(nixpkgs
, "emacs.pkgs.tree-sitter-langs.src")
62 existing
: List
[str] = []
64 grammars
= os
.listdir(join(src_dir
, "repos"))
66 exists
= check_grammar_exists(nixpkgs
, g
)
68 existing
.append(fmt_grammar(g
))
70 sys
.stderr
.write("Missing grammar: " + fmt_grammar(g
) + "\n")
73 with
open(join(cwd
, "default-grammars.json"), mode
="w") as f
:
74 json
.dump(sorted(existing
), f
, indent
=2)