-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
tree-sitter-grammars: Enable grammar testing #391520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: staging
Are you sure you want to change the base?
Changes from all commits
a709b70
4a3c21b
524d5d8
7be9c3a
82411a8
40f8ae1
b5fe6bf
727a4e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,54 @@ | ||
| [ | ||
| "tree-sitter-bash", | ||
| "tree-sitter-beancount", | ||
| "tree-sitter-bibtex", | ||
| "tree-sitter-c", | ||
| "tree-sitter-c-sharp", | ||
| "tree-sitter-cpp", | ||
| "tree-sitter-clojure", | ||
| "tree-sitter-cmake", | ||
| "tree-sitter-comment", | ||
| "tree-sitter-css", | ||
| "tree-sitter-dart", | ||
| "tree-sitter-dockerfile", | ||
| "tree-sitter-elixir", | ||
| "tree-sitter-elm", | ||
| "tree-sitter-erlang", | ||
| "tree-sitter-fennel", | ||
| "tree-sitter-fortran", | ||
| "tree-sitter-gdscript", | ||
| "tree-sitter-glsl", | ||
| "tree-sitter-go", | ||
| "tree-sitter-haskell", | ||
| "tree-sitter-hcl", | ||
| "tree-sitter-heex", | ||
| "tree-sitter-html", | ||
| "tree-sitter-janet-simple", | ||
| "tree-sitter-java", | ||
| "tree-sitter-javascript", | ||
| "tree-sitter-jsdoc", | ||
| "tree-sitter-json", | ||
| "tree-sitter-jsonnet", | ||
| "tree-sitter-julia", | ||
| "tree-sitter-nix", | ||
| "tree-sitter-kotlin", | ||
| "tree-sitter-llvm", | ||
| "tree-sitter-lua", | ||
| "tree-sitter-markdown", | ||
| "tree-sitter-ocaml", | ||
| "tree-sitter-perl", | ||
| "tree-sitter-ocaml-interface", | ||
| "tree-sitter-pgn", | ||
| "tree-sitter-php", | ||
| "tree-sitter-prisma", | ||
| "tree-sitter-python", | ||
| "tree-sitter-r", | ||
| "tree-sitter-rst", | ||
| "tree-sitter-ruby", | ||
| "tree-sitter-rust", | ||
| "tree-sitter-scala", | ||
| "tree-sitter-scheme", | ||
| "tree-sitter-smithy", | ||
| "tree-sitter-solidity", | ||
| "tree-sitter-svelte", | ||
| "tree-sitter-toml", | ||
| "tree-sitter-twig", | ||
| "tree-sitter-typescript", | ||
| "tree-sitter-verilog", | ||
| "tree-sitter-yaml", | ||
| "tree-sitter-zig" | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,12 @@ def check_grammar_exists(nixpkgs: str, grammar: str) -> bool: | |
| ) | ||
|
|
||
|
|
||
| def check_grammar_broken(nixpkgs: str, grammar: str) -> bool: | ||
| return eval_expr( | ||
| nixpkgs, f'tree-sitter-grammars.{fmt_grammar(grammar)}.meta.broken' | ||
| ) | ||
|
|
||
|
|
||
| def build_attr(nixpkgs, attr: str) -> str: | ||
| return ( | ||
| subprocess.run( | ||
|
|
@@ -55,7 +61,7 @@ def build_attr(nixpkgs, attr: str) -> str: | |
|
|
||
| if __name__ == "__main__": | ||
| cwd = dirname(abspath(__file__)) | ||
| nixpkgs = abspath(join(cwd, "../../../../../..")) | ||
| nixpkgs = abspath(join(cwd, "../../../../../../..")) | ||
khaneliman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| src_dir = build_attr(nixpkgs, "emacs.pkgs.tree-sitter-langs.src") | ||
|
|
||
|
|
@@ -65,7 +71,12 @@ def build_attr(nixpkgs, attr: str) -> str: | |
| for g in grammars: | ||
| exists = check_grammar_exists(nixpkgs, g) | ||
| if exists: | ||
| existing.append(fmt_grammar(g)) | ||
| broken = check_grammar_broken(nixpkgs, g) | ||
| if not broken: | ||
| existing.append(fmt_grammar(g)) | ||
| else: | ||
| sys.stderr.write("Grammar is broken: " + fmt_grammar(g) + "\n") | ||
| sys.stderr.flush() | ||
| else: | ||
| sys.stderr.write("Missing grammar: " + fmt_grammar(g) + "\n") | ||
| sys.stderr.flush() | ||
|
Comment on lines
71
to
82
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose a rewrite: for g in grammars:
grammar = fmt_grammar(g)
if not check_grammar_exists(nixpkgs, g):
print(f"Missing grammar: {grammar}", file=sys.stderr)
continue
if check_grammar_broken(nixpkgs, g):
print(f"Broken grammar: {grammar}", file=sys.stderr)
continue
existing.append(grammar)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, thanks. This script is only for Emacs plugins, so I think that would add the grammars tagged as broken back into the emacs ecosystem. Which is something that I might have forgotten to handle without your feedback. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| stdenv, | ||
| nodejs, | ||
| tree-sitter, | ||
| writableTmpDirAsHomeHook, | ||
| lib, | ||
| }: | ||
|
|
||
|
|
@@ -14,6 +15,7 @@ | |
| src, | ||
| location ? null, | ||
| generate ? false, | ||
| broken ? false, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like it is |
||
| ... | ||
| }@args: | ||
|
|
||
|
|
@@ -47,6 +49,21 @@ stdenv.mkDerivation ( | |
| tree-sitter generate | ||
| ''; | ||
|
|
||
| doCheck = !broken; | ||
|
|
||
| nativeCheckInputs = [ | ||
| # tree-sitter needs a writable home folder for the checkPhase | ||
| writableTmpDirAsHomeHook | ||
| ]; | ||
|
|
||
| checkPhase = '' | ||
| runHook preCheck | ||
|
|
||
| ${lib.getExe tree-sitter} test | ||
|
|
||
| runHook postCheck | ||
| ''; | ||
|
|
||
| # When both scanner.{c,cc} exist, we should not link both since they may be the same but in | ||
| # different languages. Just randomly prefer C++ if that happens. | ||
| buildPhase = '' | ||
|
|
@@ -71,6 +88,9 @@ stdenv.mkDerivation ( | |
| fi | ||
| runHook postInstall | ||
| ''; | ||
| meta = { | ||
| inherit broken; | ||
| }; | ||
| } | ||
| // removeAttrs args [ | ||
| "language" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| { | ||
| "url": "https://github.com/usernobody14/tree-sitter-dart", | ||
| "rev": "e81af6ab94a728ed99c30083be72d88e6d56cf9e", | ||
| "date": "2024-11-16T21:53:35-07:00", | ||
| "path": "/nix/store/jb7wiv90s78p45pj9mqvmbgk06xhjlj5-tree-sitter-dart", | ||
| "sha256": "0zl46vkm4p1jmivmnpyyzc58fwhx5frfgi0rfxna43h0qxdv62wy", | ||
| "hash": "sha256-nguzW8cADqJsdxnE57IrHXKHCvveX1t3rDJcUuc2hH4=", | ||
| "rev": "80e23c07b64494f7e21090bb3450223ef0b192f4", | ||
| "date": "2025-02-28T15:18:07-07:00", | ||
| "path": "/nix/store/7pfv5380h2fwv0rg0ckdjg8h71vzq71f-tree-sitter-dart", | ||
| "sha256": "00wzdgmi6kph4lk988brpy03j43a8vvfcjx9plnnnk07a14l3hbc", | ||
| "hash": "sha256-bMFBSVAHTGstvalL5vZGahA5gL95IZQmJfBOE+trnwM=", | ||
| "fetchLFS": false, | ||
| "fetchSubmodules": false, | ||
| "deepClone": false, | ||
| "leaveDotGit": false | ||
| "leaveDotGit": false, | ||
| "broken": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| { | ||
| "url": "https://github.com/gleam-lang/tree-sitter-gleam", | ||
| "rev": "af6043419f5aa0f8b6c2a26db0187aefa46c7f5f", | ||
| "date": "2025-02-07T14:27:03Z", | ||
| "path": "/nix/store/k54xiiqza536lzgvdw8yizsp6czdalln-tree-sitter-gleam", | ||
| "sha256": "0b7k2ah7a29simvvzm3f01vna5lzvv1mi7idvzpc056wjbgnvrg8", | ||
| "hash": "sha256-6OVt35LcFMDu3y2eWMPenxZldwBu1L93jToJdaAS8yw=", | ||
| "rev": "99ec4101504452c488b7c835fb65cfef75b090b7", | ||
| "date": "2025-03-20T12:15:08Z", | ||
| "path": "/nix/store/fyy76dad39xxxlg1mh8f7w8ny2yck8pa-tree-sitter-gleam", | ||
| "sha256": "11vvlpwhxr9wa0flq9k9xl4cr97jnvi8r2zaafy86qb71n7rqiql", | ||
| "hash": "sha256-FEecjw1nYYO8U+qLjOK28qTMCO1pJkwdUDzlDvmle4c=", | ||
| "fetchLFS": false, | ||
| "fetchSubmodules": false, | ||
| "deepClone": false, | ||
| "leaveDotGit": false | ||
| "leaveDotGit": false, | ||
| "broken": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| { | ||
| "url": "https://github.com/MunifTanjim/tree-sitter-lua", | ||
| "rev": "99fc677e6971c425e8d407f59c77ab897e585c92", | ||
| "date": "2024-09-09T11:10:03-04:00", | ||
| "path": "/nix/store/iiih0sfdls1h8q7ca12y0rhc7g5jl76w-tree-sitter-lua", | ||
| "sha256": "0wrbxmb6j8xyckf5jw14jf97cb9fn7yhalap6xxgsag84ypfsqj3", | ||
| "hash": "sha256-Q2LtrifoKf16N1dRBf2xLi12kpMkcFncZL4jaVbtK3M=", | ||
| "rev": "534c461d2b75b0887ec968ef9635f4460b0878b7", | ||
| "date": "2025-03-21T16:15:02+01:00", | ||
| "path": "/nix/store/vcmm6sdh9lfw4bvwx78yx2llzwq40jyb-tree-sitter-lua", | ||
| "sha256": "041anx0qirvd4il87whpic8nfdc1nk3kimxdb99m25bfdzm9rn0r", | ||
| "hash": "sha256-Gdic6m9uFVFTWq3XOMe0gTVnEYsX8oNoJG3niEG3KhA=", | ||
| "fetchLFS": false, | ||
| "fetchSubmodules": false, | ||
| "deepClone": false, | ||
| "leaveDotGit": false | ||
| "leaveDotGit": false, | ||
| "broken": true | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.