2021-12-21 02:18:32 +00:00
|
|
|
{ writeShellScript
|
|
|
|
, nix-prefetch-git
|
|
|
|
, formats
|
|
|
|
, lib
|
|
|
|
, curl
|
|
|
|
, jq
|
|
|
|
, xe
|
|
|
|
, src
|
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-03-16 09:55:35 +00:00
|
|
|
# Grammar list:
|
|
|
|
# https://github.com/tree-sitter/tree-sitter/blob/master/docs/index.md
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
let
|
2021-01-05 17:05:55 +00:00
|
|
|
# Grammars we want to fetch from the tree-sitter github orga
|
|
|
|
knownTreeSitterOrgGrammarRepos = [
|
|
|
|
"tree-sitter-javascript"
|
|
|
|
"tree-sitter-c"
|
|
|
|
"tree-sitter-swift"
|
|
|
|
"tree-sitter-json"
|
|
|
|
"tree-sitter-cpp"
|
|
|
|
"tree-sitter-ruby"
|
|
|
|
"tree-sitter-go"
|
|
|
|
"tree-sitter-c-sharp"
|
|
|
|
"tree-sitter-python"
|
|
|
|
"tree-sitter-typescript"
|
|
|
|
"tree-sitter-rust"
|
|
|
|
"tree-sitter-bash"
|
|
|
|
"tree-sitter-php"
|
|
|
|
"tree-sitter-java"
|
|
|
|
"tree-sitter-scala"
|
|
|
|
"tree-sitter-ocaml"
|
|
|
|
"tree-sitter-julia"
|
|
|
|
"tree-sitter-agda"
|
|
|
|
"tree-sitter-fluent"
|
|
|
|
"tree-sitter-html"
|
|
|
|
"tree-sitter-haskell"
|
|
|
|
"tree-sitter-regex"
|
|
|
|
"tree-sitter-css"
|
|
|
|
"tree-sitter-verilog"
|
|
|
|
"tree-sitter-jsdoc"
|
|
|
|
"tree-sitter-ql"
|
|
|
|
"tree-sitter-embedded-template"
|
2021-05-28 09:39:13 +00:00
|
|
|
"tree-sitter-tsq"
|
2022-04-27 09:35:20 +00:00
|
|
|
"tree-sitter-toml"
|
2021-01-05 17:05:55 +00:00
|
|
|
];
|
|
|
|
knownTreeSitterOrgGrammarReposJson = jsonFile "known-tree-sitter-org-grammar-repos" knownTreeSitterOrgGrammarRepos;
|
|
|
|
|
|
|
|
# repos of the tree-sitter github orga we want to ignore (not grammars)
|
|
|
|
ignoredTreeSitterOrgRepos = [
|
|
|
|
"tree-sitter"
|
|
|
|
"tree-sitter-cli"
|
|
|
|
# this is the haskell language bindings, tree-sitter-haskell is the grammar
|
|
|
|
"haskell-tree-sitter"
|
|
|
|
# this is the ruby language bindings, tree-sitter-ruby is the grammar
|
|
|
|
"ruby-tree-sitter"
|
|
|
|
# this is the (unmaintained) rust language bindings, tree-sitter-rust is the grammar
|
|
|
|
"rust-tree-sitter"
|
|
|
|
# this is the nodejs language bindings, tree-sitter-javascript is the grammar
|
|
|
|
"node-tree-sitter"
|
|
|
|
# this is the python language bindings, tree-sitter-python is the grammar
|
|
|
|
"py-tree-sitter"
|
|
|
|
# afl fuzzing for tree sitter
|
|
|
|
"afl-tree-sitter"
|
|
|
|
# archived
|
|
|
|
"highlight-schema"
|
|
|
|
# website
|
|
|
|
"tree-sitter.github.io"
|
2021-03-16 09:55:35 +00:00
|
|
|
# not maintained
|
|
|
|
"tree-sitter-razor"
|
2021-05-28 09:39:13 +00:00
|
|
|
# rust library for constructing arbitrary graph structures from source code
|
|
|
|
"tree-sitter-graph"
|
2021-01-05 17:05:55 +00:00
|
|
|
];
|
|
|
|
ignoredTreeSitterOrgReposJson = jsonFile "ignored-tree-sitter-org-repos" ignoredTreeSitterOrgRepos;
|
|
|
|
|
|
|
|
# Additional grammars that are not in the official github orga.
|
|
|
|
# If you need a grammar that already exists in the official orga,
|
|
|
|
# make sure to give it a different name.
|
|
|
|
otherGrammars = {
|
2021-12-06 16:07:01 +00:00
|
|
|
"tree-sitter-beancount" = {
|
|
|
|
orga = "polarmutex";
|
|
|
|
repo = "tree-sitter-beancount";
|
|
|
|
};
|
2021-09-22 15:38:15 +00:00
|
|
|
"tree-sitter-clojure" = {
|
|
|
|
orga = "sogaiu";
|
|
|
|
repo = "tree-sitter-clojure";
|
|
|
|
};
|
2021-08-08 23:34:03 +00:00
|
|
|
"tree-sitter-comment" = {
|
|
|
|
orga = "stsewd";
|
|
|
|
repo = "tree-sitter-comment";
|
|
|
|
};
|
2021-09-22 15:38:15 +00:00
|
|
|
"tree-sitter-dart" = {
|
|
|
|
orga = "usernobody14";
|
|
|
|
repo = "tree-sitter-dart";
|
|
|
|
};
|
|
|
|
"tree-sitter-elisp" = {
|
|
|
|
orga = "wilfred";
|
|
|
|
repo = "tree-sitter-elisp";
|
|
|
|
};
|
2021-01-17 00:15:33 +00:00
|
|
|
"tree-sitter-nix" = {
|
|
|
|
orga = "cstrahan";
|
|
|
|
repo = "tree-sitter-nix";
|
|
|
|
};
|
2021-07-14 22:03:04 +00:00
|
|
|
"tree-sitter-latex" = {
|
|
|
|
orga = "latex-lsp";
|
|
|
|
repo = "tree-sitter-latex";
|
|
|
|
};
|
2021-01-05 17:05:55 +00:00
|
|
|
"tree-sitter-lua" = {
|
2022-01-27 00:19:43 +00:00
|
|
|
orga = "MunifTanjim";
|
2021-01-05 17:05:55 +00:00
|
|
|
repo = "tree-sitter-lua";
|
|
|
|
};
|
2021-03-16 09:55:35 +00:00
|
|
|
"tree-sitter-fennel" = {
|
|
|
|
orga = "travonted";
|
|
|
|
repo = "tree-sitter-fennel";
|
|
|
|
};
|
2021-10-17 02:12:59 +00:00
|
|
|
"tree-sitter-make" = {
|
|
|
|
orga = "alemuller";
|
|
|
|
repo = "tree-sitter-make";
|
|
|
|
};
|
2021-03-16 09:55:35 +00:00
|
|
|
"tree-sitter-markdown" = {
|
2022-01-26 04:04:25 +00:00
|
|
|
orga = "MDeiml";
|
2021-03-16 09:55:35 +00:00
|
|
|
repo = "tree-sitter-markdown";
|
|
|
|
};
|
2021-09-22 15:38:15 +00:00
|
|
|
"tree-sitter-rst" = {
|
|
|
|
orga = "stsewd";
|
|
|
|
repo = "tree-sitter-rst";
|
|
|
|
};
|
2021-03-16 09:55:35 +00:00
|
|
|
"tree-sitter-svelte" = {
|
|
|
|
orga = "Himujjal";
|
|
|
|
repo = "tree-sitter-svelte";
|
|
|
|
};
|
2021-09-22 15:38:15 +00:00
|
|
|
"tree-sitter-vim" = {
|
|
|
|
orga = "vigoux";
|
|
|
|
repo = "tree-sitter-viml";
|
|
|
|
};
|
2021-03-16 09:55:35 +00:00
|
|
|
"tree-sitter-yaml" = {
|
|
|
|
orga = "ikatyang";
|
|
|
|
repo = "tree-sitter-yaml";
|
|
|
|
};
|
2021-05-28 09:39:13 +00:00
|
|
|
"tree-sitter-zig" = {
|
2021-09-22 15:38:15 +00:00
|
|
|
orga = "maxxnino";
|
2021-05-28 09:39:13 +00:00
|
|
|
repo = "tree-sitter-zig";
|
|
|
|
};
|
2021-08-08 23:34:03 +00:00
|
|
|
"tree-sitter-fish" = {
|
|
|
|
orga = "ram02z";
|
|
|
|
repo = "tree-sitter-fish";
|
|
|
|
};
|
2021-09-18 10:52:07 +00:00
|
|
|
"tree-sitter-dot" = {
|
|
|
|
orga = "rydesun";
|
|
|
|
repo = "tree-sitter-dot";
|
|
|
|
};
|
2021-10-01 09:20:50 +00:00
|
|
|
"tree-sitter-norg" = {
|
|
|
|
orga = "nvim-neorg";
|
|
|
|
repo = "tree-sitter-norg";
|
|
|
|
};
|
2021-12-21 02:18:32 +00:00
|
|
|
"tree-sitter-commonlisp" = {
|
|
|
|
orga = "thehamsta";
|
|
|
|
repo = "tree-sitter-commonlisp";
|
|
|
|
};
|
|
|
|
"tree-sitter-cuda" = {
|
|
|
|
orga = "thehamsta";
|
|
|
|
repo = "tree-sitter-cuda";
|
|
|
|
};
|
|
|
|
"tree-sitter-glsl" = {
|
|
|
|
orga = "thehamsta";
|
|
|
|
repo = "tree-sitter-glsl";
|
|
|
|
};
|
|
|
|
"tree-sitter-dockerfile" = {
|
|
|
|
orga = "camdencheek";
|
|
|
|
repo = "tree-sitter-dockerfile";
|
|
|
|
};
|
|
|
|
"tree-sitter-ledger" = {
|
|
|
|
orga = "cbarrete";
|
|
|
|
repo = "tree-sitter-ledger";
|
|
|
|
};
|
|
|
|
"tree-sitter-gomod" = {
|
|
|
|
orga = "camdencheek";
|
|
|
|
repo = "tree-sitter-go-mod";
|
|
|
|
};
|
|
|
|
"tree-sitter-graphql" = {
|
|
|
|
orga = "bkegley";
|
|
|
|
repo = "tree-sitter-graphql";
|
|
|
|
};
|
2022-04-27 09:35:20 +00:00
|
|
|
"tree-sitter-pgn" = {
|
|
|
|
orga = "rolandwalker";
|
|
|
|
repo = "tree-sitter-pgn";
|
|
|
|
};
|
2021-12-21 02:18:32 +00:00
|
|
|
"tree-sitter-perl" = {
|
|
|
|
orga = "ganezdragon";
|
|
|
|
repo = "tree-sitter-perl";
|
|
|
|
};
|
|
|
|
"tree-sitter-kotlin" = {
|
|
|
|
orga = "fwcd";
|
|
|
|
repo = "tree-sitter-kotlin";
|
|
|
|
};
|
|
|
|
"tree-sitter-scss" = {
|
|
|
|
orga = "serenadeai";
|
|
|
|
repo = "tree-sitter-scss";
|
|
|
|
};
|
|
|
|
"tree-sitter-erlang" = {
|
|
|
|
orga = "abstractmachineslab";
|
|
|
|
repo = "tree-sitter-erlang";
|
|
|
|
};
|
|
|
|
"tree-sitter-elixir" = {
|
|
|
|
orga = "elixir-lang";
|
|
|
|
repo = "tree-sitter-elixir";
|
|
|
|
};
|
|
|
|
"tree-sitter-surface" = {
|
|
|
|
orga = "connorlay";
|
|
|
|
repo = "tree-sitter-surface";
|
|
|
|
};
|
|
|
|
"tree-sitter-heex" = {
|
|
|
|
orga = "connorlay";
|
|
|
|
repo = "tree-sitter-heex";
|
|
|
|
};
|
|
|
|
"tree-sitter-supercollider" = {
|
|
|
|
orga = "madskjeldgaard";
|
|
|
|
repo = "tree-sitter-supercollider";
|
|
|
|
};
|
|
|
|
"tree-sitter-tlaplus" = {
|
|
|
|
orga = "tlaplus-community";
|
|
|
|
repo = "tree-sitter-tlaplus";
|
|
|
|
};
|
|
|
|
"tree-sitter-glimmer" = {
|
|
|
|
orga = "alexlafroscia";
|
|
|
|
repo = "tree-sitter-glimmer";
|
|
|
|
};
|
|
|
|
"tree-sitter-pug" = {
|
|
|
|
orga = "zealot128";
|
|
|
|
repo = "tree-sitter-pug";
|
|
|
|
};
|
|
|
|
"tree-sitter-vue" = {
|
|
|
|
orga = "ikatyang";
|
|
|
|
repo = "tree-sitter-vue";
|
|
|
|
};
|
|
|
|
"tree-sitter-elm" = {
|
|
|
|
orga = "elm-tooling";
|
|
|
|
repo = "tree-sitter-elm";
|
|
|
|
};
|
|
|
|
"tree-sitter-yang" = {
|
|
|
|
orga = "hubro";
|
|
|
|
repo = "tree-sitter-yang";
|
|
|
|
};
|
|
|
|
"tree-sitter-query" = {
|
|
|
|
orga = "nvim-treesitter";
|
|
|
|
repo = "tree-sitter-query";
|
|
|
|
};
|
|
|
|
"tree-sitter-sparql" = {
|
|
|
|
orga = "bonabeavis";
|
|
|
|
repo = "tree-sitter-sparql";
|
|
|
|
};
|
|
|
|
"tree-sitter-gdscript" = {
|
|
|
|
orga = "prestonknopp";
|
|
|
|
repo = "tree-sitter-gdscript";
|
|
|
|
};
|
|
|
|
"tree-sitter-godot-resource" = {
|
|
|
|
orga = "prestonknopp";
|
|
|
|
repo = "tree-sitter-godot-resource";
|
|
|
|
};
|
|
|
|
"tree-sitter-turtle" = {
|
|
|
|
orga = "bonabeavis";
|
|
|
|
repo = "tree-sitter-turtle";
|
|
|
|
};
|
|
|
|
"tree-sitter-devicetree" = {
|
|
|
|
orga = "joelspadin";
|
|
|
|
repo = "tree-sitter-devicetree";
|
|
|
|
};
|
|
|
|
"tree-sitter-r" = {
|
|
|
|
orga = "r-lib";
|
|
|
|
repo = "tree-sitter-r";
|
|
|
|
};
|
|
|
|
"tree-sitter-bibtex" = {
|
|
|
|
orga = "latex-lsp";
|
|
|
|
repo = "tree-sitter-bibtex";
|
|
|
|
};
|
|
|
|
"tree-sitter-fortran" = {
|
|
|
|
orga = "stadelmanma";
|
|
|
|
repo = "tree-sitter-fortran";
|
|
|
|
};
|
|
|
|
"tree-sitter-cmake" = {
|
|
|
|
orga = "uyha";
|
|
|
|
repo = "tree-sitter-cmake";
|
|
|
|
};
|
2022-04-27 09:35:20 +00:00
|
|
|
"tree-sitter-janet-simple" = {
|
|
|
|
orga = "sogaiu";
|
|
|
|
repo = "tree-sitter-janet-simple";
|
|
|
|
};
|
2021-12-21 02:18:32 +00:00
|
|
|
"tree-sitter-json5" = {
|
|
|
|
orga = "joakker";
|
|
|
|
repo = "tree-sitter-json5";
|
|
|
|
};
|
|
|
|
"tree-sitter-pioasm" = {
|
|
|
|
orga = "leo60228";
|
|
|
|
repo = "tree-sitter-pioasm";
|
|
|
|
};
|
|
|
|
"tree-sitter-hjson" = {
|
|
|
|
orga = "winston0410";
|
|
|
|
repo = "tree-sitter-hjson";
|
|
|
|
};
|
|
|
|
"tree-sitter-llvm" = {
|
|
|
|
orga = "benwilliamgraham";
|
|
|
|
repo = "tree-sitter-llvm";
|
|
|
|
};
|
|
|
|
"tree-sitter-http" = {
|
|
|
|
orga = "ntbbloodbath";
|
|
|
|
repo = "tree-sitter-http";
|
|
|
|
};
|
|
|
|
"tree-sitter-prisma" = {
|
|
|
|
orga = "victorhqc";
|
|
|
|
repo = "tree-sitter-prisma";
|
|
|
|
};
|
2022-02-10 20:34:41 +00:00
|
|
|
"tree-sitter-org-nvim" = {
|
2022-01-22 01:22:15 +00:00
|
|
|
orga = "milisims";
|
|
|
|
repo = "tree-sitter-org";
|
|
|
|
};
|
2022-03-30 09:31:56 +00:00
|
|
|
"tree-sitter-hcl" = {
|
|
|
|
orga = "MichaHoffmann";
|
|
|
|
repo = "tree-sitter-hcl";
|
|
|
|
};
|
2022-04-27 09:35:20 +00:00
|
|
|
"tree-sitter-scheme" = {
|
|
|
|
orga = "6cdh";
|
|
|
|
repo = "tree-sitter-scheme";
|
|
|
|
};
|
2021-01-05 17:05:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
allGrammars =
|
|
|
|
let
|
|
|
|
treeSitterOrgaGrammars =
|
2021-12-21 02:18:32 +00:00
|
|
|
lib.listToAttrs (map
|
|
|
|
(repo:
|
|
|
|
{
|
|
|
|
name = repo;
|
|
|
|
value = {
|
|
|
|
orga = "tree-sitter";
|
|
|
|
inherit repo;
|
|
|
|
};
|
|
|
|
})
|
|
|
|
knownTreeSitterOrgGrammarRepos);
|
2021-01-05 17:05:55 +00:00
|
|
|
|
|
|
|
in
|
2021-12-21 02:18:32 +00:00
|
|
|
mergeAttrsUnique otherGrammars treeSitterOrgaGrammars;
|
2021-01-05 17:05:55 +00:00
|
|
|
|
|
|
|
# TODO: move to lib
|
|
|
|
mergeAttrsUnique = left: right:
|
|
|
|
let intersect = lib.intersectLists (lib.attrNames left) (lib.attrNames right); in
|
|
|
|
assert
|
2021-12-21 02:18:32 +00:00
|
|
|
lib.assertMsg (intersect == [ ])
|
|
|
|
(lib.concatStringsSep "\n" [
|
|
|
|
"mergeAttrsUnique: keys in attrset overlapping:"
|
|
|
|
"left: ${lib.generators.toPretty {} (lib.getAttrs intersect left)}"
|
|
|
|
"right: ${lib.generators.toPretty {} (lib.getAttrs intersect right)}"
|
|
|
|
]);
|
2021-01-05 17:05:55 +00:00
|
|
|
left // right;
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-12-21 02:18:32 +00:00
|
|
|
jsonFile = name: val: (formats.json { }).generate name val;
|
2021-01-05 17:05:55 +00:00
|
|
|
|
|
|
|
# check the tree-sitter orga repos
|
|
|
|
checkTreeSitterRepos = writeShellScript "get-grammars.sh" ''
|
2020-04-24 23:36:52 +00:00
|
|
|
set -euo pipefail
|
2021-01-05 17:05:55 +00:00
|
|
|
res=$(${jq}/bin/jq \
|
|
|
|
--slurpfile known "${knownTreeSitterOrgGrammarReposJson}" \
|
|
|
|
--slurpfile ignore "${ignoredTreeSitterOrgReposJson}" \
|
|
|
|
'. - ($known[0] + $ignore[0])' \
|
|
|
|
)
|
|
|
|
if [ ! "$res" == "[]" ]; then
|
|
|
|
echo "These repositories are neither known nor ignored:" 1>&2
|
|
|
|
echo "$res" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
urlEscape = x: x;
|
|
|
|
|
|
|
|
# generic bash script to find the latest github release for a repo
|
2021-01-05 17:05:55 +00:00
|
|
|
latestGithubRelease = { orga, repo }: writeShellScript "latest-github-release" ''
|
2020-04-24 23:36:52 +00:00
|
|
|
set -euo pipefail
|
2022-01-13 20:06:32 +00:00
|
|
|
|
|
|
|
args=( '--silent' )
|
2022-01-25 03:21:06 +00:00
|
|
|
if [ -n "''${GITHUB_TOKEN:-}" ]; then
|
2022-01-13 20:06:32 +00:00
|
|
|
args+=( "-H" "Authorization: token ''${GITHUB_TOKEN}" )
|
|
|
|
fi
|
|
|
|
args+=( "https://api.github.com/repos/${urlEscape orga}/${urlEscape repo}/releases/latest" )
|
|
|
|
|
|
|
|
res=$(${curl}/bin/curl "''${args[@]}")
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
if [[ "$(printf "%s" "$res" | ${jq}/bin/jq '.message?')" =~ "rate limit" ]]; then
|
2020-04-24 23:36:52 +00:00
|
|
|
echo "rate limited" >&2
|
|
|
|
fi
|
2022-03-30 09:31:56 +00:00
|
|
|
release="$(printf "%s" "$res" | ${jq}/bin/jq -r '.tag_name' | tr -d \")"
|
2020-04-24 23:36:52 +00:00
|
|
|
# github sometimes returns an empty list even tough there are releases
|
|
|
|
if [ "$release" = "null" ]; then
|
2021-01-05 17:05:55 +00:00
|
|
|
echo "uh-oh, latest for ${orga + "/" + repo} is not there, using HEAD" >&2
|
2020-04-24 23:36:52 +00:00
|
|
|
release="HEAD"
|
|
|
|
fi
|
|
|
|
echo "$release"
|
|
|
|
'';
|
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
# find the latest repos of a github organization
|
|
|
|
latestGithubRepos = { orga }: writeShellScript "latest-github-repos" ''
|
|
|
|
set -euo pipefail
|
2022-01-13 20:06:32 +00:00
|
|
|
|
|
|
|
args=( '--silent' )
|
2022-01-25 03:21:06 +00:00
|
|
|
if [ -n "''${GITHUB_TOKEN:-}" ]; then
|
2022-01-13 20:06:32 +00:00
|
|
|
args+=( "-H" "Authorization: token ''${GITHUB_TOKEN}" )
|
|
|
|
fi
|
|
|
|
args+=( 'https://api.github.com/orgs/${urlEscape orga}/repos?per_page=100' )
|
|
|
|
|
|
|
|
res=$(${curl}/bin/curl "''${args[@]}")
|
2021-01-05 17:05:55 +00:00
|
|
|
|
|
|
|
if [[ "$(printf "%s" "$res" | ${jq}/bin/jq '.message?')" =~ "rate limit" ]]; then
|
2022-01-25 03:21:06 +00:00
|
|
|
echo "rate limited" >&2
|
|
|
|
exit 1
|
|
|
|
elif [[ "$(printf "%s" "$res" | ${jq}/bin/jq '.message?')" =~ "Bad credentials" ]]; then
|
|
|
|
echo "bad credentials" >&2
|
|
|
|
exit 1
|
2021-01-05 17:05:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
printf "%s" "$res" | ${jq}/bin/jq 'map(.name)' \
|
|
|
|
|| echo "failed $res"
|
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
# update one tree-sitter grammar repo and print their nix-prefetch-git output
|
2021-01-05 17:05:55 +00:00
|
|
|
updateGrammar = { orga, repo }: writeShellScript "update-grammar.sh" ''
|
2020-04-24 23:36:52 +00:00
|
|
|
set -euo pipefail
|
2021-01-05 17:05:55 +00:00
|
|
|
latest="$(${latestGithubRelease { inherit orga repo; }})"
|
|
|
|
echo "Fetching latest release ($latest) of ${repo} …" >&2
|
2020-04-24 23:36:52 +00:00
|
|
|
${nix-prefetch-git}/bin/nix-prefetch-git \
|
|
|
|
--quiet \
|
|
|
|
--no-deepClone \
|
2021-01-05 17:05:55 +00:00
|
|
|
--url "https://github.com/${urlEscape orga}/${urlEscape repo}" \
|
2020-04-24 23:36:52 +00:00
|
|
|
--rev "$latest"
|
2021-12-21 02:18:32 +00:00
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-01-05 17:05:55 +00:00
|
|
|
foreachSh = attrs: f:
|
|
|
|
lib.concatMapStringsSep "\n" f
|
2021-12-21 02:18:32 +00:00
|
|
|
(lib.mapAttrsToList (k: v: { name = k; } // v) attrs);
|
2021-01-05 17:05:55 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
update-all-grammars = writeShellScript "update-all-grammars.sh" ''
|
|
|
|
set -euo pipefail
|
2021-01-05 17:05:55 +00:00
|
|
|
echo "fetching list of grammars" 1>&2
|
|
|
|
treeSitterRepos=$(${latestGithubRepos { orga = "tree-sitter"; }})
|
|
|
|
echo "checking the tree-sitter repo list against the grammars we know" 1>&2
|
|
|
|
printf '%s' "$treeSitterRepos" | ${checkTreeSitterRepos}
|
2020-04-24 23:36:52 +00:00
|
|
|
outputDir="${toString ./.}/grammars"
|
2021-01-05 17:05:55 +00:00
|
|
|
echo "writing files to $outputDir" 1>&2
|
2020-04-24 23:36:52 +00:00
|
|
|
mkdir -p "$outputDir"
|
2021-01-05 17:05:55 +00:00
|
|
|
${foreachSh allGrammars
|
|
|
|
({name, orga, repo}: ''${updateGrammar { inherit orga repo; }} > $outputDir/${name}.json'')}
|
2022-01-25 03:21:06 +00:00
|
|
|
( echo "{ lib }:"
|
|
|
|
echo "{"
|
2021-01-05 17:05:55 +00:00
|
|
|
${foreachSh allGrammars
|
|
|
|
({name, ...}: ''
|
|
|
|
# indentation hack
|
2021-12-06 16:07:01 +00:00
|
|
|
printf " %s = lib.importJSON ./%s.json;\n" "${name}" "${name}"'')}
|
2020-04-24 23:36:52 +00:00
|
|
|
echo "}" ) \
|
|
|
|
> "$outputDir/default.nix"
|
|
|
|
'';
|
|
|
|
|
2021-12-21 02:18:32 +00:00
|
|
|
in
|
|
|
|
update-all-grammars
|